Repository: brandonwillard/loghyc (language: python)

Issue:
simple replace pycons
replace cons  to python-cons
Readme fix


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index f32d5e6..9c2ffff 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,9 @@
 language: python
 python:
-  - "3.5"
   - "3.6"
   - "3.7"
-  - "pypy3.5"
+  - "3.8"  
+  - "pypy3"
 install: pip install -r requirements.txt
 script:
   - nosetests -v tests
diff --git a/README.md b/README.md
index 5f5aee4..54af270 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,8 @@ Example
 -------
 
 ```hy
-(import [adderall.dsl [*]])
-(require adderall.dsl)
+(import  [adderall.dsl [*]])
+(require [adderall.dsl [*]])
 
 (run* [q] (condᵉ [(≡ q 'tea)]
                  [(≡ q 'coffee) succeed]))
@@ -51,8 +51,8 @@ mostly to show the power of the system, or for fun:
 ```hy
 (import [adderall.dsl [*]]
         [adderall.extra.zebra [*]])
-(require adderall.dsl)
-(require adderall.extra.zebra)
+(require [adderall.dsl [*]])
+(require [adderall.extra.zebra [*]])
 
 (run* [water-drinker horse-owner] (zebraᵖ water-drinker horse-owner))
 ;; => [['norvegian 'japanese]]
diff --git a/adderall/bitnum.hy b/adderall/bitnum.hy
index 2067a18..e7cb110 100644
--- a/adderall/bitnum.hy
+++ b/adderall/bitnum.hy
@@ -14,6 +14,8 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
+
 (import [adderall.dsl [*]]
         [adderall.internal [*]])
 
diff --git a/adderall/dsl.hy b/adderall/dsl.hy
index 14c4455..f85ae38 100644
--- a/adderall/dsl.hy
+++ b/adderall/dsl.hy
@@ -17,6 +17,7 @@
 (import [functools [reduce partial]]
         [hy [HySymbol HyExpression HyList HyKeyword]]
         [hy.contrib.walk [prewalk]])
+(import [cons [cons car cdr]])
 (import [adderall.internal [unify lvar? seq? reify
                             LVar unbound interleave cons]])
 
diff --git a/adderall/internal.hy b/adderall/internal.hy
index fda0327..57f1788 100644
--- a/adderall/internal.hy
+++ b/adderall/internal.hy
@@ -17,7 +17,9 @@
 (import [collections.abc [Iterable]])
 
 (require [hy.contrib.walk [let]])
-
+(import [cons [cons car cdr]])
+(import [cons.core [ConsPair MaybeCons ConsNull]])
+;;(import [unification [unify  reify var]])
 
 (defmacro defmacro-alias [names lambda-list &rest body]
   "define one macro with several names"
@@ -30,72 +32,6 @@
     (+ `(do (defn ~main ~lambda-list ~@body))
        (lfor name aliases `(setv ~name ~main)))))
 
-(defclass ConsPair [Iterable]
-  "Construct a cons list.
-
-A Python `list` is returned when the cdr is a `list` or `None`; otherwise, a
-`ConsPair` is returned.
-
-The arguments to `ConsPair` can be a car & cdr pair, or a sequence of objects to
-be nested in `cons`es, e.g.
-
-    (ConsPair car-1 car-2 car-3 cdr) == (ConsPair car-1 (cons car-2 (cons car-3 cdr)))
-"
-  (defn --new-- [cls &rest parts]
-    (if (> (len parts) 2)
-        (reduce (fn [x y] (ConsPair y x))
-                (reversed parts))
-        ;; Handle basic car, cdr case.
-        (do (setv car-part (-none-to-empty-or-list
-                             (first parts)))
-            (setv cdr-part (-none-to-empty-or-list
-                             (if (and (coll? parts)
-                                      (> (len parts) 1))
-                                 (last parts)
-                                 None)))
-            (if (list? cdr-part)
-                ;; Try to preserve the exact type of list
-                ;; (e.g. in case it's actually a HyList).
-                (+ ((type cdr-part) [car-part]) cdr-part)
-                (do
-                  (setv instance (.--new-- (super ConsPair cls) cls))
-                  (setv instance.car car-part)
-                  (setv instance.cdr cdr-part)
-                  instance)))))
-  (defn --hash-- [self]
-    (hash [self.car, self.cdr]))
-  (defn --eq-- [self other]
-    (and (= (type self) (type other))
-         (= self.car other.car)
-         (= self.cdr other.cdr)))
-  (defn --iter-- [self]
-    (yield self.car)
-    (if (list? self.cdr)
-        (for [x self.cdr] (yield x))
-        (raise StopIteration)))
-  (defn --repr-- [self]
-    (.format "({} . {})" self.car self.cdr)))
-
-(defn -none-to-empty-or-list [x]
-  (cond [(none? x) (list)]
-        [(and (coll? x)
-              (not (cons? x))
-              (not (list? x)))
-         (list x)]
-        [True x]))
-
-;; A synonym for ConsPair
-(setv cons ConsPair)
-
-(defn car [z]
-  (or (getattr z "car" None)
-      (-none-to-empty-or-list (first z))))
-(defn cdr [z]
-  (or (getattr z "cdr" None)
-      ;; Try to preserve the exact type of list
-      ;; (e.g. in case it's actually a HyList).
-      ((type z) (list (rest z)))))
-
 (defn lvar? [x] (instance? LVar x))
 (defn tuple? [x] (instance? tuple x))
 (defn list? [x] (instance? list x))
diff --git a/requirements.txt b/requirements.txt
index 43a2f45..46a6da2 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
 -e git://github.com/hylang/hy.git@master#egg=hy
 -e git://github.com/algernon/monaxhyd.git@master#egg=monaxhyd
+-e git://github.com/pythological/python-cons.git#egg=cons
diff --git a/setup.py b/setup.py
index e64e9b4..8770ac2 100755
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,7 @@
 setup(
     name="adderall",
     version="2.0.0",
-    install_requires=['hy>=0.15', 'monaxhyd>=0.2.1'],
+    install_requires=['hy>=0.15', 'monaxhyd>=0.2.1', "cons>=0.3.1"],
     packages=find_packages(exclude=['tests', 'tests.extra', 'tests.schemer']),
     package_data={
         'adderall': ['*.hy'],
@@ -35,7 +35,7 @@
     license="LGPL-3",
     url="https://github.com/algernon/adderall",
     platforms=['any'],
-    python_requires='>=3.4',
+    python_requires='>=3.6',
     classifiers=[
         "Development Status :: 5 - Production/Stable",
         "Intended Audience :: Developers",


Test patch:
diff --git a/tests/adderall_test.hy b/tests/adderall_test.hy
index 4f2a4f8..251274f 100644
--- a/tests/adderall_test.hy
+++ b/tests/adderall_test.hy
@@ -15,6 +15,7 @@
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 (import [nose.tools [assert-equal assert-not-equal]]
+        [cons [cons car cdr]]
         [adderall.dsl [*]]
         [adderall.internal [*]])
 
@@ -29,69 +30,29 @@
   None)
 
 (defn test-cons []
-  (assert-all-equal (cons 'a None)
-                    (cons 'a [])
-                    (cons 'a (,))
-                    (cons 'a '())
-                    ['a])
-  (assert-all-equal (cons None 'a)
-                    (cons [] 'a)
-                    (cons (,) 'a)
-                    (cons '() 'a))
-  (assert-not-equal (cons 'a None)
-                    (, 'a))
-  (assert-equal (cons 'a None)
-                (list (, 'a)))
-
-  (assert-all-equal (cons 'a '(b c))
-                    (cons 'a ['b 'c])
-                    (cons 'a (, 'b 'c))
-                    ['a 'b 'c])
-  (assert-not-equal (cons 'a (, 'b 'c))
-                    (, 'a))
-  (assert-all-equal (cons 'a None)
-                    (list (, 'a)))
-
-  (assert-all-equal (cons '(a b) 'c)
-                    (cons ['a 'b] 'c)
-                    (cons (, 'a 'b) 'c))
-
-  (assert-all-equal (cons '(a b) '(c d))
-                    (cons '(a b) ['c 'd])
-                    (cons '(a b) (, 'c 'd))
-                    [['a 'b] 'c 'd])
-  (assert-not-equal (cons 'a (, 'b 'c))
-                    (, 'a 'b 'c))
-  (assert-all-equal (cons 'a (, 'b 'c))
-                    (list (, 'a 'b 'c)))
-  (assert-all-equal (cons '(a b) 'c)
-                    (cons ['a 'b] 'c)
-                    (cons (, 'a 'b) 'c))
-  (assert-all-equal (cons '(a b) '(c))
-                    (cons ['a 'b] ['c])
-                    (cons (, 'a 'b) (, 'c))
-                    [['a 'b] 'c])
-  (assert-equal (car (cons 'a 'b)) 'a)
-  (assert-all-equal (car (cons '(a b) 'a))
-                    (car (cons ['a 'b] 'a))
-                    (car (cons (, 'a 'b) 'a))
-                    ['a 'b])
-  (assert-not-equal (car (cons (, 'a 'b) 'a))
-                    (, 'a 'b))
-  (assert-equal (cdr (cons 'a 'b)) 'b)
-  (assert-all-equal (cdr (cons 'a None))
-                    (cdr (cons '(a) None))
-                    (cdr (cons 'a '()))
-                    (cdr (cons 'a (,)))
-                    (cdr (cons 'a []))
-                    [])
-  (assert-all-equal (cdr (cons 'a '(b)))
-                    (cdr (cons '(a) '(b)))
-                    (cdr (cons 'a ['b]))
-                    (cdr (cons 'a (, 'b)))
-                    ['b])
-  (assert-not-equal (cdr (cons 'a (, 'b)))
-                    (, 'b)))
+  (assert-equal 
+    (cons 'a '())
+    '(a))
+  (assert-equal
+    (cons 'a '(b c))
+    '(a b c))
+  (assert-equal
+    (cons '(a b) '(c d))
+    '((a b) c d))
+  (assert-equal
+    (cons '(a b) '(c))
+    '((a b) c))
+  (assert-equal
+    (car (cons '(a b) 'a))
+    '(a b))
+  (assert-equal
+    (cdr (cons 'a '()))
+    '())
+  (assert-all-equal
+    (cdr (cons 'a '(b)))
+    (cdr (cons '(a) '(b)))
+    '(b))
+)
 
 (defn test-fail-and-succeed []
   (assert-equal (run* [q] fail) [])
@@ -150,13 +111,13 @@
                             (memberᵒ ?y [1 3 5])))
                 [1 3 5 4 4 4 2 2 2]))
 
-(defn test-set-support []
-  (assert-equal (run* [q]
-                      (memberᵒ q (set [1 2 3 1 2 3])))
-                [1 2 3])
-  (assert-equal (run* [q]
-                      (memberᵒ 3 (set [1 2 q q])))
-                [3]))
+;; (defn test-set-support []
+;;   (assert-equal (run* [q]
+;;                       (memberᵒ q (set [1 2 3 1 2 3])))
+;;                 [1 2 3])
+;;   (assert-equal (run* [q]
+;;                       (memberᵒ 3 (set [1 2 q q])))
+;;                 [3]))
 
 (defn test-lazyness []
   (assert-equal (first (wrap-stdout
diff --git a/tests/schemer/chapter01.hy b/tests/schemer/chapter01.hy
index 8f53122..35f7e2e 100644
--- a/tests/schemer/chapter01.hy
+++ b/tests/schemer/chapter01.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]])
 (import [tests.schemer.common [*]])
 
diff --git a/tests/schemer/chapter02.hy b/tests/schemer/chapter02.hy
index 71d657c..0502550 100644
--- a/tests/schemer/chapter02.hy
+++ b/tests/schemer/chapter02.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [adderall.internal [*]])
 (import [tests.schemer.common [*]])
diff --git a/tests/schemer/chapter03.hy b/tests/schemer/chapter03.hy
index 52c93df..3d9b74d 100644
--- a/tests/schemer/chapter03.hy
+++ b/tests/schemer/chapter03.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [adderall.internal [*]])
 (import [tests.schemer.common [*]])
diff --git a/tests/schemer/chapter04.hy b/tests/schemer/chapter04.hy
index 7ef2e6c..43849c2 100644
--- a/tests/schemer/chapter04.hy
+++ b/tests/schemer/chapter04.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [adderall.internal [*]]
         [tests.schemer.common [*]])
diff --git a/tests/schemer/chapter05.hy b/tests/schemer/chapter05.hy
index 7a3bc7b..d080461 100644
--- a/tests/schemer/chapter05.hy
+++ b/tests/schemer/chapter05.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [adderall.internal [*]]
         [tests.schemer.common [*]])
diff --git a/tests/schemer/chapter06.hy b/tests/schemer/chapter06.hy
index 699b809..b669843 100644
--- a/tests/schemer/chapter06.hy
+++ b/tests/schemer/chapter06.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [tests.schemer.common [*]])
 (require [adderall.dsl [*]])
diff --git a/tests/schemer/chapter07.hy b/tests/schemer/chapter07.hy
index e8a5c6e..b5d1244 100644
--- a/tests/schemer/chapter07.hy
+++ b/tests/schemer/chapter07.hy
@@ -14,6 +14,7 @@
 ;; You should have received a copy of the GNU Lesser General Public
 ;; License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+(import [cons [cons car cdr]])
 (import [adderall.dsl [*]]
         [adderall.bitnum [*]]
         [adderall.internal [*]])