Commit basic (and ...) & (or ...) *functions*, with lambda args.
This commit is contained in:
parent
893b7e122e
commit
9af29f28da
|
|
@ -0,0 +1,26 @@
|
||||||
|
#S(#="lambda"
|
||||||
|
; (define (test-and)
|
||||||
|
; (and (lambda () 3)
|
||||||
|
; (lambda () #t)
|
||||||
|
; (lambda () 4)
|
||||||
|
; (lambda () #f)
|
||||||
|
; (lambda () 5)))
|
||||||
|
#(
|
||||||
|
#i"../lib/primitive/and.rla"
|
||||||
|
(
|
||||||
|
#S(#="lambda" #(( 3) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #((#t) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #(( 4) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #((#f) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #(( 5) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
#()
|
||||||
|
0
|
||||||
|
""
|
||||||
|
0x01 ; g1
|
||||||
|
0x02 ; g2
|
||||||
|
0xfe ; k
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
; vim:set syntax= sw=2 expandtab:
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
#S(#="lambda"
|
||||||
|
; (define (test-or)
|
||||||
|
; (and (lambda () #f)
|
||||||
|
; (lambda () 3)
|
||||||
|
; (lambda () #f)
|
||||||
|
; (lambda () #t)
|
||||||
|
; (lambda () #f)))
|
||||||
|
#(
|
||||||
|
#i"../lib/primitive/or.rla"
|
||||||
|
(
|
||||||
|
#S(#="lambda" #((#f) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #(( 3) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #((#f) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #((#t) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
#S(#="lambda" #((#f) #f) #() 0 "" 0xfe 0x01 0x02 0x02)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
#()
|
||||||
|
0
|
||||||
|
""
|
||||||
|
0x01 ; g1
|
||||||
|
0x02 ; g2
|
||||||
|
0xfe ; k
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
; vim:set syntax= sw=2 expandtab:
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
;; Evaluates each function in turn, returning #f immediately if any
|
||||||
|
;; function returns #f, or else the first result of the last function.
|
||||||
|
|
||||||
|
; (define (and . fns)
|
||||||
|
; (let/cc k
|
||||||
|
; (foldl (lambda (fn _)
|
||||||
|
; (let/cc k2
|
||||||
|
; ((lambda (x)
|
||||||
|
; ((if x k2 k) x))
|
||||||
|
; (fn))))
|
||||||
|
; #t
|
||||||
|
; fns))
|
||||||
|
|
||||||
|
#S(#="lambda"
|
||||||
|
#(
|
||||||
|
#i"foldl.rla"
|
||||||
|
#S(#="template"
|
||||||
|
; (lambda (fn _)
|
||||||
|
; (let/cc k2
|
||||||
|
; ((lambda (x)
|
||||||
|
; ((if x k2 k) x))
|
||||||
|
; (fn))))
|
||||||
|
#(
|
||||||
|
#S(#="template"
|
||||||
|
; (lambda (x)
|
||||||
|
; ((if x k2 k) x))
|
||||||
|
#(#f)
|
||||||
|
"\x40\xfe" ; i0 k
|
||||||
|
1
|
||||||
|
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||||
|
\x80\x80\x41\x40"; (set! f0 (if f0 i1 i0))
|
||||||
|
0x80 ; f0
|
||||||
|
0xfd ; argv
|
||||||
|
0x01 ; g1
|
||||||
|
0x01 ; g1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"\xfe" ; k
|
||||||
|
2
|
||||||
|
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||||
|
\x00\x81\x1b\x01"; (set! f1 (lambda g1))
|
||||||
|
0x80 ; f0
|
||||||
|
0x00 ; nil
|
||||||
|
0x81 ; f1
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
#t
|
||||||
|
)
|
||||||
|
#()
|
||||||
|
2
|
||||||
|
"\x02\x80\xfd\x00\; (set! f0 (cons argv nil))
|
||||||
|
\x02\x80\x03\x80\; (set! f0 (cons g3 f0))
|
||||||
|
\x00\x81\x1b\x02\; (set! f1 (lambda g2))
|
||||||
|
\x02\x80\x81\x80"; (set! f0 (cons f1 f0))
|
||||||
|
0x01 ; g1
|
||||||
|
0x80 ; f0
|
||||||
|
0xfe ; k
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
; vim:set syntax= sw=2 expandtab:
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
;; Evaluates each function in turn, immediately returning the first
|
||||||
|
;; non-#f result, or #f if no function returns a non-#f result.
|
||||||
|
|
||||||
|
; (define (or . fns)
|
||||||
|
; (let/cc k
|
||||||
|
; (foldl (lambda (fn _)
|
||||||
|
; (let/cc k2
|
||||||
|
; ((lambda (x)
|
||||||
|
; ((if x k k2) x))
|
||||||
|
; (fn))))
|
||||||
|
; #f
|
||||||
|
; fns))
|
||||||
|
|
||||||
|
#S(#="lambda"
|
||||||
|
#(
|
||||||
|
#i"foldl.rla"
|
||||||
|
#S(#="template"
|
||||||
|
; (lambda (fn _)
|
||||||
|
; (let/cc k2
|
||||||
|
; ((lambda (x)
|
||||||
|
; ((if x k2 k) x))
|
||||||
|
; (fn))))
|
||||||
|
#(
|
||||||
|
#S(#="template"
|
||||||
|
; (lambda (x)
|
||||||
|
; ((if x k2 k) x))
|
||||||
|
#(#f)
|
||||||
|
"\x40\xfe" ; i0 k
|
||||||
|
1
|
||||||
|
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||||
|
\x80\x80\x40\x41"; (set! f0 (if f0 i0 i1))
|
||||||
|
0x80 ; f0
|
||||||
|
0xfd ; argv
|
||||||
|
0x01 ; g1
|
||||||
|
0x01 ; g1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
"\xfe" ; k
|
||||||
|
2
|
||||||
|
"\x00\x80\x03\xfd\; (set! f0 (car argv))
|
||||||
|
\x00\x81\x1b\x01"; (set! f1 (lambda g1))
|
||||||
|
0x80 ; f0
|
||||||
|
0x00 ; nil
|
||||||
|
0x81 ; f1
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
#f
|
||||||
|
)
|
||||||
|
#()
|
||||||
|
2
|
||||||
|
"\x02\x80\xfd\x00\; (set! f0 (cons argv nil))
|
||||||
|
\x02\x80\x03\x80\; (set! f0 (cons g3 f0))
|
||||||
|
\x00\x81\x1b\x02\; (set! f1 (lambda g2))
|
||||||
|
\x02\x80\x81\x80"; (set! f0 (cons f1 f0))
|
||||||
|
0x01 ; g1
|
||||||
|
0x80 ; f0
|
||||||
|
0xfe ; k
|
||||||
|
0xff ; ctx
|
||||||
|
)
|
||||||
|
; vim:set syntax= sw=2 expandtab:
|
||||||
Loading…
Reference in New Issue