本文整理汇总了C++中consp函数的典型用法代码示例。如果您正苦于以下问题:C++ consp函数的具体用法?C++ consp怎么用?C++ consp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了consp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cell_write
static void cell_write(SExp s, int b_escape, struct StreamBase* strm) {
// 省略表示系のチェック
if (consp(CDR(s)) && nullp(CDDR(s))) {
SExp t = CAR(s);
const char* str = NULL;
if (eq(t, intern("quote"))) {
str = "'";
} else if (eq(t, intern("quasiquote"))) {
str = "`";
}
if (str != NULL) {
strm_puts(strm, str, 0);
swrite(CADR(s), b_escape, strm);
return;
}
}
{
int first = TRUE;
SExp p;
strm_puts(strm, "(", 0);
for (p = s; consp(p); p = CDR(p)) {
if (!first) strm_puts(strm, " ", 0);
first = FALSE;
swrite(CAR(p), b_escape, strm);
}
if (!nullp(p)) {
strm_puts(strm, " . ", 0);
swrite(p, b_escape, strm);
}
strm_puts(strm, ")", 0);
}
}
示例2: pplist
/* pplist - pretty print a list */
LOCAL void pplist(LVAL expr)
{
int n;
/* if the expression will fit on one line, print it on one */
if ((n = flatsize(expr)) < ppmaxlen) {
xlprint(ppfile,expr,TRUE);
pplevel += n;
}
/* otherwise print it on several lines */
else {
n = ppmargin;
ppputc('(');
if (atomp(car(expr))) {
ppexpr(car(expr));
ppputc(' ');
ppmargin = pplevel;
expr = cdr(expr);
}
else
ppmargin = pplevel;
for (; consp(expr); expr = cdr(expr)) {
pp(car(expr));
if (consp(cdr(expr)))
ppterpri();
}
if (expr != NIL) {
ppputc(' '); ppputc('.'); ppputc(' ');
ppexpr(expr);
}
ppputc(')');
ppmargin = n;
}
}
示例3: StMObDeleteItem
/* to reflect the shift in position */
void StMObDeleteItem(LVAL menu, LVAL item)
{
HMENU addr;
int n, i, j, id, flags;
LVAL items;
char *s;
if (StMObAllocated(menu)) {
addr = get_menu_address(menu);
id = get_menu_id(menu);
i = get_item_position(menu, item);
for (j = 0, items = slot_value(menu, s_items);
j < i && consp(items);
j++, items = cdr(items));
n = GetMenuItemCount((HMENU) addr);
for (; i < n; n--) DeleteMenu((HMENU) addr, i, MF_BYPOSITION);
if (consp(items)) items = cdr(items);
for (; consp(items); items = cdr(items), i++) {
item = car(items);
s = get_item_string(item);
if (s[0] == '-') AppendMenu((HMENU) addr, MF_SEPARATOR, 0, NULL);
else {
flags = MF_STRING;
if (slot_value(item, s_mark) != NIL) flags |= MF_CHECKED;
if (slot_value(item, s_enabled) == NIL) flags |= MF_GRAYED;
AppendMenu((HMENU) addr, flags, MAKEITEMINDEX(id, i), s);
}
}
}
}
示例4: lisp_print
LISPTR lisp_print(LISPTR x, FILE* out)
{
if (consp(x)) {
fputwc('(', out);
while (true) {
lisp_print(car(x), out);
x = cdr(x);
if (!consp(x)) {
if (x != NIL) {
fputws(L" . ", out);
lisp_print(x, out);
}
break;
}
fputwc(' ', out);
}
fputwc(')', out);
} else if (symbolp(x)) {
fputws(string_text(symbol_name(x)), out);
} else if (numberp(x)) {
fwprintf(out, L"%g", number_value(x));
} else if (stringp(x)) {
fputwc('"', out);
fputws(string_text(x), out);
fputwc('"', out);
} else {
fputws(L"*UNKOBJ*", out);
}
return x;
}
示例5: is_labels
int is_labels(LVAL expr)
{
/* make sure that we have a list whose first element is a
list of the form (time "label") */
if (!consp(expr))
return 0;
if (!consp(car(expr)))
return 0;
if (!(floatp(car(car(expr))) || fixp(car(car(expr)))))
return 0;
if (!consp(cdr(car(expr))))
return 0;
if (!(stringp(car(cdr(car(expr))))))
return 0;
/* If this is the end of the list, we're done */
if (cdr(expr) == NULL)
return 1;
/* Otherwise recurse */
return is_labels(cdr(expr));
}
示例6: xnconc
/* xnconc - destructively append lists */
LVAL xnconc(void)
{
LVAL next,last=NULL,val;
/* initialize */
val = NIL;
/* concatenate each argument */
if (moreargs()) {
while (xlargc > 1) {
/* ignore everything except lists */
if ((next = nextarg()) && consp(next)) {
/* concatenate this list to the result list */
if (val) rplacd(last,next);
else val = next;
/* find the end of the list */
while (consp(cdr(next)))
next = cdr(next);
last = next;
}
}
/* handle the last argument */
if (val) rplacd(last,nextarg());
else val = nextarg();
}
/* return the list */
return (val);
}
示例7: xassoc
/* xassoc - built-in function 'assoc' */
LVAL xassoc(void)
{
LVAL x,alist,fcn,pair,val;
int tresult;
/* protect some pointers */
xlsave1(fcn);
/* get the expression to look for and the association list */
x = xlgetarg();
alist = xlgalist();
xltest(&fcn,&tresult);
/* look for the expression */
for (val = NIL; consp(alist); alist = cdr(alist))
if ((pair = car(alist)) && consp(pair))
if (dotest2(x,car(pair),fcn) == tresult) {
val = pair;
break;
}
/* restore the stack */
xlpop();
/* return result */
return (val);
}
示例8: get_acceptable_type
static sexpr get_acceptable_type (sexpr lq)
{
sexpr types = get_acceptable_types (lq), ta,
mape = lx_environment_alist (mime_map), n;
while (consp (types))
{
ta = car (types);
n = mape;
while (consp (n))
{
if (truep (equalp (ta, cdr (car (n)))))
{
return ta;
}
n = cdr (n);
}
types = cdr (types);
}
return default_type;
}
示例9: bind_args
LISPTR bind_args(LISPTR formals, LISPTR acts, LISPTR prev)
{
if (!consp(formals)) {
return prev;
}
return cons(cons(car(formals), consp(acts) ? eval(car(acts)) : NIL), bind_args(cdr(formals), consp(acts) ? cdr(acts) : NIL, prev));
}
示例10: xlfail
/* xlapply - apply a function to a list of arguments */
NODE *xlapply(NODE *fun,NODE *args)
{
NODE *env,*val;
val = 0; //BUG: uninitialized variable is used if xlfail returns
/* check for a null function */
if (fun == NIL)
xlfail("bad function");
/* evaluate the function */
if (subrp(fun))
val = (*getsubr(fun))(args);
else if (consp(fun)) {
if (consp(car(fun))) {
env = cdr(fun);
fun = car(fun);
}
else
env = xlenv;
if (car(fun) != s_lambda)
xlfail("bad function type");
val = evfun(fun,args,env);
}
else
xlfail("bad function");
/* return the result value */
return (val);
}
示例11: xcar
bool Array_T::typep(Value type) const
{
if (consp(type))
{
Value type_specifier_atom = xcar(type);
Value tail = xcdr(type);
if (type_specifier_atom == S_array)
{
if (consp(tail))
{
Value element_type = xcar(tail);
tail = xcdr(tail);
if (element_type == UNSPECIFIED || ::equal(element_type, _element_type)
|| (_element_type == S_bit && ::equal(element_type, BIT_TYPE)))
{
if (tail == NIL)
return true;
if (::length(tail) == 1)
{
Value dimensions = xcar(tail);
if (dimensions == UNSPECIFIED)
return true;
if (dimensions == make_fixnum(_rank))
return true;
if (consp(dimensions))
{
if (::length(dimensions) == _rank)
{
unsigned long i = 0;
while (dimensions != NIL)
{
Value dim = xcar(dimensions);
if (dim == UNSPECIFIED || dim == make_fixnum(_dimensions[i]))
; // ok
else
return false;
dimensions = xcdr(dimensions);
++i;
}
return true;
}
}
}
}
}
}
}
else if (symbolp(type))
{
if (type == S_array || type == S_atom || type == T)
return true;
}
else
{
if (type == C_array || type == C_t)
return true;
}
return false;
}
示例12: return
/* findprop - find a property pair */
LOCAL NODE *findprop(NODE *sym,NODE *prp)
{
NODE *p;
for (p = getplist(sym); consp(p) && consp(cdr(p)); p = cdr(cdr(p)))
if (car(p) == prp)
return (cdr(p));
return (NIL);
}
示例13: findprop
/* findprop - find a property pair */
LVAL findprop(LVAL sym, LVAL prp)
{
LVAL p;
for (p = getplist(sym); consp(p) && consp(cdr(p)); p = cdr(cdr(p)))
if (car(p) == prp)
return (cdr(p));
return (NIL);
}
示例14: xcar
bool SimpleArray_UB16_1::typep(Value type) const
{
if (consp(type))
{
Value type_specifier_atom = xcar(type);
Value tail = xcdr(type);
if (type_specifier_atom == S_array || type_specifier_atom == S_simple_array)
{
if (consp(tail))
{
Value element_type = xcar(tail);
if (element_type == UNSPECIFIED)
; // ok
else
{
Value upgraded_element_type = upgraded_array_element_type(element_type);
if (::equal(upgraded_element_type, UB16_TYPE))
; // ok
else if (::equal(upgraded_element_type,
list3(S_integer, FIXNUM_ZERO, make_fixnum(65535))))
; // ok
else if (::equal(upgraded_element_type,
list3(S_integer, FIXNUM_ZERO, list1(make_fixnum(65536)))))
; // ok
else
return false;
}
tail = xcdr(tail);
if (tail == NIL)
return true;
if (cdr(tail) == NIL) // i.e. length(tail) == 1
{
Value dimensions = xcar(tail);
if (dimensions == UNSPECIFIED)
return true;
if (dimensions == FIXNUM_ONE)
return true;
if (::equal(dimensions, list1(UNSPECIFIED)))
return true;
if (::equal(dimensions, list1(make_fixnum(_capacity))))
return true;
}
}
}
}
else if (symbolp(type))
{
if (type == S_vector || type == S_sequence || type == S_simple_array
|| type == S_array || type == S_atom || type == T)
return true;
}
else
{
if (type == C_vector || type == C_array || type == C_sequence || type == C_t)
return true;
}
return false;
}
示例15: test_one_env
LOCAL void test_one_env(LVAL environment, int i, char *s)
{
register LVAL fp,ep;
LVAL val;
/* check the environment list */
for (fp = environment; fp; fp = cdr(fp)) {
/* check that xlenv is good */
if (!consp(fp)) {
sprintf(buf,"%s: xlenv 0x%lx, frame 0x%lx, type(frame) %d\n",
s, xlenv, fp, ntype(fp));
errputstr(buf);
report_exit("xlenv points to a bad list", i);
}
/* check for an instance variable */
if ((ep = car(fp)) && objectp(car(ep))) {
/* do nothing */
}
/* check an environment stack frame */
else {
for (; ep; ep = cdr(ep)) {
/* check that ep is good */
if (!consp(ep)) {
sprintf(buf,"%s: fp 0x%lx, ep 0x%lx, type(ep) %d\n",
s, fp, ep, ntype(ep));
errputstr(buf);
report_exit("car(fp) points to a bad list", i);
}
/* check that car(ep) is nonnull */
if (!car(ep)) {
sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx\n",
s, ep, car(ep));
errputstr(buf);
report_exit("car(ep) (an association) is NULL", i);
}
/* check that car(ep) is a cons */
if (!consp(car(ep))) {
sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx, type(car(ep)) %d\n",
s, ep, car(ep), ntype(car(ep)));
errputstr(buf);
report_exit("car(ep) (an association) is not a cons", i);
}
/* check that car(car(ep)) is a symbol */
if (!symbolp(car(car(ep)))) {
sprintf(buf,"%s: ep 0x%lx, car(ep) 0x%lx, car(car(ep)) 0x%lx, type(car(car(ep))) %d\n",
s, ep, car(ep), car(car(ep)), ntype(car(car(ep))));
errputstr(buf);
report_exit("car(car(ep)) is not a symbol", i);
}
}
}
}
}