diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | eval.c | 3 | ||||
-rw-r--r-- | txr.1 | 12 |
3 files changed, 17 insertions, 6 deletions
@@ -1,3 +1,11 @@ +2012-09-25 Kaz Kylheku <kaz@kylheku.com> + + * eval.c: Allow the test form of a for loop to be omitted, + defaulting to a true test, allowing an infinite loop to + be expressed as (for () () () ...). + + * txr.1: Documented. + 2012-09-24 Kaz Kylheku <kaz@kylheku.com> * RELNOTES: Correct incorrect 2011 years on all 2012 dates. @@ -1010,7 +1010,8 @@ static val op_for(val form, val env) uw_block_begin (nil, result); - for (; eval(car(cond), new_env, form); eval_progn(incs, new_env, form)) + for (; cond == nil || eval(car(cond), new_env, form); + eval_progn(incs, new_env, form)) eval_progn(forms, new_env, form); result = eval_progn(rest(cond), new_env, form); @@ -5498,7 +5498,7 @@ Examples: Syntax: ({for | for*} ({<sym> | (<sym> <init-form>)}*) - (<test-form> <result-form>*) + ([<test-form> <result-form>*]) (<inc-form>*) <body-form>*) @@ -5510,6 +5510,7 @@ The first argument is a list of variables with optional initializers, exactly the same as in the let and let* operators. Furthermore, the difference between for and for* is like that between let and let* with regard to this list of variables. + The for operators execute these steps: 1. Establish bindings for the specified variables similarly to let @@ -5519,10 +5520,11 @@ and let*. The variable bindings are visible over the <test-form>, each 2. Establish an anonymous block over the remaining forms, allowing the return operator to be used to terminate the loop. -3. Evaluate <test-form>. If <test-form> yields nil, then each -<result-form> is evaluated, and the vale of the last of these forms -is is the result value of the for loop. If there are no such forms -then the return value is nil. +3. Evaluate <test-form>. If <test-form> yields nil, then the loop +terminates. Each <result-form> is evaluated, and the value of the last of these +forms is is the result value of the for loop. If there are no <result-form>-s +then the result value is nil. If the <test-form> is omitted, then the +the test is taken to be true, and the loop does not terminate. 4. Otherwise, if <test-form> yields non-nil, then each <body-form> is evaluated in turn. Then, each <inc-form> is evaluated in turn |