diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-04-05 09:23:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-04-05 09:23:15 -0700 |
commit | c8dc7ebafbf945c2ea5afb48464b4a54fd381713 (patch) | |
tree | 44247716acef15f800f65e3ad7fc388ae1455ead /txr.1 | |
parent | 74134c4a71029af056b7c55fbb4e65c866d35e5d (diff) | |
download | txr-c8dc7ebafbf945c2ea5afb48464b4a54fd381713.tar.gz txr-c8dc7ebafbf945c2ea5afb48464b4a54fd381713.tar.bz2 txr-c8dc7ebafbf945c2ea5afb48464b4a54fd381713.zip |
New whilet macro.
* eval.c (while_s): New symbol variable.
(me_whilet): New static function.
(eval_init): Initialize while_s. Use while_s in registration
of while macro. Register new whilet macro.
* txr.1: whilet is documented.
* tl.vim, txr.vim: Regenerated.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 63 |
1 files changed, 63 insertions, 0 deletions
@@ -10029,6 +10029,69 @@ is if the operator is used to terminate the implicit anonymous block, and is given an argument, which becomes the result value. +.coNP Macro @ whilet +.synb +.mets (whilet ({ sym | >> ( sym << init-form )}+) +.mets \ \ < body-form *) +.syne +.desc +The +.code whilet +macro provides a construct which combines iteration with variable +binding. + +The evaluation of the form takes place as follows. First, fresh bindings are +established for +.metn sym -s +as if by the +.code let* +operator. +It is an error for the list of variable bindings to be empty. + +After the establishment of the bindings, the the value of the +.meta sym +is tested. If the value is +.codn nil , +then +.code whilet +terminates. Otherwise, +.metn body-form -s +are evaluated in the scope of the variable bindings, and then +.code whilet +iterates from the beginning, again establishing fresh bindings for the +.metn sym -s, +and testing the value of the last +.metn sym . + + +All evaluation takes place in an anonymous block, which can be +terminated with the +.code return +operator. Doing so terminates the loop. +If the +.code whilet +loop is thus terminated by an explicit +.codn return , +a return value can be specified. Under normal termination, the return value is +.codn nil . + +.TP* Examples: +.cblk + ;; read lines of text from *std-input* and print them, + ;; until the end-of-stream condition: + + (whilet ((line (get-line))) + (put-line line)) + + ;; read lines of text from *std-input* and print them, + ;; until the end-of-stream condition occurs or + ;; a line is identical to the character string "end". + + (whilet ((line (get-line)) + (more (and line (not (equal line "end"))))) + (put-line line)) +.cble + .coNP Operator/function @ if .synb .mets (if < cond < t-form <> [ e-form ]) |