Hello,

In combinators.lib, we have &&, ||, and some arity variants. However, they 
only return 't' or 'f'. We're interested in versions which return non-f 
results. In the case of '||' it would return the first non-f result. In the 
case of '&&' it would return the last result if all the results were non-f.

If you perform a manual expansion of expressions which you'd pass to && 
and ||, a pattern arises. I think this macro captures the 0 arity case:

: 0||-rewrite ( quots -- quot )
  dup empty?
    [ drop [ ] ]
    [ unclip swap 0||-rewrite '[ drop @ dup [ ] [ @ ] if ] ]
  if ;

MACRO: 0|| ( quots -- quot ) 0||-rewrite f prefix ;

        This is 1 arity case:

: 1||-rewrite ( quots -- quot )
  dup empty?
    [ drop [ nip ] ]
    [ unclip swap 1||-rewrite '[ drop dup @ dup [ nip ] [ @ ] if ] ]
  if ;

MACRO: 1|| ( quots -- quot ) 1||-rewrite f prefix ;

        And finally the 2 arity case:

: 2||-rewrite ( quots -- quot )
  dup empty?
    [ drop [ 2nip ] ]
    [ unclip swap 2||-rewrite '[ drop 2dup @ dup [ 2nip ] [ @ ] if ] ]
  if ;

MACRO: 2|| ( quots -- quot ) 2||-rewrite f prefix ;

Fry really helped here. I'm the syntax rebel/separatist around here. I'd been 
experimenting with a syntax I call "auto fry" whereby you don't have to 
single-quot a quotation in order to fry it. If a quotation contains fry 
directives, it's fried. I really like this but this in this application it 
didn't work. I was using auto-fry instead of the explicit fry above. The 
probem is, the quotation I intend to fry is actually in another quotation. 
The inner directives cause the outer quotation to fry; not the desired 
result...

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