From c65e299e8c9bbe2d460203e4fd38219333f286cc Mon Sep 17 00:00:00 2001
From: James Cash <james.nvc@gmail.com>
Date: Mon, 2 Jun 2008 01:26:10 -0400
Subject: [PATCH] Moving cons stuff into its own sub-vocab

---
 extra/lisp/conses/authors.txt         |  1 +
 extra/lisp/conses/conses-docs.factor  |  0
 extra/lisp/conses/conses-tests.factor | 13 +++++++++++++
 extra/lisp/conses/conses.factor       | 26 ++++++++++++++++++++++++++
 extra/lisp/conses/summary.txt         |  1 +
 extra/lisp/conses/tags.txt            |  4 ++++
 extra/lisp/lisp.factor                |  5 +----
 extra/lisp/parser/parser-tests.factor |  2 +-
 extra/lisp/parser/parser.factor       | 11 +----------
 9 files changed, 48 insertions(+), 15 deletions(-)
 create mode 100644 extra/lisp/conses/authors.txt
 create mode 100644 extra/lisp/conses/conses-docs.factor
 create mode 100644 extra/lisp/conses/conses-tests.factor
 create mode 100644 extra/lisp/conses/conses.factor
 create mode 100644 extra/lisp/conses/summary.txt
 create mode 100644 extra/lisp/conses/tags.txt

diff --git a/extra/lisp/conses/authors.txt b/extra/lisp/conses/authors.txt
new file mode 100644
index 0000000000..4b7af4aac0
--- /dev/null
+++ b/extra/lisp/conses/authors.txt
@@ -0,0 +1 @@
+James Cash
diff --git a/extra/lisp/conses/conses-docs.factor b/extra/lisp/conses/conses-docs.factor
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/extra/lisp/conses/conses-tests.factor b/extra/lisp/conses/conses-tests.factor
new file mode 100644
index 0000000000..e4288a2e11
--- /dev/null
+++ b/extra/lisp/conses/conses-tests.factor
@@ -0,0 +1,13 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: tools.test lisp.conses math ;
+
+IN: lisp.conses.tests
+
+{ { 3 4 5 6 } } [
+    T{ cons f 1       
+        T{ cons f 2 
+            T{ cons f 3
+                T{ cons f 4
+                T{ cons f f f } } } } } [ 2 + ] map-cons
+] unit-test
\ No newline at end of file
diff --git a/extra/lisp/conses/conses.factor b/extra/lisp/conses/conses.factor
new file mode 100644
index 0000000000..3fdbc25b0e
--- /dev/null
+++ b/extra/lisp/conses/conses.factor
@@ -0,0 +1,26 @@
+! Copyright (C) 2008 James Cash
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences accessors ;
+
+IN: lisp.conses 
+
+TUPLE: cons car cdr ;
+: cons \ cons new ;
+    
+: uncons ( cons -- cdr car )
+    [ cdr>> ] [ car>> ] bi ;
+
+: null? ( cons -- ? )
+    uncons and not ;
+
+: <car> ( x -- cons )
+    cons swap >>car ;
+
+: seq>cons ( seq -- cons )
+    <reversed> cons [ <car> swap >>cdr ] reduce ;
+    
+: (map-cons) ( acc cons quot -- seq )    
+    over null? [ 2drop ] [ [ uncons ] dip [ call ] keep swapd [ suffix ] 2dip (map-cons) ] if ;
+    
+: map-cons ( cons quot -- seq )
+    [ { } clone ] 2dip (map-cons) ;
\ No newline at end of file
diff --git a/extra/lisp/conses/summary.txt b/extra/lisp/conses/summary.txt
new file mode 100644
index 0000000000..d69b63b233
--- /dev/null
+++ b/extra/lisp/conses/summary.txt
@@ -0,0 +1 @@
+Cons cell helper functions for extra/lisp
diff --git a/extra/lisp/conses/tags.txt b/extra/lisp/conses/tags.txt
new file mode 100644
index 0000000000..a3f9681acb
--- /dev/null
+++ b/extra/lisp/conses/tags.txt
@@ -0,0 +1,4 @@
+lisp
+cons
+lists
+sequences
diff --git a/extra/lisp/lisp.factor b/extra/lisp/lisp.factor
index 59b0ccdff2..3d977df97f 100644
--- a/extra/lisp/lisp.factor
+++ b/extra/lisp/lisp.factor
@@ -3,12 +3,9 @@
 USING: kernel peg sequences arrays strings combinators.lib
 namespaces combinators math locals locals.private accessors
 vectors syntax lisp.parser assocs parser sequences.lib words quotations
-fry ;
+fry lisp.conses ;
 IN: lisp
 
-: uncons ( cons -- cdr car )
-    [ cdr>> ] [ car>> ] bi ;
-
 DEFER: convert-form
 DEFER: funcall
 DEFER: lookup-var
diff --git a/extra/lisp/parser/parser-tests.factor b/extra/lisp/parser/parser-tests.factor
index 712a1f9b9e..9c33f635f9 100644
--- a/extra/lisp/parser/parser-tests.factor
+++ b/extra/lisp/parser/parser-tests.factor
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 James Cash
 ! See http://factorcode.org/license.txt for BSD license.
-USING: lisp.parser tools.test peg peg.ebnf ;
+USING: lisp.parser tools.test peg peg.ebnf lisp.conses ;
 
 IN: lisp.parser.tests
 
diff --git a/extra/lisp/parser/parser.factor b/extra/lisp/parser/parser.factor
index dad6a7dc24..9679c77209 100644
--- a/extra/lisp/parser/parser.factor
+++ b/extra/lisp/parser/parser.factor
@@ -1,22 +1,13 @@
 ! Copyright (C) 2008 James Cash
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel peg peg.ebnf peg.expr math.parser sequences arrays strings
-combinators.lib math fry accessors ;
+combinators.lib math fry accessors lisp.conses ;
 
 IN: lisp.parser
 
 TUPLE: lisp-symbol name ;
 C: <lisp-symbol> lisp-symbol
 
-TUPLE: cons car cdr ;
-: cons \ cons new ;
-
-: <car> ( x -- cons )
-    cons swap >>car ;
-
-: seq>cons ( seq -- cons )
-    <reversed> cons [ <car> swap >>cdr ] reduce ;
-    
 EBNF: lisp-expr
 _            = (" " | "\t" | "\n")*
 LPAREN       = "("