From 9bc8aa2473929c68c84b57e544a881f343feade5 Mon Sep 17 00:00:00 2001 From: Jim Pryor Date: Thu, 7 Oct 2010 11:02:38 -0400 Subject: [PATCH] library tweaks Signed-off-by: Jim Pryor --- lambda_library.mdwn | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) 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 -- 2.11.0