On Friday 04 July 2008 10:03:19 Joe Groff wrote:

> 20 { [ 1+ ] [ 1- ] [ 2^ ] } cleave

Hi Joe,

In some of my combinators which accept a sequence of quotations, if it finds a 
word instead of a quotation, it is promoted to a quotation. So for example, 
had I written 'cleave' this way, the above would look like this:

        20 { 1+ 1- 2^ } cleave

I haven't been consistent with including this property in 
sequence-of-quotation accepting combinators, mainly because it's an 
experimental idea.

One word which acts like this is '<arr>' in combinators.cleave:

        2 { 1+ 1- 2^ } <arr> .

        { 3 1 4 }

All combinators which accept a sequence of quotations could be endowed with 
this. It's very trivial to support. Here's the implementation of '<arr>' :

        MACRO: <arr> ( seq -- )
          [ >quots ] [ length ] bi
          '[ , cleave , narray ] ;

As you can see, supporting this feature involves a simple preprocessing of the 
sequence, promoting words to 1quotations. Here's >quots:

        : >quot ( obj -- quot ) dup word? [ 1quotation ] when ;

        : >quots ( seq -- seq ) [ >quot ] map ;

Ed

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to