We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Crazy J/Reverse input
Jump to navigation
Jump to search
Crazy J examples
Reverse input
One more exercise before serious work.
init_list = λ v g f . f v g = V
push_front = λ v l g f . f v (l g) = D V
reverse = λ1 input . input (Y (λ2 self l g ch tail . ch T (λ3 g1 g2 . tail (self (push_front ch l) (g2 g1)))
(256 T (Q1 l)) g)
(init_list EOF)
I
)
init_list and push_front primitives are designed not only to provide an access to stored items but also to pass garbage through and put it finally after the last element (the one put first).
Lambdas are marked with indices to reference them from the following explanation text:
- λ3 packs lumps of garbage and makes recursive call of λ2 by passing
selfas a parameter totail. - λ2 is called to handle each character of input. First parameter (
self) is provided byY,l(currently accumulated reversed list) andg(garbage) - by λ3 (recursive call) or by λ1 (topmost call),chandtail- by input list element. - λ1 is an entry point which provides initial values for accumulated list and garbage.
Compiled program:
```jii````````j``j`j`j```j``j`jiii``jiii``jiiji`````j`j`j`j``jiii``jiji``j`jii`````j``jii``ji``jii`j`j``jii````j``ji``j`j``jiii`j``jii`jij```j``jii``````j`j``jii``ji``jii``ji`j`j``jii````j```jii````j```jii```j``ji``j``jiii``jii``jijii``jiiii``jii``jii`ji````j`j``jii``ji``jii``ji`j`j``jii`````j``jii``ji``jii`j`j``jii```j``jii`j``jii`j``jii`````j``jii``ji``jii`j`j``jii``````j```jj``j```jiiii`j``jiiiij```j``jii`j`j``jii`j``jii`````j```jj``j```jiiii`j``jiiiij```j``jii`j`j``jii`j``jii````j``jii`j`j``jii`j``jii`````j``ji``j`j``jiii`j``jii`jij`````j``jii`j``jii`j``jii`````j``jii``ji``jii`j`j``jii````j```jj``j```jiiii`j``jiiiij```ji````j```jj``j```jiiii`j``jiiiij``jii``````j```jj``j```jiiii`j``jiiiij````j``jii`j`j``jii`j``jii`````j``jii``ji``jii`j`j``jii`````j```jj``j```jiiii`j``jiiiij`ji````j```jj``j```jiiii`j``jiiiij````j`j``jii``ji``jii``ji`j`j``jii```j``j```jii`j`j``jii``jiiij````j``j```jii`j`j``jii``jiiij`````j``ji``j`j``jiii`j``jii`jij````j`j``jii``ji``jii``ji`j`j``jii````j```jii````j```jii```j``ji``j``jiii``jii``jijii``jiiii``jiii