Hello,

The short-circuit words were all special cased based on arity. Now they are 
defined in terms of n&&-rewrite and n||-rewrite words. Here's n&&-rewrite:

:: n&&-rewrite ( quots N -- quot )
   quots
     [ '[ drop N ndup @ dup not ] [ drop N ndrop f ] 2array ]
   map
   [ t ] [ N nnip ] 2array suffix
   '[ f , cond ] ;

The variants are now just:

MACRO: 0&& ( quots -- quot ) 0 n&&-rewrite ;
MACRO: 1&& ( quots -- quot ) 1 n&&-rewrite ;
MACRO: 2&& ( quots -- quot ) 2 n&&-rewrite ;

Can 'n&&-rewrite' be improved? Here's a "holy grail" version of 'n&&-rewrite' 
using some non-existent syntax features:

:: n&&-rewrite ( qs N -- quot )
  '[
     f
      {
       @[ qs [| Q | { [ drop N ndup Q@ dup not ] [ drop N ndrop f ] } ] map ]
       { [ t ] [ N nnip ] }
      }
     cond
   ] ;

The features:

        * Locals inside literal arrays
        * @[ ... ] means splice the result of calling the ...
        * There's a local named 'Q' specified in the lambda.
          Q@ means to splice the value.

At this point I'd like to send a little shout-out to Chris Double. When he 
introduced the n* general arity shuffle words, their value was questioned. It 
was said that if you need them, you should refactor your code. Well 
eventually macros came along and the code that writes code renaissance began. 
It turns out that for general macros like n&&-rewrite, the n* macros are 
essential. I'm very glad we have them.

Ed

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to