Hi all,

Here is some code from cpu.8080.emulator:

SYMBOL: $1
SYMBOL: $2
SYMBOL: $3
SYMBOL: $4

: replace-patterns ( vector tree -- tree )
   #! Copy the tree, replacing each occurence of
   #! $1, $2, etc with the relevant item from the
   #! given index.
   dup quotation? over [ ] = not and [ ! vector tree
     dup first swap rest ! vector car cdr
     >r dupd replace-patterns ! vector v R: cdr
     swap r> replace-patterns >r 1quotation r> append
   ] [ ! vector value
     dup $1 = [ drop 0 over nth  ] when
     dup $2 = [ drop 1 over nth  ] when
     dup $3 = [ drop 2 over nth  ] when
     dup $4 = [ drop 3 over nth  ] when
     nip
   ] if ;

This code was written a while ago, before we had some of the  
abstractions we do now.

Here is a new version:

SYMBOLS: $1 $2 $3 $4 ;

: replace-patterns ( vector tree -- tree )
   [
     {
       { $1 [ first ] }
       { $2 [ second ] }
       { $3 [ third ] }
       { $4 [ fourth ] }
       [ nip ]
     } case
   ] with deep-map ;

Slava

-------------------------------------------------------------------------
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