On 7-Sep-07, at 3:37 PM, William Tanksley, Jr wrote:

> I've seen one attempt to implement this in Factor; the implementor
> wrote a defining word that, given an integer 'depth', generated all
> words that permuted the stack to the given depth. (That's a LOT of
> words to define!) As impressive of a feat as that was... I hope it's
> possible to do something less resource-intensive :-).
>
> Does Factor have reader-macros (to use the Lisp term)? Is there some
> other way of getting this kind of thing done?

It can be done using local variables.

USE: locals

:: abc--cab | a b c | c a b ;

abc--cab

However, here you have to explicitly define your shuffle first.

To do this 'inline', you can still use locals, but with a lambda:

[| a b | b a ] with-locals call

However this is too verbose.

We can write a parsing word to abstract it out:

: S[ POSTPONE: [| \ with-locals \ call parsed ; parsing

Now you can write

17 S[ a | a a ] * .

Instead of

17 dup * .

etc.

I prefer traditional Forth shuffle words though. I find them easier  
to read and write than the 'pictorial' mnemonics. There are only a  
few shuffle words and they're easy to remember after a few weeks of  
writing code.

Slava

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to