Skip to content

Instantly share code, notes, and snippets.

@sw1nn
Created October 9, 2014 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sw1nn/f8463b5bfed6db7a9f30 to your computer and use it in GitHub Desktop.
Save sw1nn/f8463b5bfed6db7a9f30 to your computer and use it in GitHub Desktop.
user> *clojure-version*
{:major 1, :minor 7, :incremental 0, :qualifier "alpha2"}
user> (defn colsum [f1]
(let [acc (atom (repeat 0))]
(fn
([] (f1))
([result] (f1 (vec @acc)))
([result input]
(swap! acc #(map + %1 %2) input)
result))))
#'user/colsum
user> (transduce colsum (fn ([]) ([x] x)) (repeat 1000 (range 5)))
[0 1000 2000 3000 4000]
user> (transduce colsum (fn ([]) ([x] x)) (repeat 10000 (range 5)))
StackOverflowError clojure.core/map/fn--4349 (core.clj:2617)
user> (cemerick.piggieback/cljs-repl :repl-env (weasel.repl.websocket/repl-env :port 9001))
;;; output cleared
cljs.user> ;; clojurescript 0.0-2342
cljs.user> (defn colsum [f1]
(let [acc (atom (repeat 0))]
(fn
([] (f1))
([result] (f1 (vec @acc)))
([result input]
(swap! acc #(map + %1 %2) input)
result))))
;;; output cleared
cljs.user> (transduce colsum (fn ([]) ([x] x)) (repeat 1000 (range 5)))
[0 1000 2000 3000 4000]
cljs.user> (transduce colsum (fn ([]) ([x] x)) (repeat 10000 (range 5)))
"Error evaluating:" (transduce colsum (fn ([]) ([x] x)) (repeat 10000 (range 5))) :as "cljs.core.transduce.call(null,cljs.user.colsum,(function() {\nvar G__24463 = null;\nvar G__24463__0 = (function (){return null;\n});\nvar G__24463__1 = (function (x){return x;\n});\nG__24463 = function(x){\nswitch(arguments.length){\ncase 0:\nreturn G__24463__0.call(this);\ncase 1:\nreturn G__24463__1.call(this,x);\n}\nthrow(new Error('Invalid arity: ' + arguments.length));\n};\nG__24463.cljs$core$IFn$_invoke$arity$0 = G__24463__0;\nG__24463.cljs$core$IFn$_invoke$arity$1 = G__24463__1;\nreturn G__24463;\n})()\n,cljs.core.repeat.call(null,(10000),cljs.core.range.call(null,(5))));\n"
#<RangeError: Maximum call stack size exceeded>
RangeError: Maximum call stack size exceeded
at http://localhost:8000/assets/generated/cljs/core.js:2538:15
at seq (http://localhost:8000/assets/generated/cljs/core.js:2547:3)
at cljs.core.map.map__3 (http://localhost:8000/assets/generated/cljs/core.js:11123:105)
at cljs.core.LazySeq.sval (http://localhost:8000/assets/generated/cljs/core.js:7106:23)
at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:8000/assets/generated/cljs/core.js:7159:30)
at _seq (http://localhost:8000/assets/generated/cljs/core.js:1499:11)
at seq (http://localhost:8000/assets/generated/cljs/core.js:2548:24)
at cljs.core.map.map__3 (http://localhost:8000/assets/generated/cljs/core.js:11123:105)
at cljs.core.LazySeq.sval (http://localhost:8000/assets/generated/cljs/core.js:7106:23)
at cljs.core.LazySeq.cljs$core$ISeqable$_seq$arity$1 (http://localhost:8000/assets/generated/cljs/core.js:7159:30)
nil
cljs.user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment