6 #include "util_const.h"
7 #include "util_string.h"
17 (quote LIST...) -> LIST
20 //#AFUNC quote ml_quote
22 MNode* ml_quote (MNode* cell, MlEnv* mlenv) {
23 MNode* arg = cell->cdr ();
26 throw (uErrorWrongNumber);
29 switch (arg->car ()->type) {
33 return mlenv->retval = arg->car ();
41 (list LIST...) -> LIST
46 MNode* ml_list (MNode* cell, MlEnv* mlenv) {
47 MNode* arg = cell->cdr ();
51 ans.append (eval (arg->car (), mlenv));
54 return ans.release ();
59 (if EXPR THEN_FUNCTION ELSE_FUNCTION_BODY...) -> LAST VALUE
64 MNode* ml_if (MNode* cell, MlEnv* mlenv) {
65 MNode* arg = cell->cdr ();
70 r = eval_bool (arg->car (), mlenv);
71 if (mlenv->breaksym ())
72 return mlenv->breakval ();
76 ans = eval (arg->car (), mlenv);
81 ans = progn (arg, mlenv);
82 // ifはbreakの対象でない mlenv->stopBreak (cell->car ());
86 return ans.release ();
91 (cond (EXPR BODY...)...) -> LAST VALUE
96 MNode* ml_cond (MNode* cell, MlEnv* mlenv) {
97 MNode* arg = cell->cdr ();
102 while (arg && ! mlenv->breaksym ()) {
105 throw (uNil + uErrorBadType);
107 throw (a->dump_string () + uErrorBadType);
108 f = eval_bool (a->car (), mlenv);
109 if (mlenv->breaksym ()) {
110 ans = mlenv->breakval ();
111 // condはbreakの対象ではない mlenv->stopBreak (cell->car ());
115 ans = progn (a->cdr (), mlenv);
116 // condはbreakの対象ではない mlenv->stopBreak (cell->car ());
122 return ans.release ();
127 (progn [:on-error FUNCTION] BODY...) -> LAST VALUE
130 //#AFUNC progn ml_progn
132 MNode* ml_progn (MNode* cell, MlEnv* mlenv) {
133 MNode* arg = cell->cdr ();
136 std::vector<MNode*> keywords;
138 static paramList kwlist[] = {
139 {CharConst ("on-error"), false},
143 setParams (arg, 0, NULL, kwlist, &keywords, &rest);
145 errfn = eval (keywords[0], mlenv);
148 ans = progn (rest, mlenv);
149 } catch (ustring& msg) {
151 onErrorFn (errfn (), mlenv);
156 mlenv->stopBreak (cell->car ());
158 return ans.release ();
162 ===select, case, otherwise===
169 //#AFUNC select ml_select
171 //#AFUNC case ml_case
173 //#AFUNC otherwise ml_otherwise
174 //#WIKIFUNC otherwise
175 MNode* ml_select (MNode* cell, MlEnv* mlenv) {
176 MNode* arg = cell->cdr ();
179 while (arg && ! mlenv->breaksym ()) {
180 ans = eval (arg->car (), mlenv);
181 if (mlenv->breaksym ()) {
182 ans = mlenv->breakval ();
183 // 対象外 mlenv->stopBreak (cell->car ());
184 return ans.release ();
188 if (ans ()->isCons () && to_bool (ans ()->car ())) {
189 ans = ans ()->cdr ();
190 return ans.release ();
199 MNode* ml_case (MNode* cell, MlEnv* mlenv) {
200 MNode* arg = cell->cdr ();
205 throw (uErrorWrongNumber);
207 r = eval_bool (arg->car (), mlenv);
211 ans ()->set_car (newMNode_bool (true));
212 ans ()->set_cdr (progn (arg, mlenv));
213 // mlenv->stopBreak (cell->car ());
216 return ans.release ();
219 MNode* ml_otherwise (MNode* cell, MlEnv* mlenv) {
220 MNode* arg = cell->cdr ();
224 ans ()->set_car (newMNode_bool (true));
225 ans ()->set_cdr (progn (arg, mlenv));
226 // mlenv->stopBreak (cell->car ());
228 return ans.release ();
233 (repeat VARIABLE FROM TO [:step ADD] [:array VARLIST] BODY...) -> LAST VALUE
235 index VARIABLE is set local.
238 //#AFUNC repeat ml_repeat
239 MNode* ml_repeat (MNode* cell, MlEnv* mlenv) {
240 MNode* arg = cell->cdr ();
245 std::vector<ustring> lv;
251 std::vector<MNode*> params;
252 std::vector<MNode*> keywords;
254 static paramList kwlist[] = {
255 {CharConst ("step"), false},
256 {CharConst ("array"), false},
260 setParams (arg, 3, ¶ms, kwlist, &keywords, &rest);
261 iv = eval_str (params[0], mlenv);
262 from = eval_double (params[1], mlenv);
263 to = eval_double (params[2], mlenv);
265 step = eval_double (keywords[0], mlenv);
269 if (a && a->isSym ()) {
270 lv.push_back (a->to_string ());
271 } else if (a && a->isCons ()) {
273 lv.push_back (to_string (a->car ()));
277 throw (to_string (t ()) + ustring (": bad argument."));
282 AutoLocalVariable autoLocal (mlenv);
284 mlenv->defineLocalVar (iv);
288 for (i = from; kp && i <= to; i += step) {
289 t = newMNode_num (i);
290 mlenv->setVar (iv, t ());
292 for (j = 0; j < lv.size (); j ++)
293 mlenv->setVar (lv[j], mlenv->getAry (lv[j], (size_t)i));
294 ans = progn (rest, mlenv);
295 if (mlenv->breaksym ()) {
296 mlenv->stopBreak (cell->car ());
300 for (j = 0; j < lv.size (); j ++)
301 mlenv->setAry (lv[j], (size_t)i, mlenv->getVar (lv[j]));
303 if (mlenv->qtimeup ())
307 } else if (step < 0) {
309 for (i = from; kp && i >= to; i += step) {
310 t = newMNode_num (i);
311 mlenv->setVar (iv, t ());
313 for (j = 0; j < lv.size (); j ++)
314 mlenv->setVar (lv[j], mlenv->getAry (lv[j], (size_t)i));
315 ans = progn (rest, mlenv);
316 if (mlenv->breaksym ()) {
317 mlenv->stopBreak (cell->car ());
321 for (j = 0; j < lv.size (); j ++)
322 mlenv->setAry (lv[j], (size_t)i, mlenv->getVar (lv[j]));
324 if (mlenv->qtimeup ())
331 return mlenv->retval = ans ();
336 (doarray '(ARRAY_VARIABLE ...) [:index VARIABLE] [:setvar '(VARIABLE...)] BODY...) -> LAST VALUE
338 index VARIABLE is set local.
341 //#AFUNC doarray ml_doarray
343 MNode* ml_doarray (MNode* cell, MlEnv* mlenv) {
344 MNode* arg = cell->cdr ();
345 std::vector<ustring> lv;
346 std::vector<ustring> setvar;
354 std::vector<MNode*> params;
355 std::vector<MNode*> keywords;
357 static paramList kwlist[] = {
358 {CharConst ("index"), false},
359 {CharConst ("setvar"), false},
363 setParams (arg, 1, ¶ms, kwlist, &keywords, &rest);
364 t = eval (params[0], mlenv);
365 if (t () && t ()->isSym ()) {
366 lv.push_back (t ()->to_string ());
367 } else if (t () && t ()->isCons ()) {
369 while (a && a->isCons ()) {
370 lv.push_back (to_string (a->car ()));
374 throw (dump_to_sexp (t ()) + ustring (": bad argument."));
377 iv = to_string (t ());
379 if (t () && t ()->isSym ()) {
380 setvar.push_back (to_string (t ()));
381 } else if (t () && t ()->isCons ()) {
383 while (a && a->isCons ()) {
384 setvar.push_back (to_string (a->car ()));
388 throw (ustring (CharConst (":setvar ")) + dump_to_sexp (t ()) + ustring (": bad argument."));
393 AutoLocalVariable autoLocal (mlenv);
395 if (iv.length () > 0)
396 mlenv->defineLocalVar (iv);
399 nsv = setvar.size ();
400 if (nsv > 0 && nlv > nsv)
405 n = mlenv->getArySize (lv[0]);
406 for (i = 1; kp && i <= n; i ++) {
408 for (it = 0; it < nlv; it ++) {
409 mlenv->setVar (lv[it], mlenv->getAry (lv[it], i));
412 for (it = 0; it < nlv; it ++) {
413 mlenv->setVar (setvar[it], mlenv->getAry (lv[it], i));
415 for (; it < nsv; it ++) {
416 mlenv->setVar (setvar[it], NULL);
419 if (iv.size () > 0) {
420 t = newMNode_num (i);
421 mlenv->setVar (iv, t ());
423 ans = progn (rest, mlenv);
424 if (mlenv->breaksym ()) {
425 mlenv->stopBreak (cell->car ());
429 for (it = 0; it < nlv; it ++) {
430 mlenv->setAry (lv[it], i, mlenv->getVar (lv[it]));
433 for (it = 0; it < nlv; it ++) {
434 mlenv->setAry (lv[it], i, mlenv->getVar (setvar[it]));
438 for (it = 0; it < nlv; it ++) {
439 mlenv->setArySize (lv[it], n);
444 return ans.release ();
450 // (dolist '(VARIABLE1...) '(LIST...) [:index VARIABLE2] BODY...) -> LAST VALUE
451 (list-each '(VARIABLE1...) '(LIST...) [:index VARIABLE2] BODY...) -> LAST VALUE
453 list VARIABLE1 and index VARIABLE2 is set local.
456 //#AFUNC dolist ml_list_each
457 //#AFUNC list-each ml_list_each
459 //#WIKIFUNC list-each
460 MNode* ml_list_each (MNode* cell, MlEnv* mlenv) {
461 MNode* arg = cell->cdr ();
462 std::vector<ustring> lv;
467 std::vector<MNode*> llv;
473 std::vector<MNode*> params;
474 std::vector<MNode*> keywords;
476 static paramList kwlist[] = {
477 {CharConst ("index"), false},
481 setParams (arg, 2, ¶ms, kwlist, &keywords, &rest);
482 vlist = eval (params[0], mlenv);
483 if (vlist () && vlist ()->isSym ()) {
484 lv.push_back (vlist ()->to_string ());
485 } else if (vlist () && vlist ()->isCons ()) {
487 while (a && a->isCons ()) {
488 lv.push_back (to_string (a->car ()));
492 throw (to_string (vlist ()) + ustring (": bad argument."));
494 list = eval (params[1], mlenv);
496 iv = eval_str (keywords[0], mlenv);
500 for (i = 0; i < iu; i ++) {
502 llv.push_back (a->car ());
504 llv.push_back (NULL);
509 AutoLocalVariable autoLocal (mlenv);
511 for (it = 0; it < iu; it ++)
512 mlenv->defineLocalVar (lv[it]);
513 if (iv.length () > 0)
514 mlenv->defineLocalVar (iv);
516 if (iu > 0 && llv.size () > 0) {
518 for (i = 1; kp && llv[0]; i ++) {
519 if (iv.length () > 0) {
520 mlenv->setVar (iv, newMNode_num (i));
522 for (it = 0; it < iu; it ++) {
524 mlenv->setVar (lv[it], llv[it]->car ());
526 mlenv->setVar (lv[it], NULL);
529 ans = progn (rest, mlenv);
530 if (mlenv->breaksym ()) {
531 mlenv->stopBreak (cell->car ());
538 return ans.release ();
543 (while EXPR BODY...) -> LAST VALUE
546 //#AFUNC while ml_while
547 MNode* ml_while (MNode* cell, MlEnv* mlenv) {
548 MNode* arg = cell->cdr ();
555 while (eval_bool (exp, mlenv)) {
556 ans = progn (arg, mlenv);
557 if (mlenv->breaksym ()) {
558 mlenv->stopBreak (cell->car ());
563 return ans.release ();
568 (break FUNCTION-NAME VALUE) -> NULL
571 //#AFUNC break ml_break
572 MNode* ml_break (MNode* cell, MlEnv* mlenv) {
573 MNode* arg = cell->cdr ();
580 sym = eval (arg->car (), mlenv);
583 val = eval (arg->car (), mlenv);
586 throw (uErrorWrongNumber);
589 mlenv->setBreak (sym.release (), val ());
591 return mlenv->retval = val.release ();
599 //#AFUNC exit ml_exit
600 MNode* ml_exit (MNode* cell, MlEnv* mlenv) {
601 MNode* arg = cell->cdr ();
604 throw (uErrorWrongNumber);
613 (apply FUNCTION-NAME VALUE... LIST) -> ANY
614 (apply LAMBDA VALUE... LIST) -> ANY
617 //#AFUNC apply ml_apply
618 MNode* ml_apply (MNode* cell, MlEnv* mlenv) {
619 MNode* arg = cell->cdr ();
625 throw (uErrorWrongNumber);
626 fn = eval (arg->car (), mlenv);
629 throw (uErrorSyntax);
630 } else if (isLambda (fn ())) {
632 if (! isNil (arg->cdr ())) {
633 list.append (eval (arg->car (), mlenv));
636 h = eval (arg->car (), mlenv);
638 while (a && a->isCons ()) {
639 list.append (a->car ());
645 return mlenv->retval = execDefun (mlenv, fn (), list (), uEmpty);
646 } else if (fn ()->isSym ()) {
648 if (! isNil (arg->cdr ())) {
649 list.append (quoted (eval (arg->car (), mlenv)));
652 h = eval (arg->car (), mlenv);
654 while (a && a->isCons ()) {
655 list.append (quoted (a->car ()));
664 f ()->set_car (fn ());
665 f ()->set_cdr (list ());
666 return mlenv->retval = eval (f (), mlenv);
668 throw (uErrorSyntax);
675 (funcall LAMBDA PARAMS...)
678 //#AFUNC funcall ml_funcall
679 MNode* ml_funcall (MNode* cell, MlEnv* mlenv) {
680 MNode* arg = cell->cdr ();
684 throw (uErrorWrongNumber);
685 fn = eval (arg->car (), mlenv);
689 throw (uErrorSyntax);
690 } else if (isLambda (fn ())) {
691 return mlenv->retval = execDefun (mlenv, fn (), arg, uEmpty);
692 } else if (fn ()->isSym ()) {
695 f ()->set_car (fn ());
697 return mlenv->retval = eval (f (), mlenv);
699 throw (uErrorSyntax);
709 //#AFUNC eval ml_eval
710 MNode* ml_eval (MNode* cell, MlEnv* mlenv) {
711 MNode* arg = cell->cdr ();
715 throw (uErrorWrongNumber);
716 h = eval (arg->car (), mlenv);
719 throw (uErrorWrongNumber);
720 return mlenv->retval = eval (h (), mlenv);
730 MNode* ml_car (MNode* cell, MlEnv* mlenv) {
731 MNode* arg = cell->cdr ();
735 throw (uErrorWrongNumber);
736 h = eval (arg->car (), mlenv);
739 throw (uErrorWrongNumber);
741 if (h () && h ()->isCons ()) {
742 return mlenv->retval = h ()->car ();
755 MNode* ml_cdr (MNode* cell, MlEnv* mlenv) {
756 MNode* arg = cell->cdr ();
760 throw (uErrorWrongNumber);
761 h = eval (arg->car (), mlenv);
764 throw (uErrorWrongNumber);
766 if (h () && h ()->isCons ()) {
767 return mlenv->retval = h ()->cdr ();
775 (nth N LIST) -> ELEMENT
776 (car LIST) is (nth 0 LIST)
781 MNode* ml_nth (MNode* cell, MlEnv* mlenv) {
782 MNode* arg = cell->cdr ();
788 throw (uErrorWrongNumber);
789 n = eval_int (arg->car (), mlenv);
791 h = eval (arg->car (), mlenv);
794 throw (uErrorWrongNumber);
797 while (n > 0 && a && a->isCons ()) {
802 if (a && a->isCons ())
803 return mlenv->retval = a->car ();
811 (replca CELL NEWCAR) -> NEWCAR
814 //#AFUNC replca ml_replca
815 MNode* ml_replca (MNode* cell, MlEnv* mlenv) {
816 MNode* arg = cell->cdr ();
821 throw (uErrorWrongNumber);
822 c = eval (arg->car (), mlenv);
823 nextNodeNonNil (arg);
824 newcar = eval (arg->car (), mlenv);
827 throw (uErrorWrongNumber);
830 throw (ustring (CharConst ("nil data.")));
831 if (! c ()->isCons ())
832 throw (c ()->dump_string () + uErrorBadType);
834 c ()->set_car (newcar ());
836 return mlenv->retval = newcar ();
841 (replcd CELL NEWCDR) -> NEWCDR
844 //#AFUNC replcd ml_replcd
845 MNode* ml_replcd (MNode* cell, MlEnv* mlenv) {
846 MNode* arg = cell->cdr ();
851 throw (uErrorWrongNumber);
852 c = eval (arg->car (), mlenv);
853 nextNodeNonNil (arg);
854 newcdr = eval (arg->car (), mlenv);
857 throw (uErrorWrongNumber);
860 throw (ustring (CharConst ("nil data.")));
861 if (! c ()->isCons ())
862 throw (c ()->dump_string () + uErrorBadType);
864 c ()->set_cdr (newcdr ());
866 return mlenv->retval = newcdr ();
871 (cons CAR CDR) -> CONS
874 //#AFUNC cons ml_cons
876 MNode* ml_cons (MNode* cell, MlEnv* mlenv) {
877 MNode* arg = cell->cdr ();
883 throw (uErrorWrongNumber);
884 car = eval (arg->car (), mlenv);
887 cdr = eval (arg->car (), mlenv);
891 throw (uErrorWrongNumber);
894 ans ()->set_car (car ());
895 ans ()->set_cdr (cdr ());
897 return mlenv->retval = ans ();
902 (append LIST...) -> LIST
905 //#AFUNC append ml_append
907 MNode* ml_append (MNode* cell, MlEnv* mlenv) {
908 MNode* arg = cell->cdr ();
914 h = eval (arg->car (), mlenv);
918 while (a && a->isCons ()) {
919 list.append (a->car ());
923 list.set_cdr_cut (h ());
927 return mlenv->retval = list ();
932 (mapcar LAMBDA LIST...) -> LIST
935 //#AFUNC mapcar ml_mapcar
937 MNode* ml_mapcar (MNode* cell, MlEnv* mlenv) {
938 MNode* arg = cell->cdr ();
946 throw (uErrorWrongNumber);
947 fn = eval (arg->car (), mlenv);
948 nextNodeNonNil (arg);
950 list.append (eval (arg->car (), mlenv));
955 throw (uErrorSyntax);
956 } else if (isLambda (fn ())) {
957 } else if (fn ()->isSym ()) {
959 throw (uErrorSyntax);
964 if (fn ()->isSym ()) {
971 if (h () && h ()->isCons ()) {
972 e.append (newMNode_quote (h ()->car ()));
974 arg->set_car (h ()->cdr ());
984 h ()->set_car (fn ());
985 h ()->set_cdr (e.release ());
986 ans.append (eval (h (), mlenv));
995 if (h () && h ()->isCons ()) {
996 e.append (h ()->car ());
998 arg->set_car (h ()->cdr ());
1007 ans.append (execDefun (mlenv, fn (), e (), uEmpty));
1011 return ans.release ();
1015 ===mapcar-collect===
1016 (mapcar-collect LAMBDA LIST...) -> LIST
1019 //#AFUNC mapcar-collect ml_mapcar_collect
1020 //#WIKIFUNC mapcar-collect
1021 MNode* ml_mapcar_collect (MNode* cell, MlEnv* mlenv) {
1022 MNode* arg = cell->cdr ();
1031 throw (uErrorWrongNumber);
1032 fn = eval (arg->car (), mlenv);
1033 nextNodeNonNil (arg);
1035 list.append (eval (arg->car (), mlenv));
1040 throw (uErrorSyntax);
1041 } else if (isLambda (fn ())) {
1042 } else if (fn ()->isSym ()) {
1044 throw (uErrorSyntax);
1046 if (isNil (list ()))
1049 if (fn ()->isSym ()) {
1056 if (h () && h ()->isCons ()) {
1057 e.append (newMNode_quote (h ()->car ()));
1059 arg->set_car (h ()->cdr ());
1069 h ()->set_car (fn ());
1070 h ()->set_cdr (e.release ());
1071 v = eval (h (), mlenv);
1073 ans.append (v.release ());
1082 if (h () && h ()->isCons ()) {
1083 e.append (h ()->car ());
1085 arg->set_car (h ()->cdr ());
1094 v = execDefun (mlenv, fn (), e (), uEmpty);
1096 ans.append (v.release ());
1100 return ans.release ();
1105 (mapcar-append LAMBDA LIST...) -> LIST
1108 //#AFUNC mapcar-append ml_mapcar_append
1109 //#WIKIFUNC mapcar-append
1110 MNode* ml_mapcar_append (MNode* cell, MlEnv* mlenv) {
1111 MNode* arg = cell->cdr ();
1120 throw (uErrorWrongNumber);
1121 fn = eval (arg->car (), mlenv);
1122 nextNodeNonNil (arg);
1124 list.append (eval (arg->car (), mlenv));
1129 throw (uErrorSyntax);
1130 } else if (isLambda (fn ())) {
1131 } else if (fn ()->isSym ()) {
1133 throw (uErrorSyntax);
1135 if (isNil (list ()))
1138 if (fn ()->isSym ()) {
1145 if (h () && h ()->isCons ()) {
1146 e.append (newMNode_quote (h ()->car ()));
1148 arg->set_car (h ()->cdr ());
1158 h ()->set_car (fn ());
1159 h ()->set_cdr (e.release ());
1160 v = eval (h (), mlenv);
1162 } else if (v ()->isCons ()) {
1165 ans.append (a->car ());
1169 ans.append (v.release ()); // XXX: hack
1179 if (h () && h ()->isCons ()) {
1180 e.append (h ()->car ());
1182 arg->set_car (h ()->cdr ());
1191 v = execDefun (mlenv, fn (), e (), uEmpty);
1193 } else if (v ()->isCons ()) {
1196 ans.append (a->car ());
1200 ans.append (v.release ()); // XXX: hack
1205 return ans.release ();
1210 (mapcar-concat LAMBDA LIST...) -> LIST
1213 //#AFUNC mapcar-concat ml_mapcar_concat
1214 //#WIKIFUNC mapcar-concat
1215 MNode* ml_mapcar_concat (MNode* cell, MlEnv* mlenv) {
1216 MNode* arg = cell->cdr ();
1225 throw (uErrorWrongNumber);
1226 fn = eval (arg->car (), mlenv);
1227 nextNodeNonNil (arg);
1229 list.append (eval (arg->car (), mlenv));
1234 throw (uErrorSyntax);
1235 } else if (isLambda (fn ())) {
1236 } else if (fn ()->isSym ()) {
1238 throw (uErrorSyntax);
1240 if (isNil (list ()))
1243 if (fn ()->isSym ()) {
1250 if (h () && h ()->isCons ()) {
1251 e.append (newMNode_quote (h ()->car ()));
1253 arg->set_car (h ()->cdr ());
1263 h ()->set_car (fn ());
1264 h ()->set_cdr (e.release ());
1265 v = eval (h (), mlenv);
1268 ans.append (v.release ());
1278 if (h () && h ()->isCons ()) {
1279 e.append (h ()->car ());
1281 arg->set_car (h ()->cdr ());
1290 v = execDefun (mlenv, fn (), e (), uEmpty);
1293 ans.append (v.release ());
1298 return ans.release ();
1303 (member ELT LIST) -> LIST
1305 Return 1 if LIST contaions ELT. The comparison is done by ===.
1308 //#AFUNC member ml_member
1310 MNode* ml_member (MNode* cell, MlEnv* mlenv) {
1311 MNode* arg = cell->cdr ();
1316 throw (uErrorWrongNumber);
1317 elt = eval (arg->car (), mlenv);
1319 list = eval (arg->car (), mlenv);
1322 throw (uErrorWrongNumber);
1326 if (eq (elt (), arg->car ())) {
1327 return newMNode_bool (true);
1336 (memberp LAMBDA LIST) -> LIST
1338 Return first cdr of LIST that the LAMBDA applied the element returns true.
1341 //#AFUNC memberp ml_memberp
1343 MNode* ml_memberp (MNode* cell, MlEnv* mlenv) {
1344 MNode* arg = cell->cdr ();
1349 throw (uErrorWrongNumber);
1350 fn = eval (arg->car (), mlenv);
1352 list = eval (arg->car (), mlenv);
1355 throw (uErrorWrongNumber);
1358 throw (uErrorSyntax);
1359 } else if (isLambda (fn ())) {
1360 } else if (fn ()->isSym ()) {
1362 throw (uErrorSyntax);
1366 if (fn ()->isSym ()) {
1368 sexp = new MNode ();
1369 sexp ()->set_car (fn ());
1370 MNode* q = new MNode ();
1371 sexp ()->set_cdr (q);
1375 q->set_car (eval (arg->car (), mlenv));
1376 if (eval_bool (sexp (), mlenv))
1384 h ()->set_car (arg->car ());
1385 h = execDefun (mlenv, fn (), h (), uEmpty);
1396 (reverse LIST) -> LIST
1399 //#AFUNC reverse ml_reverse
1401 MNode* ml_reverse (MNode* cell, MlEnv* mlenv) {
1402 MNode* arg = cell->cdr ();
1408 throw (uErrorWrongNumber);
1409 a = eval (arg->car (), mlenv);
1412 throw (uErrorWrongNumber);
1414 if (! a () || ! a ()->isCons ()) {
1417 while (a () && a ()->isCons ()) {
1419 c->set_car (a ()->car ());
1420 c->set_cdr (ans ());
1426 return mlenv->retval = ans.release ();