[stack] Re: Programming Puzzle
"Ivan Tomac" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], "Christopher Diggins" <cdiggins@...> wrote: > Define a while loop that takes a loop body and termination predicate > in Joy using only the following combinators: > > "ifte","cat","swap","dup","pop","i","dip" and "unit" > LIBRA (* Joy doesn't appear to have unit and cat combinators - unit == [] cons ? *) unit == [] cons ; cat == concat ; (* first thing's first - define cons *) cons == [unit] dip cat ; make-recursive == [dip dup i] cons ; fix-predicate == [dip swap ] cons ; construct-loop == [[pop] ifte] cons cons ; recurse == dup i ; while == [fix-predicate] dip make-recursive construct-loop recurse . 10 [0 >] [dup put 1 -] while . > Cheers, > Christopher > Ivan [Non-text portions of this message have been removed]