projects
/
lambda.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
posted assignment4
[lambda.git]
/
lambda_library.mdwn
diff --git
a/lambda_library.mdwn
b/lambda_library.mdwn
index
bdd0168
..
423ad59
100644
(file)
--- a/
lambda_library.mdwn
+++ b/
lambda_library.mdwn
@@
-63,8
+63,12
@@
and all sorts of other places. Others of them are our own handiwork.
; very inefficient but correct reverse
let reverse = \lst. lst (\h sofar. append sofar (singleton h)) empty in ; or
; more efficient reverse builds a left-fold instead
; very inefficient but correct reverse
let reverse = \lst. lst (\h sofar. append sofar (singleton h)) empty in ; or
; more efficient reverse builds a left-fold instead
- ;
(
make_left_list a (make_left_list b (make_left_list c empty)) ~~> \f z. f c (f b (f a z))
+ ; make_left_list a (make_left_list b (make_left_list c empty)) ~~> \f z. f c (f b (f a z))
let reverse = (\make_left_list lst. lst make_left_list empty) (\h t f z. t f (f h z)) in
let reverse = (\make_left_list lst. lst make_left_list empty) (\h t f z. t f (f h z)) in
+ ; from Oleg, of course it's the most elegant
+ ; revappend [a;b;c] [x;y] ~~> [c;b;a;x;y]
+ let revappend = \left. left (\hd sofar. \right. sofar (make_list hd right)) I in
+ let rev = \lst. revappend lst empty in
; zip [a;b;c] [x;y;z] ~~> [(a,x);(b,y);(c,z)]
let zip = \left right. (\base build. reverse left build base (\x y. reverse x))
; where base is
; zip [a;b;c] [x;y;z] ~~> [(a,x);(b,y);(c,z)]
let zip = \left right. (\base build. reverse left build base (\x y. reverse x))
; where base is
@@
-237,8
+241,9
@@
and all sorts of other places. Others of them are our own handiwork.
; now you can search for primes, do encryption :-)
; now you can search for primes, do encryption :-)
- let gcd = Y (\gcd m n. iszero n m (gcd n (mod m n))) in
- let lcm = \m n. or (iszero m) (iszero n) 0 (mul (div m (gcd m n)) n) in
+ let gcd = Y (\gcd m n. iszero n m (gcd n (mod m n))) in ; or
+ let gcd = \m n. iszero m n (Y (\gcd m n. iszero n m (lt n m (gcd (sub m n) n) (gcd m (sub n m)))) m n) in
+ let lcm = \m n. or (iszero m) (iszero n) 0 (mul (div m (gcd m n)) n) in
; length for version 1 lists
; length for version 1 lists
@@
-324,5
+329,9
@@
let list_equal =
)
; when fold is finished, check sofar-pair
(\might_be_equal right_tail. and might_be_equal (isempty right_tail))
)
; when fold is finished, check sofar-pair
(\might_be_equal right_tail. and might_be_equal (isempty right_tail))
+
+; most elegant
+let list_equal = \left. left (\hd sofar. \right. and (and (not (isempty right)) (eq hd (head right))) (sofar (tail right))) isempty
+
-->
-->