[stack] adding construction to factor

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
I managed to add something like FP's construction form to Factor. It  
treats stacks as if they were vectors in More's array theory, e.g. '5  
== {5}'. I mentioned wanting to do this a few days ago, so I thought  
I'd share. Maybe it's useful.

Here are a few of examples:

    5 [( sq , dup , neg , drop ])  ==  25 { 5 5 } -5 { }
    5 3 2@ [( + , - )]  ==  8 2
    5 [( 5 + , 5 - )]  ==  10 0

And here's the implementation:

: 2@ 2array ;
: 3@ 3array ;
: 4@ 4array ;
: lift dup array? [ 1array ] unless ;
: lower dup length 1 = [ 0 swap nth ] when ;
: construct
   [ lift ] dip
   [ over [ with-datastack ] dip swap lower ] map
   nip [ ] each
;
: )] ;
: [( \ )]
   [ \ , 1array split [ >quotation ] map ] parse-literal
   \ construct suffix
; parsing

- John
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.