]> gitweb.factorcode.org Git - factor.git/commitdiff
Add columns vocab
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 20 Apr 2008 05:51:10 +0000 (00:51 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 20 Apr 2008 05:51:10 +0000 (00:51 -0500)
extra/columns/authors.txt [new file with mode: 0644]
extra/columns/columns-docs.factor [new file with mode: 0644]
extra/columns/columns-tests.factor [new file with mode: 0644]
extra/columns/columns.factor [new file with mode: 0644]
extra/columns/summary.txt [new file with mode: 0644]
extra/columns/tags.txt [new file with mode: 0644]

diff --git a/extra/columns/authors.txt b/extra/columns/authors.txt
new file mode 100644 (file)
index 0000000..a44f8d7
--- /dev/null
@@ -0,0 +1,2 @@
+Slava Pestov
+Daniel Ehrenberg
diff --git a/extra/columns/columns-docs.factor b/extra/columns/columns-docs.factor
new file mode 100644 (file)
index 0000000..6b2adce
--- /dev/null
@@ -0,0 +1,26 @@
+USING: help.markup help.syntax sequences ;
+IN: columns
+
+ARTICLE: "columns" "Column sequences"
+"A " { $emphasis "column" } " presents a column of a matrix represented as a sequence of rows:"
+{ $subsection column }
+{ $subsection <column> } ;
+
+HELP: column
+{ $class-description "A virtual sequence which presents a fixed column of a matrix represented as a sequence of rows. New instances can be created by calling " { $link <column> } "." } ;
+
+HELP: <column> ( seq n -- column )
+{ $values { "seq" sequence } { "n" "a non-negative integer" } { "column" column } }
+{ $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of" { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." }
+{ $examples
+    { $example
+        "USING: arrays prettyprint sequences ;"
+        "{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } 0 <column> >array ."
+        "{ 1 4 7 }"
+    }
+}
+{ $notes
+    "In the same sense that " { $link <reversed> } " is a virtual variant of " { $link reverse } ", " { $link <column> } " is a virtual variant of " { $snippet "swap [ nth ] curry map" } "."
+} ;
+
+ABOUT: "columns"
diff --git a/extra/columns/columns-tests.factor b/extra/columns/columns-tests.factor
new file mode 100644 (file)
index 0000000..657b9e0
--- /dev/null
@@ -0,0 +1,9 @@
+IN: columns.tests
+USING: columns sequences kernel namespaces arrays tools.test math ;
+
+! Columns
+{ { 1 2 3 } { 4 5 6 } { 7 8 9 } } [ clone ] map "seq" set
+
+[ { 1 4 7 } ] [ "seq" get 0 <column> >array ] unit-test
+[ ] [ "seq" get 1 <column> [ sq ] change-each ] unit-test
+[ { 4 25 64 } ] [ "seq" get 1 <column> >array ] unit-test
diff --git a/extra/columns/columns.factor b/extra/columns/columns.factor
new file mode 100644 (file)
index 0000000..7e4a7fd
--- /dev/null
@@ -0,0 +1,15 @@
+! Copyright (C) 2005, 2008 Slava Pestov, Daniel Ehrenberg.
+! See http://factorcode.org/license.txt for BSD license.
+USING: sequences kernel accessors ;
+IN: columns
+
+! A column of a matrix
+TUPLE: column seq col ;
+
+C: <column> column
+
+M: column virtual-seq seq>> ;
+M: column virtual@ dup col>> -rot seq>> nth bounds-check ;
+M: column length seq>> length ;
+
+INSTANCE: column virtual-sequence
diff --git a/extra/columns/summary.txt b/extra/columns/summary.txt
new file mode 100644 (file)
index 0000000..c4ade7f
--- /dev/null
@@ -0,0 +1 @@
+Virtual sequence view of a matrix column
diff --git a/extra/columns/tags.txt b/extra/columns/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections