mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
Adding for loop shortcut syntax.
This commit is contained in:
parent
2ac6b0f271
commit
08cf38851e
3 changed files with 18 additions and 4 deletions
|
@ -171,4 +171,9 @@
|
|||
(for res (listing i)))
|
||||
=> res))
|
||||
|
||||
(test '(1 4 9)
|
||||
(for ((i (in-list '(1 2 3)))
|
||||
(res (listing (* i i))))
|
||||
=> res))
|
||||
|
||||
(test-end))))
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
(define-library (chibi loop)
|
||||
(export loop in-list in-lists in-port in-file up-from down-from
|
||||
(export loop for in-list in-lists in-port in-file up-from down-from
|
||||
listing listing-reverse appending appending-reverse
|
||||
summing multiplying in-string in-string-reverse
|
||||
in-vector in-vector-reverse)
|
||||
(import (chibi))
|
||||
(include "loop/loop.scm"))
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
;;;; loop.scm - the chibi loop (aka foof-loop)
|
||||
;;
|
||||
;; Copyright (c) 2009-2012 Alex Shinn. All rights reserved.
|
||||
;; Copyright (c) 2009-2015 Alex Shinn. All rights reserved.
|
||||
;; BSD-style license: http://synthcode.com/license.txt
|
||||
|
||||
;;> The loop API is mostly compatible with Taylor Campbell's
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;;> \subsubsubsection{\scheme{(loop [name] (vars ...) [=> result] body ...)}}
|
||||
;;> \macro{\scheme{(loop [name] (vars ...) [=> result] body ...)}}
|
||||
|
||||
(define-syntax loop
|
||||
(syntax-rules ()
|
||||
|
@ -123,6 +123,16 @@
|
|||
(finals ... new-finals ...)
|
||||
. rest))))
|
||||
|
||||
;;> Utility syntax for the common case of a loop which has only
|
||||
;;> \scheme{for} clauses.
|
||||
|
||||
(define-syntax for
|
||||
(syntax-rules ()
|
||||
((for ((vars ...) ...) body ...)
|
||||
(loop ((for vars ...) ...) body ...))
|
||||
((for lp ((vars ...) ...) body ...)
|
||||
(loop lp ((for vars ...) ...) body ...))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;> \section{Iterators}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue