diff --git a/extra/slots/syntax/syntax-docs.factor b/extra/slots/syntax/syntax-docs.factor index b79916f91b..84e6e89dac 100755 --- a/extra/slots/syntax/syntax-docs.factor +++ b/extra/slots/syntax/syntax-docs.factor @@ -3,6 +3,16 @@ USING: help.markup help.syntax ; IN: slots.syntax +HELP: slots[ +{ $description "Outputs several slot values to the stack." } +{ $example "USING: kernel prettyprint slots.syntax ;" + "IN: slots.syntax.example" + "TUPLE: rectangle width height ;" + "T{ rectangle { width 3 } { height 5 } } slots[ width height ] [ . ] bi@" + """3 +5""" +} ; + HELP: slots{ { $description "Outputs an array of slot values from a tuple." } { $example "USING: prettyprint slots.syntax ;" @@ -14,6 +24,8 @@ HELP: slots{ ARTICLE: "slots.syntax" "Slots syntax sugar" "The " { $vocab-link "slots.syntax" } " vocabulary provides an alternative syntax for taking a sequence of slots from a tuple." $nl +"Syntax sugar for cleaving slots to the stack:" +{ $subsections POSTPONE: slots[ } "Syntax sugar for cleaving slots to an array:" { $subsections POSTPONE: slots{ } ; diff --git a/extra/slots/syntax/syntax-tests.factor b/extra/slots/syntax/syntax-tests.factor index 689ccb48eb..e4dac6e4a4 100755 --- a/extra/slots/syntax/syntax-tests.factor +++ b/extra/slots/syntax/syntax-tests.factor @@ -5,6 +5,10 @@ IN: slots.syntax.tests TUPLE: slot-test a b c ; +[ 1 2 3 ] [ T{ slot-test f 1 2 3 } slots[ a b c ] ] unit-test +[ 3 ] [ T{ slot-test f 1 2 3 } slots[ c ] ] unit-test +[ ] [ T{ slot-test f 1 2 3 } slots[ ] ] unit-test + [ { 1 2 3 } ] [ T{ slot-test f 1 2 3 } slots{ a b c } ] unit-test [ { 3 } ] [ T{ slot-test f 1 2 3 } slots{ c } ] unit-test -[ { } ] [ T{ slot-test f 1 2 3 } slots{ } ] unit-test \ No newline at end of file +[ { } ] [ T{ slot-test f 1 2 3 } slots{ } ] unit-test diff --git a/extra/slots/syntax/syntax.factor b/extra/slots/syntax/syntax.factor index 95207a0de9..7bfe238fa8 100755 --- a/extra/slots/syntax/syntax.factor +++ b/extra/slots/syntax/syntax.factor @@ -4,6 +4,10 @@ USING: combinators combinators.smart fry lexer quotations sequences slots ; IN: slots.syntax +SYNTAX: slots[ + "]" [ reader-word 1quotation ] map-tokens + '[ _ cleave ] append! ; + SYNTAX: slots{ "}" [ reader-word 1quotation ] map-tokens '[ [ _ cleave ] output>array ] append! ;