]> gitweb.factorcode.org Git - factor.git/commitdiff
extra: moving named-tuples to basis.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 18 Mar 2021 18:03:21 +0000 (11:03 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 18 Mar 2021 18:03:21 +0000 (11:03 -0700)
12 files changed:
basis/named-tuples/authors.txt [new file with mode: 0644]
basis/named-tuples/named-tuples-docs.factor [new file with mode: 0644]
basis/named-tuples/named-tuples-tests.factor [new file with mode: 0644]
basis/named-tuples/named-tuples.factor [new file with mode: 0644]
basis/named-tuples/summary.txt [new file with mode: 0644]
basis/named-tuples/tags.txt [new file with mode: 0644]
extra/named-tuples/authors.txt [deleted file]
extra/named-tuples/named-tuples-docs.factor [deleted file]
extra/named-tuples/named-tuples-tests.factor [deleted file]
extra/named-tuples/named-tuples.factor [deleted file]
extra/named-tuples/summary.txt [deleted file]
extra/named-tuples/tags.txt [deleted file]

diff --git a/basis/named-tuples/authors.txt b/basis/named-tuples/authors.txt
new file mode 100644 (file)
index 0000000..e091bb8
--- /dev/null
@@ -0,0 +1 @@
+John Benediktsson
diff --git a/basis/named-tuples/named-tuples-docs.factor b/basis/named-tuples/named-tuples-docs.factor
new file mode 100644 (file)
index 0000000..c61fd43
--- /dev/null
@@ -0,0 +1,5 @@
+USING: assocs classes.mixin help.markup help.syntax named-tuples
+sequences ;
+
+HELP: named-tuple
+{ $class-description "A " { $link mixin-class } " that allows you to treat a tuple as both a " { $link sequence } " and an " { $link assoc } "." } ;
diff --git a/basis/named-tuples/named-tuples-tests.factor b/basis/named-tuples/named-tuples-tests.factor
new file mode 100644 (file)
index 0000000..ea55cca
--- /dev/null
@@ -0,0 +1,40 @@
+USING: arrays assocs classes.tuple kernel math named-tuples
+sequences tools.test ;
+IN: named-tuples.tests
+
+TUPLE: foo x y z ;
+
+INSTANCE: foo named-tuple
+
+{ { f f f } } [ T{ foo } >array ] unit-test
+{ { 1 f f } } [ T{ foo f 1 } >array ] unit-test
+{ { 1 2 f } } [ T{ foo f 1 2 } >array ] unit-test
+{ { 1 2 3 } } [ T{ foo f 1 2 3 } >array ] unit-test
+
+{ T{ foo } } [ { } T{ foo } like ] unit-test
+{ T{ foo f 1 } } [ { 1 } T{ foo } like ] unit-test
+{ T{ foo f 1 2 } } [ { 1 2 } T{ foo } like ] unit-test
+{ T{ foo f 1 2 3 } } [ { 1 2 3 } T{ foo } like ] unit-test
+
+{ { { "x" f } { "y" f } { "z" f } } } [ T{ foo } >alist ] unit-test
+{ { { "x" 1 } { "y" f } { "z" f } } } [ T{ foo f 1 } >alist ] unit-test
+{ { { "x" 1 } { "y" 2 } { "z" f } } } [ T{ foo f 1 2 } >alist ] unit-test
+{ { { "x" 1 } { "y" 2 } { "z" 3 } } } [ T{ foo f 1 2 3 } >alist ] unit-test
+
+{ f } [ T{ foo } "x" of ] unit-test
+{ f } [ T{ foo } "y" of ] unit-test
+{ f } [ T{ foo } "z" of ] unit-test
+
+{ f f } [ "not found" T{ foo f 1 2 3 } at* ] unit-test
+
+{ T{ foo f "x" 2 3 } } [ T{ foo f 1 2 3 } "x" dup pick set-at ] unit-test
+
+[ 1 "not found" T{ foo f 1 2 3 } set-at ] [ no-slot? ] must-fail-with
+
+{ 1 } [ T{ foo f 1 2 3 } "x" of ] unit-test
+{ 2 } [ T{ foo f 1 2 3 } "y" of ] unit-test
+{ 3 } [ T{ foo f 1 2 3 } "z" of ] unit-test
+
+{ 1 } [ 0 >bignum T{ foo f 1 2 3 } nth ] unit-test
+{ 2 } [ 1 >bignum T{ foo f 1 2 3 } nth ] unit-test
+{ 3 } [ 2 >bignum T{ foo f 1 2 3 } nth ] unit-test
diff --git a/basis/named-tuples/named-tuples.factor b/basis/named-tuples/named-tuples.factor
new file mode 100644 (file)
index 0000000..dac47ce
--- /dev/null
@@ -0,0 +1,36 @@
+! Copyright (C) 2018 John Benediktsson
+! See http://factorcode.org/license.txt for BSD license
+
+USING: accessors assocs classes classes.tuple
+classes.tuple.private kernel math sequences sequences.private
+slots.private ;
+
+IN: named-tuples
+
+MIXIN: named-tuple
+
+M: named-tuple assoc-size tuple-size ;
+
+M: named-tuple at*
+    [ nip ] [ ?offset-of-slot ] 2bi [ slot t ] [ drop f f ] if* ;
+
+M: named-tuple set-at set-slot-named ;
+
+M: named-tuple >alist
+    dup class-of all-slots
+    [ [ offset>> slot ] [ name>> ] bi swap ] with { } map>assoc ;
+
+INSTANCE: named-tuple assoc
+
+M: named-tuple length tuple-size ;
+
+M: named-tuple nth-unsafe
+    [ integer>fixnum ] dip array-nth ;
+
+M: named-tuple set-nth-unsafe
+    [ integer>fixnum ] dip set-array-nth ;
+
+M: named-tuple like class-of slots>tuple ;
+
+INSTANCE: named-tuple sequence
+
diff --git a/basis/named-tuples/summary.txt b/basis/named-tuples/summary.txt
new file mode 100644 (file)
index 0000000..92112c7
--- /dev/null
@@ -0,0 +1 @@
+Use tuples like both sequences and assocs
diff --git a/basis/named-tuples/tags.txt b/basis/named-tuples/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
diff --git a/extra/named-tuples/authors.txt b/extra/named-tuples/authors.txt
deleted file mode 100644 (file)
index e091bb8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-John Benediktsson
diff --git a/extra/named-tuples/named-tuples-docs.factor b/extra/named-tuples/named-tuples-docs.factor
deleted file mode 100644 (file)
index c61fd43..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-USING: assocs classes.mixin help.markup help.syntax named-tuples
-sequences ;
-
-HELP: named-tuple
-{ $class-description "A " { $link mixin-class } " that allows you to treat a tuple as both a " { $link sequence } " and an " { $link assoc } "." } ;
diff --git a/extra/named-tuples/named-tuples-tests.factor b/extra/named-tuples/named-tuples-tests.factor
deleted file mode 100644 (file)
index ea55cca..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-USING: arrays assocs classes.tuple kernel math named-tuples
-sequences tools.test ;
-IN: named-tuples.tests
-
-TUPLE: foo x y z ;
-
-INSTANCE: foo named-tuple
-
-{ { f f f } } [ T{ foo } >array ] unit-test
-{ { 1 f f } } [ T{ foo f 1 } >array ] unit-test
-{ { 1 2 f } } [ T{ foo f 1 2 } >array ] unit-test
-{ { 1 2 3 } } [ T{ foo f 1 2 3 } >array ] unit-test
-
-{ T{ foo } } [ { } T{ foo } like ] unit-test
-{ T{ foo f 1 } } [ { 1 } T{ foo } like ] unit-test
-{ T{ foo f 1 2 } } [ { 1 2 } T{ foo } like ] unit-test
-{ T{ foo f 1 2 3 } } [ { 1 2 3 } T{ foo } like ] unit-test
-
-{ { { "x" f } { "y" f } { "z" f } } } [ T{ foo } >alist ] unit-test
-{ { { "x" 1 } { "y" f } { "z" f } } } [ T{ foo f 1 } >alist ] unit-test
-{ { { "x" 1 } { "y" 2 } { "z" f } } } [ T{ foo f 1 2 } >alist ] unit-test
-{ { { "x" 1 } { "y" 2 } { "z" 3 } } } [ T{ foo f 1 2 3 } >alist ] unit-test
-
-{ f } [ T{ foo } "x" of ] unit-test
-{ f } [ T{ foo } "y" of ] unit-test
-{ f } [ T{ foo } "z" of ] unit-test
-
-{ f f } [ "not found" T{ foo f 1 2 3 } at* ] unit-test
-
-{ T{ foo f "x" 2 3 } } [ T{ foo f 1 2 3 } "x" dup pick set-at ] unit-test
-
-[ 1 "not found" T{ foo f 1 2 3 } set-at ] [ no-slot? ] must-fail-with
-
-{ 1 } [ T{ foo f 1 2 3 } "x" of ] unit-test
-{ 2 } [ T{ foo f 1 2 3 } "y" of ] unit-test
-{ 3 } [ T{ foo f 1 2 3 } "z" of ] unit-test
-
-{ 1 } [ 0 >bignum T{ foo f 1 2 3 } nth ] unit-test
-{ 2 } [ 1 >bignum T{ foo f 1 2 3 } nth ] unit-test
-{ 3 } [ 2 >bignum T{ foo f 1 2 3 } nth ] unit-test
diff --git a/extra/named-tuples/named-tuples.factor b/extra/named-tuples/named-tuples.factor
deleted file mode 100644 (file)
index dac47ce..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-! Copyright (C) 2018 John Benediktsson
-! See http://factorcode.org/license.txt for BSD license
-
-USING: accessors assocs classes classes.tuple
-classes.tuple.private kernel math sequences sequences.private
-slots.private ;
-
-IN: named-tuples
-
-MIXIN: named-tuple
-
-M: named-tuple assoc-size tuple-size ;
-
-M: named-tuple at*
-    [ nip ] [ ?offset-of-slot ] 2bi [ slot t ] [ drop f f ] if* ;
-
-M: named-tuple set-at set-slot-named ;
-
-M: named-tuple >alist
-    dup class-of all-slots
-    [ [ offset>> slot ] [ name>> ] bi swap ] with { } map>assoc ;
-
-INSTANCE: named-tuple assoc
-
-M: named-tuple length tuple-size ;
-
-M: named-tuple nth-unsafe
-    [ integer>fixnum ] dip array-nth ;
-
-M: named-tuple set-nth-unsafe
-    [ integer>fixnum ] dip set-array-nth ;
-
-M: named-tuple like class-of slots>tuple ;
-
-INSTANCE: named-tuple sequence
-
diff --git a/extra/named-tuples/summary.txt b/extra/named-tuples/summary.txt
deleted file mode 100644 (file)
index 92112c7..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Use tuples like both sequences and assocs
diff --git a/extra/named-tuples/tags.txt b/extra/named-tuples/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections