mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 08:47:35 +02:00
Added (append)
This commit is contained in:
parent
ef53201de5
commit
fac76980fe
1 changed files with 14 additions and 0 deletions
14
trans.scm
14
trans.scm
|
@ -70,6 +70,20 @@
|
|||
((pair? obj)
|
||||
(list? (cdr obj)))
|
||||
(else #f)))
|
||||
; append accepts a variable number of arguments, per R5RS. So a wrapper
|
||||
; has been provided for the standard 2-argument version of (append).
|
||||
;
|
||||
; We return the given value if less than 2 arguments are given, and
|
||||
; otherwise fold over each arg, appending it to its predecessor.
|
||||
(define (append . lst)
|
||||
(define append-2
|
||||
(lambda (inlist alist)
|
||||
(foldr (lambda (ap in) (cons ap in)) alist inlist)))
|
||||
(if (null? lst)
|
||||
lst
|
||||
(if (null? (cdr lst))
|
||||
(car lst)
|
||||
(foldl (lambda (a b) (append-2 b a)) (car lst) (cdr lst)))))
|
||||
(define (list . objs) objs)
|
||||
(define (map func lst)
|
||||
(foldr (lambda (x y) (cons (func x) y)) '() lst))
|
||||
|
|
Loading…
Add table
Reference in a new issue