:> ( a b c ) syntax to bind multiple variables left-to-right off the stack

db4
Joe Groff 2009-10-28 15:40:07 -05:00
parent b0362f8011
commit d284d963fa
6 changed files with 21 additions and 1 deletions

View File

@ -488,3 +488,6 @@ M: integer ed's-bug neg ;
{ [ a ed's-bug ] } && ;
[ t ] [ \ ed's-test-case optimized? ] unit-test
! multiple bind
[ 3 1 2 ] [ [let 1 2 3 :> ( a b c ) c a b ] ] unit-test

View File

@ -7,7 +7,7 @@ IN: locals
SYNTAX: :>
scan locals get [ :>-outside-lambda-error ] unless*
[ make-local ] bind <def> parsed ;
parse-def parsed ;
SYNTAX: [| parse-lambda over push-all ;

View File

@ -46,6 +46,12 @@ SYMBOL: locals
(parse-lambda) <lambda>
?rewrite-closures ;
: parse-multi-def ( locals -- multi-def )
")" parse-tokens swap [ [ make-local ] map ] bind <multi-def> ;
: parse-def ( name/paren locals -- def )
over "(" = [ nip parse-multi-def ] [ [ make-local ] bind <def> ] if ;
M: lambda-parser parse-quotation ( -- quotation )
H{ } clone (parse-lambda) ;

View File

@ -36,3 +36,8 @@ M: def pprint*
dup local>> word?
[ <block \ :> pprint-word local>> pprint-var block> ]
[ pprint-tuple ] if ;
M: multi-def pprint*
dup locals>> [ word? ] all?
[ <block \ :> pprint-word "(" text locals>> [ pprint-var ] each ")" text block> ]
[ pprint-tuple ] if ;

View File

@ -104,6 +104,8 @@ M: tuple rewrite-sugar* rewrite-element ;
M: def rewrite-sugar* , ;
M: multi-def rewrite-sugar* locals>> <reversed> [ <def> , ] each ;
M: hashtable rewrite-sugar* rewrite-element ;
M: wrapper rewrite-sugar*

View File

@ -22,6 +22,10 @@ TUPLE: def local ;
C: <def> def
TUPLE: multi-def locals ;
C: <multi-def> multi-def
PREDICATE: local < word "local?" word-prop ;
: <local> ( name -- word )