]> gitweb.factorcode.org Git - factor.git/commitdiff
Add a slots{ word for accessing multiple slots
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 27 Feb 2010 11:01:14 +0000 (05:01 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Sat, 27 Feb 2010 13:58:40 +0000 (07:58 -0600)
extra/slots/syntax/authors.txt [new file with mode: 0755]
extra/slots/syntax/syntax-docs.factor [new file with mode: 0755]
extra/slots/syntax/syntax-tests.factor [new file with mode: 0755]
extra/slots/syntax/syntax.factor [new file with mode: 0755]

diff --git a/extra/slots/syntax/authors.txt b/extra/slots/syntax/authors.txt
new file mode 100755 (executable)
index 0000000..7c1b2f2
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
diff --git a/extra/slots/syntax/syntax-docs.factor b/extra/slots/syntax/syntax-docs.factor
new file mode 100755 (executable)
index 0000000..b79916f
--- /dev/null
@@ -0,0 +1,20 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: help.markup help.syntax ;
+IN: slots.syntax
+
+HELP: slots{
+{ $description "Outputs an array of slot values from a tuple." }
+{ $example "USING: prettyprint slots.syntax ;"
+           "IN: slots.syntax.example"
+           "TUPLE: rectangle width height ;"
+           "T{ rectangle { width 3 } { height 5 } } slots{ width height } ."
+           "{ 3 5 }"
+} ;
+
+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 an array:"
+{ $subsections POSTPONE: slots{ } ;
+
+ABOUT: "slots.syntax"
diff --git a/extra/slots/syntax/syntax-tests.factor b/extra/slots/syntax/syntax-tests.factor
new file mode 100755 (executable)
index 0000000..689ccb4
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test slots.syntax ;
+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
\ No newline at end of file
diff --git a/extra/slots/syntax/syntax.factor b/extra/slots/syntax/syntax.factor
new file mode 100755 (executable)
index 0000000..2cce91c
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2010 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: combinators combinators.smart fry lexer quotations
+sequences slots  ;
+IN: slots.syntax
+
+SYNTAX: slots{
+    "}" parse-tokens
+    [ reader-word 1quotation ] map
+    '[ [ _ cleave ] output>array ] append! ;
\ No newline at end of file