Re: [stack] adding construction to factor
"Christopher Diggins" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Jan 4, 2009 at 10:40 AM, John Nowak <[email protected]> wrote: > 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 This looks like line noise to me. Either I'm dense, or the code could benefit from some comments. - Christopher