]> gitweb.factorcode.org Git - factor.git/commitdiff
Add a parsing word to output slots to the stack instead of to an array
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 2 Mar 2010 10:51:52 +0000 (04:51 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 2 Mar 2010 10:51:52 +0000 (04:51 -0600)
extra/slots/syntax/syntax-docs.factor
extra/slots/syntax/syntax-tests.factor
extra/slots/syntax/syntax.factor

index b79916f91b225d74e5f59431adac81b0f9d81055..84e6e89dacc670069fe1efa970c0c15f5aaa76d0 100755 (executable)
@@ -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{ } ;
 
index 689ccb48eba7c7c1b7f3eb8b2428a936fcd5c294..e4dac6e4a4927425f0483714842352d8f1c81cd9 100755 (executable)
@@ -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
index 95207a0de94fb713594c1a751e0c58cc2aa527e7..7bfe238fa83515dbbc0a1ef263dfa48088abad82 100755 (executable)
@@ -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! ;