literals: Improve ${ word
parent
764ee52cde
commit
8133436d6d
|
@ -20,8 +20,10 @@ IN: literals.tests
|
||||||
|
|
||||||
[ { 1.0 { 0.5 1.5 } 4.0 } ] [ { 1.0 { $[ 1.0 2.0 / ] 1.5 } $[ 2.0 2.0 * ] } ] unit-test
|
[ { 1.0 { 0.5 1.5 } 4.0 } ] [ { 1.0 { $[ 1.0 2.0 / ] 1.5 } $[ 2.0 2.0 * ] } ] unit-test
|
||||||
|
|
||||||
<<
|
|
||||||
CONSTANT: constant-a 3
|
CONSTANT: constant-a 3
|
||||||
>>
|
|
||||||
|
|
||||||
[ { 3 10 "ftw" } ] [ ${ constant-a 10 "ftw" } ] unit-test
|
[ { 3 10 "ftw" } ] [ ${ constant-a 10 "ftw" } ] unit-test
|
||||||
|
|
||||||
|
: sixty-nine ( -- a b ) 6 9 ;
|
||||||
|
|
||||||
|
[ { 6 9 } ] [ ${ sixty-nine } ] unit-test
|
||||||
|
|
|
@ -1,8 +1,21 @@
|
||||||
! (c) Joe Groff, see license for details
|
! (c) Joe Groff, see license for details
|
||||||
USING: accessors continuations kernel parser words quotations
|
USING: accessors continuations kernel parser words quotations
|
||||||
combinators.smart vectors sequences ;
|
combinators.smart vectors sequences fry ;
|
||||||
IN: literals
|
IN: literals
|
||||||
|
|
||||||
SYNTAX: $ scan-word [ def>> call ] curry with-datastack >vector ;
|
<PRIVATE
|
||||||
|
|
||||||
|
! Use def>> call so that CONSTANT:s defined in the same file can
|
||||||
|
! be called
|
||||||
|
|
||||||
|
: expand-literal ( seq obj -- seq' )
|
||||||
|
'[ _ dup word? [ def>> call ] when ] with-datastack ;
|
||||||
|
|
||||||
|
: expand-literals ( seq -- seq' )
|
||||||
|
[ [ { } ] dip expand-literal ] map concat ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
SYNTAX: $ scan-word expand-literal >vector ;
|
||||||
SYNTAX: $[ parse-quotation with-datastack >vector ;
|
SYNTAX: $[ parse-quotation with-datastack >vector ;
|
||||||
SYNTAX: ${ \ } [ [ ?execute ] { } map-as ] parse-literal ;
|
SYNTAX: ${ \ } [ expand-literals ] parse-literal ;
|
||||||
|
|
Loading…
Reference in New Issue