diff options
-rw-r--r-- | eval.c | 18 | ||||
-rw-r--r-- | txr.1 | 28 |
2 files changed, 44 insertions, 2 deletions
@@ -3430,16 +3430,30 @@ static val me_iflet_whenlet(val form, val env) return apply_frob_args(list(if3(sym == iflet_s, if_s, when_s), lets, args, nao)); } else { - val lastlet = last(lets, nil); + val lastlet_cons = last(lets, nil); + val lastlet = car(lastlet_cons); if (nilp(lastlet)) eval_error(form, lit("~s: empty binding list"), sym, nao); + if (!consp(lastlet)) + eval_error(form, lit("~s: bad binding syntax ~s"), sym, lastlet, nao); + { + val var = car(lastlet); + + if (!cdr(lastlet)) { + if (symbolp(var) && bindable(var)) + eval_warn(form, lit("~s: ~s is init-form here, not new variable"), + sym, var, nao); + push(gensym(nil), &lastlet); + lets = append2(butlast(lets, nil), cons(lastlet, nil)); + } + } return list(let_star_s, lets, cons(if3(sym == iflet_s, if_s, when_s), - cons(car(car(lastlet)), args)), nao); + cons(car(lastlet), args)), nao); } } @@ -13810,6 +13810,28 @@ Then, the last variable's value is tested. If it is not .code nil then the test is true, otherwise false. +In the syntax, a small convenience is permitted. Instead of the last +.cblk +.meti >> ( sym << init-form ) +.cble +it is permissible for the syntax +.cblk +.meti <> ( init-form ) +.cble +to appear, the +.meta sym +being omitted. A machine-generated variable is substituted +in place of the missing +.meta sym +and that variable is then initialized from +.meta init-form +and used as the basis of the test. This is intended to be useful +in situations in which +.meta then-form +or +.meta else-form +do not require access to the tested value. + In the case of the .code iflet operator, if the test is true, the operator evaluates @@ -13854,6 +13876,12 @@ is returned. (exceeds-p (> fv 150))) (format t "frobosity value ~a exceeds 150\en" fv)) + ;; same as above, taking advantage of the + ;; last variable being optional: + (whenlet ((fv (get-frobosity-value)) + ((> fv 150))) + (format t "frobosity value ~a exceeds 150\en" fv)) + ;; yield 4: 3 interpreted as atom-form (whenlet 3 4) |