本文整理汇总了C++中CADR函数的典型用法代码示例。如果您正苦于以下问题:C++ CADR函数的具体用法?C++ CADR怎么用?C++ CADR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CADR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expand_letstar
static SCM
expand_letstar (SCM expr, SCM env SCM_UNUSED)
{
const SCM cdr_expr = CDR (expr);
ASSERT_SYNTAX (scm_ilength (cdr_expr) >= 0, s_bad_expression, expr);
ASSERT_SYNTAX (scm_ilength (cdr_expr) >= 2, s_missing_expression, expr);
return expand_letstar_clause (CADR (expr), CDDR (expr), env);
}
示例2: do_makevector
/* vector(mode="logical", length=0) */
SEXP attribute_hidden do_makevector(SEXP call, SEXP op, SEXP args, SEXP rho)
{
R_xlen_t len;
SEXP s;
SEXPTYPE mode;
checkArity(op, args);
if (length(CADR(args)) != 1) error(_("invalid '%s' argument"), "length");
len = asVecSize(CADR(args));
if (len < 0) error(_("invalid '%s' argument"), "length");
s = coerceVector(CAR(args), STRSXP);
if (length(s) != 1) error(_("invalid '%s' argument"), "mode");
mode = str2type(CHAR(STRING_ELT(s, 0))); /* ASCII */
if (mode == -1 && streql(CHAR(STRING_ELT(s, 0)), "double"))
mode = REALSXP;
switch (mode) {
case LGLSXP:
case INTSXP:
case REALSXP:
case CPLXSXP:
case STRSXP:
case EXPRSXP:
case VECSXP:
case RAWSXP:
s = allocVector(mode, len);
break;
case LISTSXP:
if (len > INT_MAX) error("too long for a pairlist");
s = allocList((int) len);
break;
default:
error(_("vector: cannot make a vector of mode '%s'."),
translateChar(STRING_ELT(s, 0))); /* should be ASCII */
}
if (mode == INTSXP || mode == LGLSXP)
Memzero(INTEGER(s), len);
else if (mode == REALSXP)
Memzero(REAL(s), len);
else if (mode == CPLXSXP)
Memzero(COMPLEX(s), len);
else if (mode == RAWSXP)
Memzero(RAW(s), len);
/* other cases: list/expression have "NULL", ok */
return s;
}
示例3: CAR
struct lispobj *eval_let(struct lispobj *exps, struct lispobj *env)
{
struct lispobj *binds, *body, *vars, *vals, *lambda, *ret, *evals;
binds = CAR(exps);
body = CDR(exps);
if(length(binds) > 0) {
struct lispobj *tvars, *tvals;
vars = heap_grab(NEW_CONS(NULL, NULL));
vals = heap_grab(NEW_CONS(NULL, NULL));
tvars = vars; tvals = vals;
while(binds != NULL) {
struct lispobj *bind = CAR(binds);
if(length(bind) != 2) {
ret = NEW_ERROR("Bad binding in the let exp.\n");
goto exit;
}
CAR(tvars) = heap_grab(CAR(bind));
CAR(tvals) = heap_grab(CADR(bind));
CDR(tvars) = heap_grab(NEW_CONS(NULL, NULL));
CDR(tvals) = heap_grab(NEW_CONS(NULL, NULL));
tvars = CDR(tvars);
tvals = CDR(tvals);
binds = CDR(binds);
}
tvars = NULL;
tvals = NULL;
} else {
return NEW_ERROR("Empty bindgings in the let exp.\n");
}
lambda = heap_grab(env_proc_make(vars, body, env));
evals = heap_grab(env_val_list(vals, env));
if(evals != NULL && OBJ_TYPE(evals) == ERROR) {
ret = evals;
} else {
ret = apply(lambda, evals);
heap_release(evals);
}
heap_release(lambda);
exit:
heap_release(vals);
heap_release(vars);
return ret;
}
示例4: do_copyDFattr
/* This is allowed to change 'out' */
attribute_hidden
SEXP do_copyDFattr(SEXP call, SEXP op, SEXP args, SEXP env)
{
checkArity(op, args);
SEXP in = CAR(args), out = CADR(args);
SET_ATTRIB(out, ATTRIB(in));
IS_S4_OBJECT(in) ? SET_S4_OBJECT(out) : UNSET_S4_OBJECT(out);
SET_OBJECT(out, OBJECT(in));
return out;
}
示例5: do_lapply
/* This is a special .Internal, so has unevaluated arguments. It is
called from a closure wrapper, so X and FUN are promises. */
SEXP attribute_hidden do_lapply(SEXP call, SEXP op, SEXP args, SEXP rho)
{
SEXP R_fcall, ans, names, X, XX, FUN;
R_xlen_t i, n;
PROTECT_INDEX px;
checkArity(op, args);
PROTECT_WITH_INDEX(X = CAR(args), &px);
PROTECT(XX = eval(CAR(args), rho));
FUN = CADR(args); /* must be unevaluated for use in e.g. bquote */
n = xlength(XX);
if (n == NA_INTEGER) error(_("invalid length"));
Rboolean realIndx = CXXRCONSTRUCT(Rboolean, n > INT_MAX);
PROTECT(ans = allocVector(VECSXP, n));
names = getAttrib(XX, R_NamesSymbol);
if(!isNull(names)) setAttrib(ans, R_NamesSymbol, names);
/* The R level code has ensured that XX is a vector.
If it is atomic we can speed things up slightly by
using the evaluated version.
*/
{
SEXP ind, tmp;
/* Build call: FUN(XX[[<ind>]], ...) */
/* Notice that it is OK to have one arg to LCONS do memory
allocation and not PROTECT the result (LCONS does memory
protection of its args internally), but not both of them,
since the computation of one may destroy the other */
PROTECT(ind = allocVector(realIndx ? REALSXP : INTSXP, 1));
if(isVectorAtomic(XX))
PROTECT(tmp = LCONS(R_Bracket2Symbol,
CONS(XX, CONS(ind, R_NilValue))));
else
PROTECT(tmp = LCONS(R_Bracket2Symbol,
CONS(X, CONS(ind, R_NilValue))));
PROTECT(R_fcall = LCONS(FUN,
CONS(tmp, CONS(R_DotsSymbol, R_NilValue))));
for(i = 0; i < n; i++) {
if (realIndx) REAL(ind)[0] = double(i + 1);
else INTEGER(ind)[0] = int(i + 1);
tmp = eval(R_fcall, rho);
if (NAMED(tmp))
tmp = duplicate(tmp);
SET_VECTOR_ELT(ans, i, tmp);
}
UNPROTECT(3);
}
UNPROTECT(3); /* X, XX, ans */
return ans;
}
示例6: complex_math2
SEXP attribute_hidden complex_math2(SEXP call, SEXP op, SEXP args, SEXP env)
{
R_xlen_t i, n, na, nb;
Rcomplex ai, bi, *a, *b, *y;
SEXP sa, sb, sy;
Rboolean naflag = FALSE;
cm2_fun f;
switch (PRIMVAL(op)) {
case 0: /* atan2 */
f = z_atan2; break;
case 10001: /* round */
f = z_rround; break;
case 2: /* passed from do_log1arg */
case 10:
case 10003: /* passed from do_log */
f = z_logbase; break;
case 10004: /* signif */
f = z_prec; break;
default:
errorcall_return(call, _("unimplemented complex function"));
}
PROTECT(sa = coerceVector(CAR(args), CPLXSXP));
PROTECT(sb = coerceVector(CADR(args), CPLXSXP));
na = XLENGTH(sa); nb = XLENGTH(sb);
if ((na == 0) || (nb == 0)) {
UNPROTECT(2);
return(allocVector(CPLXSXP, 0));
}
n = (na < nb) ? nb : na;
PROTECT(sy = allocVector(CPLXSXP, n));
a = COMPLEX(sa); b = COMPLEX(sb); y = COMPLEX(sy);
for (i = 0; i < n; i++) {
ai = a[i % na]; bi = b[i % nb];
if(ISNA(ai.r) && ISNA(ai.i) &&
ISNA(bi.r) && ISNA(bi.i)) {
y[i].r = NA_REAL; y[i].i = NA_REAL;
} else {
f(&y[i], &ai, &bi);
if ( (ISNAN(y[i].r) || ISNAN(y[i].i)) &&
!(ISNAN(ai.r) || ISNAN(ai.i) || ISNAN(bi.r) || ISNAN(bi.i)) )
naflag = TRUE;
}
}
if (naflag)
warningcall(call, "NaNs produced in function \"%s\"", PRIMNAME(op));
if(n == na) {
DUPLICATE_ATTRIB(sy, sa);
} else if(n == nb) {
DUPLICATE_ATTRIB(sy, sb);
}
UNPROTECT(3);
return sy;
}
示例7: fcn
static void fcn(int n, const double x[], double *f, function_info
*state)
{
SEXP s, R_fcall;
ftable *Ftable;
double *g = (double *) 0, *h = (double *) 0;
int i;
R_fcall = state->R_fcall;
Ftable = state->Ftable;
if ((i = FT_lookup(n, x, state)) >= 0) {
*f = Ftable[i].fval;
return;
}
/* calculate for a new value of x */
s = CADR(R_fcall);
for (i = 0; i < n; i++) {
if (!R_FINITE(x[i])) error(_("non-finite value supplied by 'nlm'"));
REAL(s)[i] = x[i];
}
s = PROTECT(eval(state->R_fcall, state->R_env));
switch(TYPEOF(s)) {
case INTSXP:
if (length(s) != 1) goto badvalue;
if (INTEGER(s)[0] == NA_INTEGER) {
warning(_("NA replaced by maximum positive value"));
*f = DBL_MAX;
}
else *f = INTEGER(s)[0];
break;
case REALSXP:
if (length(s) != 1) goto badvalue;
if (!R_FINITE(REAL(s)[0])) {
warning(_("NA/Inf replaced by maximum positive value"));
*f = DBL_MAX;
}
else *f = REAL(s)[0];
break;
default:
goto badvalue;
}
if (state->have_gradient) {
g = REAL(PROTECT(coerceVector(getAttrib(s, install("gradient")), REALSXP)));
if (state->have_hessian) {
h = REAL(PROTECT(coerceVector(getAttrib(s, install("hessian")), REALSXP)));
}
}
FT_store(n, *f, x, g, h, state);
UNPROTECT(1 + state->have_gradient + state->have_hessian);
return;
badvalue:
error(_("invalid function value in 'nlm' optimizer"));
}
示例8: do_rep_int
SEXP attribute_hidden do_rep_int(SEXP call, SEXP op, SEXP args, SEXP rho)
{
checkArity(op, args);
SEXP s = CAR(args), ncopy = CADR(args);
R_xlen_t nc;
SEXP a;
if (!isVector(ncopy))
error(_("incorrect type for second argument"));
if (!isVector(s) && s != R_NilValue)
error(_("attempt to replicate an object of type '%s'"),
type2char(TYPEOF(s)));
nc = xlength(ncopy); // might be 0
if (nc == xlength(s))
PROTECT(a = rep2(s, ncopy));
else {
if (nc != 1) error(_("invalid '%s' value"), "times");
#ifdef LONG_VECTOR_SUPPORT
double snc = asReal(ncopy);
if (!R_FINITE(snc) || snc < 0)
error(_("invalid '%s' value"), "times");
nc = (R_xlen_t) snc;
#else
if ((nc = asInteger(ncopy)) == NA_INTEGER || nc < 0)/* nc = 0 ok */
error(_("invalid '%s' value"), "times");
#endif
R_xlen_t ns = xlength(s);
PROTECT(a = rep3(s, ns, nc * ns));
}
#ifdef _S4_rep_keepClass
if(IS_S4_OBJECT(s)) { /* e.g. contains = "list" */
setAttrib(a, R_ClassSymbol, getClassAttrib(s));
SET_S4_OBJECT(a);
}
#endif
if (inheritsCharSXP(s, R_FactorCharSXP)) {
SEXP tmp;
if(inheritsCharSXP(s, R_OrderedCharSXP)) {
PROTECT(tmp = allocVector(STRSXP, 2));
SET_STRING_ELT(tmp, 0, R_OrderedCharSXP);
SET_STRING_ELT(tmp, 1, R_FactorCharSXP);
} else PROTECT(tmp = mkString("factor"));
setAttrib(a, R_ClassSymbol, tmp);
UNPROTECT(1);
setAttrib(a, R_LevelsSymbol, getLevelsAttrib(s));
}
UNPROTECT(1);
return a;
}
示例9: RTcl_AssignObjToVar
SEXP RTcl_AssignObjToVar(SEXP args)
{
const void *vmax = vmaxget();
Tcl_SetVar2Ex(RTcl_interp,
translateChar(STRING_ELT(CADR(args), 0)),
NULL,
(Tcl_Obj *) R_ExternalPtrAddr(CADDR(args)),
0);
vmaxset(vmax);
return R_NilValue;
}
示例10: prnfunc
int prnfunc(Obj a, Obj stream, int how){
char n;
if( NNULLP( CADR(a))){
if( how) return prn_func_macr(a, stream, "closure");
else writestr(stream, "#<closure>");
}else{
if( how) return prn_func_macr(a, stream, "lambda");
else writestr(stream, "#<lambda>");
}
return 1;
}
示例11: do_logic2
/* && || */
SEXP attribute_hidden do_logic2(SEXP call, SEXP op, SEXP args, SEXP env)
{
/* && and || */
SEXP s1, s2;
int x1, x2;
SEXP ans;
if (length(args) != 2)
error(_("'%s' operator requires 2 arguments"),
PRIMVAL(op) == 1 ? "&&" : "||");
s1 = CAR(args);
s2 = CADR(args);
PROTECT(ans = allocVector(LGLSXP, 1));
s1 = eval(s1, env);
if (!isNumber(s1))
errorcall(call, _("invalid 'x' type in 'x %s y'"),
PRIMVAL(op) == 1 ? "&&" : "||");
x1 = asLogical(s1);
#define get_2nd \
s2 = eval(s2, env); \
if (!isNumber(s2)) \
errorcall(call, _("invalid 'y' type in 'x %s y'"), \
PRIMVAL(op) == 1 ? "&&" : "||"); \
x2 = asLogical(s2);
switch (PRIMVAL(op)) {
case 1: /* && */
if (x1 == FALSE)
LOGICAL(ans)[0] = FALSE;
else {
get_2nd;
if (x1 == NA_LOGICAL)
LOGICAL(ans)[0] = (x2 == NA_LOGICAL || x2) ? NA_LOGICAL : x2;
else /* x1 == TRUE */
LOGICAL(ans)[0] = x2;
}
break;
case 2: /* || */
if (x1 == TRUE)
LOGICAL(ans)[0] = TRUE;
else {
get_2nd;
if (x1 == NA_LOGICAL)
LOGICAL(ans)[0] = (x2 == NA_LOGICAL || !x2) ? NA_LOGICAL : x2;
else /* x1 == FALSE */
LOGICAL(ans)[0] = x2;
}
}
UNPROTECT(1);
return ans;
}
示例12: transformSugarDef
Obj transformSugarDef(Obj expr) {
Obj funcArgs = CADR(expr);
Obj func = CAR(funcArgs);
Obj args = CDR(funcArgs);
Obj body = CDDR(expr);
Obj lambdaExpr = CONS(LAMBDAOBJ, CONS(args, body));
Obj transformed = CONS(DEFOBJ, CONS(func, CONS(lambdaExpr, NULLOBJ)));
return transformed;
}
示例13: do_substr
SEXP attribute_hidden do_substr(SEXP call, SEXP op, SEXP args, SEXP env)
{
SEXP s, x, sa, so, el;
R_xlen_t i, len;
int start, stop, k, l;
size_t slen;
cetype_t ienc;
const char *ss;
char *buf;
checkArity(op, args);
x = CAR(args);
sa = CADR(args);
so = CADDR(args);
k = LENGTH(sa);
l = LENGTH(so);
if (!isString(x))
error(_("extracting substrings from a non-character object"));
len = XLENGTH(x);
PROTECT(s = allocVector(STRSXP, len));
if (len > 0) {
if (!isInteger(sa) || !isInteger(so) || k == 0 || l == 0)
error(_("invalid substring arguments"));
for (i = 0; i < len; i++) {
start = INTEGER(sa)[i % k];
stop = INTEGER(so)[i % l];
el = STRING_ELT(x,i);
if (el == NA_STRING || start == NA_INTEGER || stop == NA_INTEGER) {
SET_STRING_ELT(s, i, NA_STRING);
continue;
}
ienc = getCharCE(el);
ss = CHAR(el);
slen = strlen(ss); /* FIXME -- should handle embedded nuls */
buf = R_AllocStringBuffer(slen+1, &cbuff);
if (start < 1) start = 1;
if (start > stop || start > slen) {
buf[0] = '\0';
} else {
if (stop > slen) stop = (int) slen;
substr(buf, ss, ienc, start, stop);
}
SET_STRING_ELT(s, i, mkCharCE(buf, ienc));
}
R_FreeStringBufferL(&cbuff);
}
DUPLICATE_ATTRIB(s, x);
/* This copied the class, if any */
UNPROTECT(1);
return s;
}
示例14: do_mvfft
SEXP attribute_hidden do_mvfft(SEXP call, SEXP op, SEXP args, SEXP env)
{
SEXP z, d;
int i, inv, maxf, maxp, n, p;
double *work;
int *iwork;
checkArity(op, args);
z = CAR(args);
d = getAttrib(z, R_DimSymbol);
if (d == R_NilValue || length(d) > 2)
error(_("vector-valued (multivariate) series required"));
n = INTEGER(d)[0];
p = INTEGER(d)[1];
switch(TYPEOF(z)) {
case INTSXP:
case LGLSXP:
case REALSXP:
z = coerceVector(z, CPLXSXP);
break;
case CPLXSXP:
if (NAMED(z)) z = duplicate(z);
break;
default:
error(_("non-numeric argument"));
}
PROTECT(z);
/* -2 for forward transform, complex values */
/* +2 for backward transform, complex values */
inv = asLogical(CADR(args));
if (inv == NA_INTEGER || inv == 0) inv = -2;
else inv = 2;
if (n > 1) {
fft_factor(n, &maxf, &maxp);
if (maxf == 0)
error(_("fft factorization error"));
work = (double*)R_alloc(4 * maxf, sizeof(double));
iwork = (int*)R_alloc(maxp, sizeof(int));
for (i = 0; i < p; i++) {
fft_factor(n, &maxf, &maxp);
fft_work(&(COMPLEX(z)[i*n].r), &(COMPLEX(z)[i*n].i),
1, n, 1, inv, work, iwork);
}
}
UNPROTECT(1);
return z;
}
示例15: do_lengthgets
SEXP attribute_hidden do_lengthgets(SEXP call, SEXP op, SEXP args, SEXP rho)
{
SEXP x, ans;
checkArity(op, args);
check1arg(args, call, "x");
x = CAR(args);
if (PRIMVAL(op)) { /* xlength<- */
if(isObject(x) && DispatchOrEval(call, op, "length<-", args,
rho, &ans, 0, 1))
return(ans);
if (!isVector(x) && !isVectorizable(x))
error(_("invalid argument"));
if (length(CADR(args)) != 1)
error(_("invalid value"));
R_xlen_t len = asVecSize(CADR(args));
return xlengthgets(x, len);
}
if(isObject(x) && DispatchOrEval(call, op, "length<-", args,
rho, &ans, 0, 1))
return(ans);
if (!isVector(x) && !isVectorizable(x))
error(_("invalid argument"));
if (length(CADR(args)) != 1)
error(_("invalid value"));
R_xlen_t len = asVecSize(CADR(args));
if (len < 0) error(_("invalid value"));
if (len > R_LEN_T_MAX) {
#ifdef LONG_VECTOR_SUPPORT
return xlengthgets(x, len);
#else
error(_("vector size specified is too large"));
return x; /* -Wall */
#endif
}
return lengthgets(x, (R_len_t) len);
}