Paste: funny combinators
Author: | slava |
Mode: | factor |
Date: | Tue, 9 Dec 2008 10:07:14 |
Plain Text |
: arity infer [ in>> length ] [ out>> length ] bi - 1+ ;
MACRO: ncleave
[ '[ _ '[ _ _ nkeep ] ] map [ ] join ] [ '[ _ ndrop ] ] bi append ;
MACRO: smart-cleave
dup 0 [ arity max ] reduce
[ '[ [ [ _ ] [ arity ] bi* - ] keep '[ _ ndrop @ ] ] map ] keep '[ _ _ ncleave ] ;
SYMBOL: ,
SYMBOL: ]] delimiter
: [[ \ ]] parse-until { , } split [ >quotation ] map parsed \ smart-cleave parsed ; parsing
: id ;
MACRO: select
[ swap - 1+ ] keep
[ '[ _ nrot ] ] [ 1- '[ [ _ ndrop ] dip ] ] bi* append ;
: @ scan-word parsed \ select parsed ; parsing
SYMBOL: ) delimiter
: ( \ ) parse-until unclip [ >quotation parsed ] [ parsed ] bi* ; parsing
New Annotation