Make (foldl ...) state the second argument, as with (foldr ...).
This commit is contained in:
parent
c6500a53b3
commit
2d7b079dd8
|
|
@ -1,16 +1,16 @@
|
||||||
;; Fold a function over a list; left-associative
|
;; Fold a function over a list; left-associative
|
||||||
;; (foldl fn init lst)
|
;; (foldl fn init lst)
|
||||||
;; ==> (foldl fn (fn init (car lst)) (cdr lst))
|
;; ==> (foldl fn (fn (car lst) init) (cdr lst))
|
||||||
|
|
||||||
; (define (foldl fn init lst)
|
; (define (foldl fn init lst)
|
||||||
; (if (pair? lst)
|
; (if (pair? lst)
|
||||||
; (foldl fn (fn init (car lst)) (cdr lst))
|
; (foldl fn (fn (car lst) init) (cdr lst))
|
||||||
; init))
|
; init))
|
||||||
|
|
||||||
#0=#S(#="lambda"
|
#0=#S(#="lambda"
|
||||||
; (define (foldl fn init lst)
|
; (define (foldl fn init lst)
|
||||||
; ((if (pair? lst)
|
; ((if (pair? lst)
|
||||||
; (lambda () (foldl fn (fn init (car lst)) (cdr lst))
|
; (lambda () (foldl fn (fn (car lst) init) (cdr lst))
|
||||||
; (lambda () init))))
|
; (lambda () init))))
|
||||||
#(
|
#(
|
||||||
#S(#="template"
|
#S(#="template"
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
; (call-with-multiple-values
|
; (call-with-multiple-values
|
||||||
; (lambda (new-init)
|
; (lambda (new-init)
|
||||||
; (k (foldl fn new-init (cdr lst))))
|
; (k (foldl fn new-init (cdr lst))))
|
||||||
; (lambda () (fn init (car lst))))))
|
; (lambda () (fn (car lst) init)))))
|
||||||
#(
|
#(
|
||||||
#S(#="template"
|
#S(#="template"
|
||||||
; (lambda (new-init)
|
; (lambda (new-init)
|
||||||
|
|
@ -51,9 +51,9 @@
|
||||||
)
|
)
|
||||||
"\x80\x81\x82" ; f0=fn f1=init f2=lst
|
"\x80\x81\x82" ; f0=fn f1=init f2=lst
|
||||||
2
|
2
|
||||||
"\x00\x80\x03\x42\; (set! f0 (car i2))
|
"\x02\x80\x41\x00\; (set! f0 (cons i1 nil))
|
||||||
\x02\x80\x80\x00\; (set! f0 (cons f0 nil))
|
\x00\x81\x03\x42\; (set! f1 (car i2))
|
||||||
\x02\x80\x41\x80\; (set! f0 (cons i1 f0))
|
\x02\x80\x81\x80\; (set! f0 (cons f1 f0))
|
||||||
\x00\x81\x1b\x01"; (set! f1 (lambda g1))
|
\x00\x81\x1b\x01"; (set! f1 (lambda g1))
|
||||||
0x40 ; i0
|
0x40 ; i0
|
||||||
0x80 ; f0
|
0x80 ; f0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue