X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=lambda_library.mdwn;h=e170dcf424d4b775d16faf24657e32d37502a6be;hp=9f08d9f1ecb543f11dba0d4a3448e17b5272ce15;hb=08da0e1fce6f207a276cd6d646b8741ae97a3019;hpb=6286790a41cbbac6317e34b9f3bb8a5e78070c03 diff --git a/lambda_library.mdwn b/lambda_library.mdwn index 9f08d9f1..e170dcf4 100644 --- a/lambda_library.mdwn +++ b/lambda_library.mdwn @@ -198,15 +198,15 @@ and all sorts of other places. Others of them are our own handiwork. let length = Y (\length lst. isempty lst 0 (succ (length (tail lst)))) in let fold = Y (\fold lst f z. isempty lst z (f (head lst) (fold (tail lst) f z))) in - let map = Y (\map lst f. isempty lst empty (make_list (f (head lst)) (map (tail lst) f))) in - let filter = Y (\filter lst f. isempty lst empty (f (head lst) (make_list (head lst)) I (filter (tail lst) f))) in + let map = \f. Y (\map lst. isempty lst empty (make_list (f (head lst)) (map (tail lst)))) in + let filter = \f. Y (\filter lst. isempty lst empty (f (head lst) (make_list (head lst)) I (filter (tail lst)))) in ;; version 3 (right-fold) lists let empty = \f z. z in let make_list = \h t f z. f h (t f z) in let isempty = \lst. lst (\h sofar. false) true in - let head = \lst. lst (\h sofar. h) junk in + let head = \lst. lst (\h sofar. h) err in let tail_empty = empty in let tail = \lst. (\shift. lst shift (make_pair empty tail_empty) get_snd) ; where shift is @@ -229,21 +229,21 @@ and all sorts of other places. Others of them are our own handiwork. 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 - (make_pair empty (map (\h u. u h) right)) - ; and build is - (\h sofar. sofar (\x y. isempty y - sofar - (make_pair (make_list (\u. head y (u h)) x) (tail y)) - )) in + ; where base is + (make_pair empty (map (\h u. u h) right)) + ; and build is + (\h sofar. sofar (\x y. isempty y + sofar + (make_pair (make_list (\u. head y (u h)) x) (tail y)) + )) in let all = \f lst. lst (\h sofar. and sofar (f h)) true in let any = \f lst. lst (\h sofar. or sofar (f h)) false in ;; left-fold lists let make_list = \h t f z. t f (f h z) in - let head = \lst. lst (\h sofar. (K (sofar (K h))) ) (\k. k junk) I in - let tail = \lst. (\shift. lst shift (\a b. a junk) I I) + let head = \lst. lst (\h sofar. (K (sofar (K h))) ) (\k. k err) I in + let tail = \lst. (\shift. lst shift (\a b. a tail_empty) I I) (\h p. p (\j a b. b empty) (\t a b. b (\f z. f h (t f z))) ) in @@ -268,9 +268,10 @@ and all sorts of other places. Others of them are our own handiwork. ; here's our f2 (\hd sofar continue_handler abort_handler. continue_handler hd) ; here's our z - junk + err ; here are our continue_handler and abort_handler larger_computation unused in + let tail_empty = empty in let tail = \lst larger_computation. lst ; here's our f2 (\h sofar continue_handler abort_handler. continue_handler (sofar (\t y. make_pair (make_list h t) t))) @@ -279,7 +280,6 @@ and all sorts of other places. Others of them are our own handiwork. ; here are our continue_handler and abort_handler (\sofar. sofar (\x y. larger_computation y)) unused in - ;; CPS left-fold lists ; [] is \f z c a. c z ; [1] is \f z c a. f 1 z (\z. c z) a @@ -287,19 +287,19 @@ and all sorts of other places. Others of them are our own handiwork. ; [1;2;3] is \f z c a. f 1 z (\z. f 2 z (\z. f 3 z (\z. c z) a) a) a let make_right_list = make_list in let make_list = \h t. \f2 z continue_handler abort_handler. - f2 h z (\z. t f2 z continue_handler abort_handler) abort_handler in + f2 h z (\z. t f2 z continue_handler abort_handler) abort_handler in let head = \lst larger_computation. lst ; here's our f2 - (\hd sofar continue_handler abort_handler. abort_handler hd) + (\hd sofar continue_handler abort_handler. abort_handler hd) ; here's our z - junk + err ; here are our continue_handler and abort_handler larger_computation larger_computation in let tail = \lst larger_computation. lst ; here's our f2 (\h sofar continue_handler abort_handler. continue_handler (sofar (\j a b. b empty) (\t a b. b (make_right_list h t)) ) ) ; here's our z - (\a b. a junk) + (\a b. a tail_empty) ; here are our continue_handler and abort_handler (\sofar. sofar larger_computation larger_computation) unused in