15 static LISP llength(LISP
obj)
20 return(flocons(obj->storage_as.string.dim));
22 return(flocons(obj->storage_as.double_array.dim));
24 return(flocons(obj->storage_as.long_array.dim));
26 return(flocons(obj->storage_as.lisp_array.dim));
30 for(l=obj,n=0;CONSP(l);l=CDR(l),++n) INTERRUPT_CHECK();
31 if NNULLP(l) err("improper list to length",obj);
34 return(err("wrong type of argument to length",obj));}}
36 LISP assoc(LISP x,LISP alist)
38 for(l=alist;CONSP(l);l=CDR(l))
40 if (CONSP(tmp) && equal(CAR(tmp),x))
return(tmp);
42 if EQ(l,NIL) return(NIL);
43 return(err("improper list to assoc",alist));}
45 LISP assq(LISP x,LISP alist)
47 for(l=alist;CONSP(l);l=CDR(l))
49 if (CONSP(tmp) && EQ(CAR(tmp),x))
return(tmp);
51 if EQ(l,NIL) return(NIL);
52 return(err("improper list to assq",alist));}
54 LISP setcar(LISP cell, LISP value)
55 {
if NCONSP(cell) err("wrong type of argument to setcar",cell);
56 return(CAR(cell) = value);}
58 LISP setcdr(LISP cell, LISP value)
59 {
if NCONSP(cell) err("wrong type of argument to setcdr",cell);
60 return(CDR(cell) = value);}
62 LISP delq(LISP elem,LISP l)
63 {
if NULLP(l) return(l);
65 if EQ(elem,car(l)) return(cdr(l));
66 setcdr(l,delq(elem,cdr(l)));
69 LISP copy_list(LISP x)
70 {
if NULLP(x) return(NIL);
72 return(cons(car(x),copy_list(cdr(x))));}
74 static LISP eq(LISP x,LISP y)
75 {
if EQ(x,y) return(truth); else return(NIL);}
77 LISP eql(LISP x,LISP y)
78 {
if EQ(x,y) return(truth); else
79 if NFLONUMP(x) return(NIL); else
80 if NFLONUMP(y) return(NIL); else
81 if (FLONM(x) == FLONM(y)) return(truth);
84 static LISP nullp(LISP x)
85 {
if EQ(x,NIL) return(truth); else return(NIL);}
87 LISP siod_flatten(LISP tree)
92 return append(siod_flatten(car(tree)),siod_flatten(cdr(tree)));
94 return cons(tree,NIL);
97 LISP cons(LISP x,LISP y)
106 if ((x==NIL) || CONSP(x))
113 {
if CONSP(x) return(truth); else return(NIL);}
122 return(err(
"wrong type of argument to car",x));}}
131 return(err(
"wrong type of argument to cdr",x));}}
133 LISP equal(LISP a,LISP b)
139 if EQ(a,b) return(truth);
141 if (atype != TYPE(b)) return(NIL);
144 if NULLP(equal(car(a),car(b))) return(NIL);
149 return((FLONM(a) == FLONM(b)) ? truth : NIL);
162 p = get_user_type_hooks(atype);
164 return((*p->equal)(a,b));
166 return ((USERVAL(a) == USERVAL(b)) ? truth : NIL);
173 for(p=l;NNULLP(p);p=cdr(p)) n = cons(car(p),n);
176 LISP append(LISP l1, LISP l2)
177 {LISP n=l2,p,rl1 = reverse(l1);
178 for(p=rl1;NNULLP(p);p=cdr(p))
182 void init_subrs_list(
void)
184 init_subr_2(
"assoc",assoc,
185 "(assoc KEY A-LIST)\n\
186 Return pair with KEY in A-LIST or nil.");
187 init_subr_1(
"length",llength,
189 Return length of LIST, or 0 if LIST is not a list.");
190 init_subr_1(
"flatten",siod_flatten,
192 Return flatend list (list of all atoms in LIST).");
193 init_subr_2(
"assq",assq,
194 "(assq ITEM ALIST)\n\
195 Returns pairs from ALIST whose car is ITEM or nil if ITEM is not in ALIST.");
196 init_subr_2(
"delq",delq,
198 Destructively delete ITEM from LIST, returns LIST, if ITEM is not first\n\
199 in LIST, cdr of LIST otherwise. If ITEM is not in LIST, LIST is\n\
200 returned unchanged." );
201 init_subr_1(
"copy-list",copy_list,
203 Return new list with same members as LIST.");
204 init_subr_2(
"cons",cons,
205 "(cons DATA1 DATA2)\n\
206 Construct cons pair whose car is DATA1 and cdr is DATA2.");
207 init_subr_1(
"pair?",consp,
209 Returns t if DATA is a cons cell, nil otherwise.");
210 init_subr_1(
"car",car,
212 Returns car of DATA1. If DATA1 is nil or a symbol, return nil.");
213 init_subr_1(
"cdr",cdr,
215 Returns cdr of DATA1. If DATA1 is nil or a symbol, return nil.");
216 init_subr_2(
"set-car!",setcar,
217 "(set-car! CONS1 DATA1)\n\
218 Set car of CONS1 to be DATA1. Returns CONS1. If CONS1 not of type\n\
219 consp an error is is given. This is a destructive operation.");
220 init_subr_2(
"set-cdr!",setcdr,
221 "(set-cdr! CONS1 DATA1)\n\
222 Set cdr of CONS1 to be DATA1. Returns CONS1. If CONS1 not of type\n\
223 consp an error is is given. This is a destructive operation.");
224 init_subr_2(
"eq?",eq,
225 "(eq? DATA1 DATA2)\n\
226 Returns t if DATA1 and DATA2 are the same object.");
227 init_subr_2(
"eqv?",eql,
228 "(eqv? DATA1 DATA2)\n\
229 Returns t if DATA1 and DATA2 are the same object or equal numbers.");
230 init_subr_2(
"equal?",equal,
232 t if s-expressions A and B are recursively equal, nil otherwise.");
233 init_subr_1(
"not",nullp,
235 Returns t if DATA is nil, nil otherwise.");
236 init_subr_1(
"null?",nullp,
238 Returns t if DATA is nil, nil otherwise.");
239 init_subr_1(
"reverse",reverse,
241 Returns destructively reversed LIST.");
242 init_subr_2(
"append",append,
243 "(append LIST1 LIST2)\n\
244 Returns LIST2 appended to LIST1, LIST1 is distroyed.");