On 1/12/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote:
> So let's get on with the use and abuse of Factor. :-D

I played around with some similar ideas, but using pattern matching a
couple of weeks ago. So words looked like:

FOO: recurse ( h:t quot -- )
  ?h:t empty? [
    ?quot call bind ?t ?quot recurse
  ] unless ;

FOO: my-subset3 ( seq quot result -- seq )
  ?seq [
    ?h ?quot call [ ?h ?result push ] when
  ] recurse  ?result ?seq like ;

FOO: would look at the stack effect of the word and perform a pattern
match on the input stack against that stack effect. I also added list
head/tail matching to the pattern matching library for this. So ?a:b
would make ?a equal the head of the list and ?b the tail, and ?a:b the
entire list.

FOO: translated this:

FOO: bar ( a b -- )
  ?a ?b + ;

To:

: bar ( a b -- )
  2array { ?a ?b } match [ ?a ?b + ] bind ;

I was exploring ideas on how to write combinator words at the time. I
also hit the tail recursion problem. That problem being that calling
itself from within a  'bind' is not tail recursive since 'bind'
modifies the name stack after the call.

Chris.
-- 
http://www.bluishcoder.co.nz

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to