diff --git a/extra/columns/authors.txt b/extra/columns/authors.txt new file mode 100644 index 0000000000..a44f8d7f8d --- /dev/null +++ b/extra/columns/authors.txt @@ -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 index 0000000000..6b2adce9d9 --- /dev/null +++ b/extra/columns/columns-docs.factor @@ -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 } ; + +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 } "." } ; + +HELP: ( 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 >array ." + "{ 1 4 7 }" + } +} +{ $notes + "In the same sense that " { $link } " is a virtual variant of " { $link reverse } ", " { $link } " 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 index 0000000000..657b9e0a25 --- /dev/null +++ b/extra/columns/columns-tests.factor @@ -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 >array ] unit-test +[ ] [ "seq" get 1 [ sq ] change-each ] unit-test +[ { 4 25 64 } ] [ "seq" get 1 >array ] unit-test diff --git a/extra/columns/columns.factor b/extra/columns/columns.factor new file mode 100644 index 0000000000..7e4a7fd408 --- /dev/null +++ b/extra/columns/columns.factor @@ -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 + +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 index 0000000000..c4ade7fb51 --- /dev/null +++ b/extra/columns/summary.txt @@ -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 index 0000000000..42d711b32b --- /dev/null +++ b/extra/columns/tags.txt @@ -0,0 +1 @@ +collections