Skip to content

A peer-to-peer stack for code collaboration

Remove Y-combinators. (#268)

Julian Arni13036c77afe5
diff --git a/docs/source/reference.rst b/docs/source/reference.rst
index 5369e81..ee391bc 100644
--- a/docs/source/reference.rst
+++ b/docs/source/reference.rst
@@ -127,16 +127,6 @@ values.
Throws an exception. The first argument should be an atom used as a
label for the exception, the second can be any value.
-``(Y h)``
-~~~~~~~~~
-
-A combinator used to create recursive functions of one variable.
-
-``(Y2 h)``
-~~~~~~~~~~
-
-A combinator used to create recursive functions of two variables.
-
``to-json``
~~~~~~~~~~~
@@ -241,7 +231,7 @@ Adds an element to the front of a list.
``(reverse ls)``
~~~~~~~~~~~~~~~~
-Returns the reversed 'list'.
+Returns the reversed 'ls'.
``(length xs)``
~~~~~~~~~~~~~~~
@@ -261,7 +251,7 @@ Returns 'list' with only the elements that satisfy 'filter-cond'.
``(range from to)``
~~~~~~~~~~~~~~~~~~~
-Returns a list with all integers from 'start' to 'end', inclusive.
+Returns a list with all integers from ``from`` to ``end``, inclusive.
``(list-with-head x f g)``
~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/exe/ReferenceDoc.hs b/exe/ReferenceDoc.hs
index 1312a3e..fd1a9f6 100644
--- a/exe/ReferenceDoc.hs
+++ b/exe/ReferenceDoc.hs
@@ -78,7 +78,7 @@ main = do
basics =
[ "eq?", "not", "and", "or", "all", "some", "show", "string-append", "string-length"
, "apply", "type", "atom?", "boolean?", "string?", "number?", "keyword?", "vector?", "list?"
- , "dict?", "read", "read-many", "throw", "Y", "Y2", "to-json", "uuid?", "make-counter"
+ , "dict?", "read", "read-many", "throw", "to-json", "uuid?", "make-counter"
, "public-key?" ]
maths = ["+", "*", "-", "/", "<", ">", "integral?"]
evalFns = ["base-eval", "eval", "updatable-eval"]
diff --git a/rad/prelude.rad b/rad/prelude.rad
index e56cc63..ec92f6c 100644
--- a/rad/prelude.rad
+++ b/rad/prelude.rad
@@ -5,7 +5,6 @@
(load! "rad/prelude/io.rad")
(load! "rad/prelude/bool.rad")
(load! "rad/prelude/exception.rad")
-(load! "rad/prelude/recursion.rad")
(load! "rad/prelude/list.rad")
(load! "rad/prelude/dict.rad")
(load! "rad/prelude/set.rad")
@@ -22,7 +21,6 @@
"rad/prelude/test.rad" ;; pure unless test env
"rad/prelude/basic.rad"
"rad/prelude/patterns.rad"
- "rad/prelude/recursion.rad"
"rad/prelude/bool.rad"
"rad/prelude/list.rad"
"rad/prelude/dict.rad"
diff --git a/rad/prelude/list.rad b/rad/prelude/list.rad
index 9add853..5903783 100644
--- a/rad/prelude/list.rad
+++ b/rad/prelude/list.rad
@@ -19,13 +19,13 @@
;; reverse
(def reverse
- "Returns the reversed 'list'."
+ "Returns the reversed 'ls'."
(fn [ls]
- (def go (Y2 (fn [go]
+ (def-rec go
(fn [acc new]
(if (empty? new)
acc
- (go (cons (head new) acc) (tail new)))))))
+ (go (cons (head new) acc) (tail new)))))
(go (list) ls)))
(:test "reverse"
@@ -34,12 +34,12 @@
;; range
-(def range
- "Returns a list with all integers from 'start' to 'end', inclusive."
- (Y2 (fn [range] (fn [from to]
+(def-rec range
+ "Returns a list with all integers from `from` to `end`, inclusive."
+ (fn [from to]
(if (eq? from to)
(list to)
- (cons from (range (+ 1 from) to)))))))
+ (cons from (range (+ 1 from) to)))))
(:test "range"
[ (range 1 5) ==> (1 2 3 4 5) ]
@@ -58,14 +58,13 @@
;; filter
-(def filter
+(def-rec filter
"Returns 'list' with only the elements that satisfy 'filter-cond'."
- (Y2 (fn [filter] (fn [pred ls]
- (if (empty? ls)
- ls
- (if (pred (head ls))
- (cons (head ls) (filter pred (tail ls)))
- (filter pred (tail ls))))))))
+ (fn [pred ls]
+ (cond
+ (empty? ls) ls
+ (pred (head ls)) (cons (head ls) (filter pred (tail ls)))
+ :else (filter pred (tail ls)))))
(:test "filter"
[ (filter (fn [x] (< x 10)) (list 3 10 11))
diff --git a/rad/prelude/recursion.rad b/rad/prelude/recursion.rad
deleted file mode 100644
index b2e8859..0000000
--- a/rad/prelude/recursion.rad
+++ /dev/null
@@ -1,21 +0,0 @@
-;; y-combinators ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
-(def Y
- "A combinator used to create recursive functions of one variable."
- (fn [h]
- ((fn [x] (x x))
- (fn [g]
- (h (fn [arg] ((g g) arg)))))))
-(def Y2
- "A combinator used to create recursive functions of two variables."
- (fn [h]
- ((fn [x] (x x))
- (fn [g]
- (h (fn [arg1 arg2] ((g g) arg1 arg2)))))))
-
-(:test "Y combinator"
- [ (do
- (def fac (Y (fn [f] (fn [x] (if (< x 2) 1 (* x (f (- x 1))))))))
- (fac 10)) ==> 3628800
- ]
-)