TOC »
simple-loops
This module exports some simple loop macros. The syntax of some of them has changed, but the earlier versions are still valid, albeit deprecated.
The routines
simple-loops
- simple-loops #!optional symprocedure
documentation-procedure; returns the list of exported symbols if called with no symbol, otherwise the signature of that exported symbol sym.
do-for
- (do-for (var start stop step) xpr . xprs)syntax
- (do-for (var start stop) xpr . xprs)syntax
- ; deprecated
- (do-for var (start stop step) xpr . xprs)syntax
- (do-for var (start stop) xpr . xprs)syntax
for-loop: do xpr . xprs for var in [start stop[ with step defaulting to 1")
do-forever
- (do-forever xpr . xprs)syntax
endless loop: executes body xpr . xprs until exit is called, a symbol being defined behind the scenes.
do-list
- (do-list (var lst) xpr . xprs)syntax
- ; deprecated
- (do-list var lst xpr . xprs)syntax
loop along a list: execute xpr . xprs for var in lst
do-times
- (do-times (k upto) xpr . xprs)syntax
- ; deprecated
- (do-times k upto xpr . xprs)syntax
loops a fixed number of times: execute xpr . xprs for k in [0 upto[
do-until
- (do-until test? xpr . xprs)syntax
until-loop: execute xpr . xprs while test? is false
do-while
- (do-while test? xpr . xprs)syntax
while-loop: execute xpr . xprs while test? is true
Requirements
none
Example
(import simple-loops) (let ((lst '())) (do-for (var 1 65 var) (set! lst (cons var lst))) (reverse lst)) ;-> '(1 2 4 8 16 32 64) (let ((n 3) (lst '())) (do-forever (if (zero? n) (exit lst)) (set! lst (cons 'a lst)) (set! n (- n 1)))) ;-> '(a a a) (let ((lst '())) (do-list (var '(1 2 3)) (set! lst (cons var lst))) lst) ;-> '(3 2 1) (let ((lst '())) (do-times (k (+ 2 3)) (set! lst (cons k lst))) lst) ;-> '(4 3 2 1 0) (let ((n 4) (lst '())) (do-until (> 0 n) (set! lst (cons n lst)) (set! n (- n 1))) lst) ;-> '(0 1 2 3 4) (let ((n 4) (lst '())) (do-while (<= 0 n) (set! lst (cons n lst)) (set! n (- n 1))) lst) ;-> '(0 1 2 3 4)
Last update
May 18, 2022
Author
License
Copyright (c) 2013-2022, Juergen Lorenz All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version History
- 1.0
- port from chicken-4
- 2.0
- some loops with new syntax; the old syntax is deprecated