groovy: implement conj
authorJoel Martin <github@martintribe.org>
Thu, 8 Oct 2015 20:15:25 +0000 (15:15 -0500)
committerJoel Martin <github@martintribe.org>
Thu, 8 Oct 2015 22:15:33 +0000 (17:15 -0500)
12 files changed:
.travis.yml
coffee/step1_read_print.coffee
coffee/step2_eval.coffee
coffee/step3_env.coffee
coffee/step4_if_fn_do.coffee
coffee/step5_tco.coffee
coffee/step6_file.coffee
coffee/step7_quote.coffee
coffee/step8_macros.coffee
coffee/step9_try.coffee
coffee/stepA_mal.coffee
groovy/core.groovy

index ff23540..31869b6 100644 (file)
@@ -10,7 +10,7 @@ env:
     - IMPL=bash
     - IMPL=c
     - IMPL=cpp
-    - IMPL=coffee  # step5 hangs
+    - IMPL=coffee
     - IMPL=cs
     - IMPL=clojure
     - IMPL=crystal
@@ -22,7 +22,7 @@ env:
     - IMPL=fsharp
     - IMPL=go
     - IMPL=groovy  # stepA conj failures
-    #- IMPL=guile  # docker build issues
+    #- IMPL=guile  # step0 regex issues
     - IMPL=haskell
     - IMPL=java
     - IMPL=js
index 28edd1b..d5ab6b7 100644 (file)
@@ -21,7 +21,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 1b3438e..6b51748 100644 (file)
@@ -46,7 +46,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 1446197..16d6151 100644 (file)
@@ -57,7 +57,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index ef33478..54dc8a9 100644 (file)
@@ -70,7 +70,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index fa5aced..7822b7f 100644 (file)
@@ -76,7 +76,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index feafc63..2a0ded0 100644 (file)
@@ -84,7 +84,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 7652a79..f66bedf 100644 (file)
@@ -100,7 +100,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 6150d2e..ed0dd65 100644 (file)
@@ -120,7 +120,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index d8f6f43..30bcaf0 100644 (file)
@@ -128,7 +128,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 751f9ad..52fa0a5 100644 (file)
@@ -136,7 +136,9 @@ while (line = readline.readline("user> ")) != null
     console.log rep line
   catch exc
     continue if exc instanceof reader.BlankException
-    if exc.stack then console.log exc.stack
-    else              console.log exc
+    if exc.stack? and exc.stack.length > 2000
+      console.log exc.stack.slice(0,1000) + "\n  ..." + exc.stack.slice(-1000)
+    else if exc.stack? console.log exc.stack
+    else               console.log exc
 
 # vim: ts=2:sw=2
index 08c234a..d266fad 100644 (file)
@@ -27,6 +27,13 @@ class core {
         }
         args[0][args[1]]
     }
+    def static do_conj(args) {
+        if (types.list_Q(args[0])) {
+            args.drop(1).inject(args[0], { a, b -> [b] + a })
+        } else {
+            types.vector(args.drop(1).inject(args[0], { a, b -> a + [b] }))
+        }
+    }
     def static do_apply(args) {
         def start_args = args.drop(1).take(args.size()-2) as List
         args[0](start_args + (args.last() as List))
@@ -91,7 +98,7 @@ class core {
         "apply": core.&do_apply,
         "map": { a -> a[1].collect { x -> a[0].call([x]) } },
 
-        "conj": null,
+        "conj": core.&do_conj,
 
         "meta": { a -> a[0].hasProperty("meta") ? a[0].getProperties().meta : null },
         "with-meta": { a -> def b = types.copy(a[0]); b.getMetaClass().meta = a[1]; b },