This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-28
Channels
- # aatree (1)
- # announcements (1)
- # beginners (18)
- # boot (12)
- # cljsjs (1)
- # cljsrn (6)
- # clojure (358)
- # clojure-japan (1)
- # clojure-russia (69)
- # clojurescript (20)
- # core-async (32)
- # cursive (6)
- # datomic (57)
- # devcards (3)
- # dirac (2)
- # editors (8)
- # emacs (6)
- # juxt (1)
- # ldnclj (4)
- # luminus (2)
- # om (91)
- # om-next (2)
- # onyx (11)
- # reagent (7)
What's going on here on 4ojure? I tried this code in Replete so it should be working...
@danlucraft: I’d try that in a Clojure REPL. ClojureScript can let arity errors slip by. A small example: (inc 2 3)
in ClojureScript vs. Clojure.
@mfikes: interesting, thanks. Can't see where I might be messing up though
@danlucraft: Paste code or a gist. Too hard to experiment with an image of code
@mfikes yep sorry! I think trying to do this on iOS is a fools errand really...
Replete is nice.
If it had a persistent history I could go and grab that code right now 😉
@danlucraft: I think this is the same code
(fn [n]
(->> (range 1 n)
(reduce #(let [[a b r] %1
c (+ a b)]
[b c (conj r c)])
[0 1 [1]])
(last)
(into '())
(reverse)))
@danlucraft: ClojureScript isn’t telling you this, while Clojure is.
@danlucraft: using fn
and saving some keystrokes elsewhere in the form:
(fn [n]
(->> (range 1 n)
(reduce (fn [x _]
(let [[a b r] x
c (+ a b)]
[b c (conj r c)]))
[0 1 [1]])
last
(into ())
reverse))
This way, the reduce function has arity 2Ahh so if I'd used %1 and %2 it would have defined an arity 2 function and worked?
So in ClojureScript the arity must not be checked then, because you can pass extra arts to any JS function and they are ignored
@danlucraft: In ClojureScript, sometimes arity causes an error, sometimes it causes a warning. In some bootstrapped implementations, which are new with respect to everything, sometimes you may not get a warning. But, yes, oftentimes things will just work anyway owing to the JavaScript being a bit forgiving.
@danlucraft: It is definitely not the case that ClojureScript has no arity checking.
@danlucraft: Sorry, yes, adding a %2
as in the following is also a valid way to address the issue. No need to fn
.
(fn [n]
(->> (range 1 n)
(reduce #(let [[a b r] %1
c (+ a b)
_ %2]
[b c (conj r c)])
[0 1 [1]])
(last)
(into '())
(reverse)))
got it. Thanks for your help @mfikes I'll do this with more sensible tools next time 😊