Commit (append ...) function, implemented as nested (foldr ...) calls.

This commit is contained in:
Jesse D. McDonald 2010-04-11 16:13:20 -05:00
parent a6715b0922
commit 893b7e122e
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,16 @@
#S(#="lambda"
; (define (test-append)
; (append '(1 2 3) (4 5) (6 7 8 9)))
#(
#i"../lib/primitive/append.rla"
((1 2 3) (4 5) (6 7 8 9))
)
#()
0
""
0x01 ; g1
0x02 ; g2
0xfe ; k
0xff ; ctx
)
; vim:set syntax= sw=2 expandtab:

View File

@ -0,0 +1,41 @@
;; Concatenates the list argument(s) into a single new list.
; (define (append . lsts)
; (foldr (lambda (lst base)
; (foldr cons base lst))
; nil
; lsts))
#S(#="lambda"
#(
#i"foldr.rla"
#S(#="lambda"
#(
#i"foldr.rla"
#i"cons.rla"
)
#()
2
"\x00\x80\x03\xfd\; (set! f0 (car argv))
\x02\x81\x80\x00\; (set! f1 (cons f0 nil))
\x00\x80\x04\xfd\; (set! f0 (cdr argv))
\x00\x80\x03\x80\; (set! f0 (car f0))
\x02\x81\x80\x81\; (set! f1 (cons f0 f1))
\x02\x81\x02\x81"; (set! f1 (cons g2 f1))
0x01 ; g1
0x81 ; f1
0xfe ; k
0xff ; ctx
)
)
#()
1
"\x02\x80\xfd\x00\; (set! f0 (cons argv nil))
\x02\x80\x00\x80\; (set! f0 (cons nil f0))
\x02\x80\x02\x80"; (set! f0 (cons g2 f0))
0x01 ; g1
0x80 ; f0
0xfe ; k
0xff ; ctx
)
; vim:set syntax= sw=2 expandtab: