Changes for the better
* goof-impl.scm (loop/first loop/last): add ability to specify a :default value. Added auxiliary syntax :default. * goof/iterators.scm (accumulating hash(q|v)ing): changed auxiliary keyword from initial -> :initial. * goof.scm: export extra keywords * doc.html * doc.xml : document changes. fix bugs.
This commit is contained in:
parent
1de0a624f5
commit
832c414260
6 changed files with 77 additions and 61 deletions
|
@ -32,11 +32,15 @@
|
|||
:when :unless :break :final :bind :do :subloop :for :acc
|
||||
;; Auxiliary syntax for the iterators.
|
||||
:gen
|
||||
;; auxiliary syntax for some accumulators
|
||||
:initial
|
||||
;; auxiliary auxiliary syntax
|
||||
;; for vectoring
|
||||
:length :fill
|
||||
;;for up-from and down-to
|
||||
:to :by
|
||||
;; used by for/first and for/last
|
||||
:default
|
||||
;; Internal syntax. %acc is turned into :acc by the forify macro
|
||||
;; it is used make it possible to report an error if :acc is used in
|
||||
;; one of the simple macros.
|
||||
|
@ -491,27 +495,32 @@
|
|||
=> acc
|
||||
(product-loop)))))
|
||||
|
||||
(define sentinel (list 'unique))
|
||||
|
||||
;; TODO: maybe have a look at the expansion of this. It seems weird.
|
||||
;; This exploits that we give the loop a name, but don't add the loop to the end of the
|
||||
;; body, thus returning whatever the last expr of body returns.
|
||||
(define-syntax loop/first
|
||||
(syntax-rules ()
|
||||
((n (clauses ...) body ...)
|
||||
(syntax-rules (:default)
|
||||
((n :default val (clauses ...) body ...)
|
||||
(forify (n (clauses ...) body ...)
|
||||
loop/first
|
||||
() (clauses ... (:final #t))
|
||||
=> #f
|
||||
body ...))))
|
||||
|
||||
|
||||
(define-syntax loop/last
|
||||
(syntax-rules ()
|
||||
() (clauses ...)
|
||||
=> val
|
||||
body ...))
|
||||
((n (clauses ...) body ...)
|
||||
(loop/first :default #f (clauses ...) body ...))))
|
||||
|
||||
|
||||
;; unique value used for loop/last
|
||||
(define sentinel (list 'unique))
|
||||
(define-syntax loop/last
|
||||
(syntax-rules (:default)
|
||||
((n :default val (clauses ...) body ...)
|
||||
(forify (n (clauses ...) body ...)
|
||||
loop-name () (clauses ... (%acc acc (folding sentinel)))
|
||||
=> (if (eq? sentinel acc) #f acc)
|
||||
=> (if (eq? sentinel acc) val acc)
|
||||
(let ((result (let () body ...)))
|
||||
(loop-name (=> acc result)))))))
|
||||
(loop-name (=> acc result)))))
|
||||
((n (clauses ...) body ...)
|
||||
(loop/last :default #f (clauses ...) body ...))))
|
||||
|
||||
(define-syntax loop/and
|
||||
(syntax-rules ()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue