Hello,
I'm experimenting with the '@[' directive for bake.
Here's an example of it:
1 2 3 `{ , @[ [ 10 + ] map ] @[ [ 20 + ] map ] }
=>
{ 1 10 11 20 21 22 }
An instance of the @[ ... ] causes the ... to be called on the corresponding
stack element. The result should be a sequence which is then spliced into the
sequence being baked.
Here are words from the 'generalizations' vocabulary along with versions
written in terms of the '@[' directive.
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MACRO: npick ( n -- )
1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;
MACRO: npick ( n -- )
1- dup `[ @[ saver ] dup @[ [ r> swap ] n*quot ] ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MACRO: nrot ( n -- )
1- dup saver swap [ r> swap ] n*quot append ;
MACRO: nrot ( n -- )
1- dup `[ @[ saver ] @[ [ r> swap ] n*quot ] ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MACRO: -nrot ( n -- )
1- dup [ swap >r ] n*quot swap restorer append ;
MACRO: -nrot ( n -- )
1- dup `[ @[ [ swap >r ] n*quot ] @[ restorer ] ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MACRO: ndip ( quot n -- )
dup saver -rot restorer 3append ;
MACRO: ndip ( quot n -- )
tuck `[ @[ saver ] @ @[ restorer ] ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MACRO: nslip ( n -- )
dup saver [ call ] rot restorer 3append ;
MACRO: nslip ( n -- )
dup `[ @[ saver ] [ call ] @[ restorer ] ] ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Sadly, these cannot actually use bake because it would cause a circular
dependency; the current bake implementation uses these words. 8-) But they're
some good examples.
The @[ directive is pretty esoteric. I have a working version but it's not
checked in yet. If we find some motivating uses, it can go in.
By the way, there's also a ,[ directive which is similar but the result is
inserted instead of spliced.
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