19 if !(isFunction a) && stack == [ ] then
21 else if isFunction a then
22 b: binding'' ([ a ] ++ stack) b
23 else # length stack >= 1
28 binding'' rest (top a);
31 if !(isFunction a) then
32 b: passing'' ([ a ] ++ stack) b
33 else if length stack < 1 then
40 passing'' rest (a top);
45 # binding: just like function call, if arg is a function, push to stack
46 # if not, applying stack top to it, and repeat.
47 # binding K (map f) a {} == map f a
48 # binding K (map f) (filter g) a {} == map f (filter g a)
49 binding = binding'' [ ];
51 # passing: just like binding, but with reversed order
52 # passing a (map f) K {} == map f a
53 # passing a (filter g) (map f) K {} == map f (filter g a)
54 passing = passing'' [ ];
57 # mapping = nArg 2 [1 2 3] map
58 # mapping (x: x + 1) == [2 3 4]
60 if n < 1 || !(isFunction f) then f
61 else if n == 1 then f x
62 else a: nArg (n - 1) x (f a);
69 # rapply: list -> iv -> a
70 # rapply [a b c d] iv == a (b (c (d iv)))
71 # If a b c d, any of them are not function, the applying will return itself.
72 # E.g. a is not function, (a b) == a
74 foldr' (a: b: if isFunction a then a b else a) ls iv;
76 # lapply: iv -> list -> a
77 # lapply iv [a b c d] == iv a b c d
80 foldl' (a: b: if isFunction a then a b else a) iv ls;