mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 05:50:26 +02:00
New, from Daniel Skarda. Thanks!
This commit is contained in:
parent
012a3a7537
commit
feeef4fb40
1 changed files with 31 additions and 0 deletions
31
srfi/srfi-26.scm
Normal file
31
srfi/srfi-26.scm
Normal file
|
@ -0,0 +1,31 @@
|
|||
(define-module (srfi srfi-26)
|
||||
:export (cut cute))
|
||||
|
||||
(cond-expand-provide (current-module) '(srfi-26))
|
||||
|
||||
(define-macro (cut slot . slots)
|
||||
(let loop ((slots (cons slot slots))
|
||||
(params '())
|
||||
(args '()))
|
||||
(if (null? slots)
|
||||
`(lambda ,(reverse! params) ,(reverse! args))
|
||||
(let ((s (car slots))
|
||||
(rest (cdr slots)))
|
||||
(case s
|
||||
((<>)
|
||||
(let ((var (gensym)))
|
||||
(loop rest (cons var params) (cons var args))))
|
||||
((<...>)
|
||||
(if (pair? rest)
|
||||
(error "<...> not on the end of cut expression"))
|
||||
(let ((var (gensym)))
|
||||
`(lambda ,(append! (reverse! params) var)
|
||||
(apply ,@(reverse! (cons var args))))))
|
||||
(else
|
||||
(loop rest params (cons s args))))))))
|
||||
|
||||
(define-macro (cute . slots)
|
||||
(let ((temp (map (lambda (s) (and (not (memq s '(<> <...>))) (gensym)))
|
||||
slots)))
|
||||
`(let ,(delq! #f (map (lambda (t s) (and t (list t s))) temp slots))
|
||||
(cut ,@(map (lambda (t s) (or t s)) temp slots)))))
|
Loading…
Add table
Add a link
Reference in a new issue