Hi Tim, Writing Joy primitives in the Factor-but-where-the-data-stack-is-a-single-list-on-the-stack programming language is probably not much fun, especially for something complicated like 'map'. Instead, try implementing 'map' in terms of other Joy combinators. Because everything is built up from lists in Joy, all combinators can be boiled down to the basic recursive combinators such as primrec and linrec and so on. These can then be implemented in terms of 'i' and such, if your implementation allows named recursion.
Eg, you can express map as a fold followed by a list reversal. The quotation you pass to the fold conses the result of the map onto the accumulator, which is initially nil. Since my Joy is rusty I'll just write it in Factor: [ nil ] dip [ curry dip cons ] curry foldl The idea here is that given an operation such as [ 1 + ], [ curry dip cons ] curry evaluates to [ [ 1 + ] curry dip cons ] Which has stack effect ( accum element -- new-accum ); the quotation [ 1 + ] is applied to the element and the result is consed on. A fold can itself be expressed in terms of a lower-level recursive combinator, and so on. So try to write as much as possible in Joy itself, and have your interpreter load a little 'prelude' file on startup, then the remaining parts will be easy to add as primitives. Slava On Thu, Sep 3, 2009 at 11:19 PM, Tim Wawrzynczak<[email protected]> wrote: > Hi list, > > Hoping someone can help me here, I'm having a little trouble with > implementing some combinators. > > For instance, I'm just trying to implement 'map' first b/c it's fairly > simple. The datastack is implemented > as a linked list, and quotations are implemented as a custom cons tuple > (TUPLE: joy-cons { car read-only } { cdr read-only } compiled-quot ;). > As an example, let's use [1 2 3] [1 +] map . > [1 2 3] is a linked list (cons tuple) like the Lisp (1 ( 2 ( 3 . nil ) ) ). > The quotation [1 +] is a joy-cons linked list that gets jit-compiled to [ 1 > dstack-push +-joy ], which will push 1 onto the Joy datastack, > and then take two items off, add them, and push the result back onto the Joy > datastack. > > So I have been unable so far to come up with a good solution for > implementing a way for the 'map' combinator to apply the quotation > to each element of the list and collect the results (obviously what 'map' > does). Any help is appreciated ! > > The (currently kind of working and kind of broken) code is at: > [email protected]:inforichland/Joy.git > > Cheers, > - Tim > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus > on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Factor-talk mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/factor-talk > > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Factor-talk mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/factor-talk
