} else {
nextNode (arg);
if (arg) {
-// ans = progn (arg, mlenv, cell->car ());
ans = progn (arg, mlenv);
if (mlenv->breaksym ()
- && (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))) {
+ && (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ())))
mlenv->breaksym = NULL;
- }
}
}
}
if (! a->isCons ())
throw (a->dump_string () + uErrorBadType);
if (eval_bool (a->car (), mlenv)) {
-// ans = progn (a->cdr (), mlenv, cell->car ());
ans = progn (a->cdr (), mlenv);
if (mlenv->breaksym ()
- && (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))) {
+ && (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ())))
mlenv->breaksym = NULL;
- }
break;
}
nextNode (arg);
MNode* arg = cell->cdr ();
MNodePtr ans;
-// ans = progn (arg, mlenv, cell->car ());
ans = progn (arg, mlenv);
if (mlenv->breaksym ()
&& (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))) {
}
/*DOC:
+===select===
+===case===
+===otherwise===
+ (select
+ (case BOOL1 BLOCK1)
+ (case BOOL2 BLOCK2)
+ ...
+ (otherwise BLOCKn))
+*/
+//#AFUNC select ml_select
+//#WIKIFUNC select ml_select
+//#AFUNC case ml_case
+//#WIKIFUNC case ml_case
+//#AFUNC otherwise ml_otherwise
+//#WIKIFUNC otherwise ml_otherwise
+MNode* ml_select (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr ans;
+
+ while (arg && ! mlenv->noprog) {
+#ifdef DEBUG
+ mlenv->logSexp (arg->car ());
+#endif /* DEBUG */
+ ans = eval (arg->car (), mlenv);
+ nextNode (arg);
+ if (ans ()) {
+ if (ans ()->isCons () && to_bool (ans ()->car ())) {
+ ans = ans ()->cdr ();
+ return ans.release ();
+ }
+ } else {
+ return NULL;
+ }
+ }
+ return NULL;
+}
+
+MNode* ml_case (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr ans;
+ bool r;
+
+ if (! arg)
+ throw (uErrorWrongNumber);
+
+ r = eval_bool (arg->car (), mlenv);
+ nextNode (arg);
+ ans = new MNode;
+ if (r) {
+ ans ()->set_car (newMNode_bool (true));
+ ans ()->set_cdr (progn (arg, mlenv));
+ if (mlenv->breaksym ()) {
+ if (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))
+ mlenv->breaksym = NULL;
+ }
+ }
+
+ return ans.release ();
+}
+
+MNode* ml_otherwise (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+ MNodePtr ans;
+
+ ans = new MNode;
+ ans ()->set_car (newMNode_bool (true));
+ ans ()->set_cdr (progn (arg, mlenv));
+ if (mlenv->breaksym ()) {
+ if (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))
+ mlenv->breaksym = NULL;
+ }
+
+ return ans.release ();
+}
+
+/*DOC:
===repeat===
(repeat VARIABLE FROM TO [:step ADD] [:array VARLIST] BODY...) -> LAST VALUE
exp = arg->car ();
nextNode (arg);
while (eval_bool (exp, mlenv)) {
-// ans = progn (arg, mlenv, cell->car ());
ans = progn (arg, mlenv);
if (mlenv->breaksym ()) {
if (mlenv->breaksym ()->isNil () || eq (mlenv->breaksym (), cell->car ()))
MNode* ml_list (MNode* cell, MlEnv* mlenv);
MNode* ml_if (MNode* cell, MlEnv* mlenv);
MNode* ml_cond (MNode* cell, MlEnv* mlenv);
+MNode* ml_select (MNode* cell, MlEnv* mlenv);
+MNode* ml_case (MNode* cell, MlEnv* mlenv);
+MNode* ml_otherwise (MNode* cell, MlEnv* mlenv);
MNode* ml_progn (MNode* cell, MlEnv* mlenv);
MNode* ml_repeat (MNode* cell, MlEnv* mlenv);
MNode* ml_doarray (MNode* cell, MlEnv* mlenv);