#clojure log - May 28 2015

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:00 auxchar: Yeah, I think that'd be cheating.

0:00 justin_smith: delays and promises being like reference types, but only bindable once

0:01 auxchar: technically the def exists before its body is evaluated (to allow recursive functions) but I wouldn't count on correctness

0:01 it's not an intended usage

0:01 ,(def l (list 1 2 l))

0:01 clojurebot: #'sandbox/l

0:01 justin_smith: l

0:01 ,l

0:01 clojurebot: (1 2 #object[clojure.lang.Var$Unbound 0x7a27d8b4 "Unbound: #'sandbox/l"])

0:01 justin_smith: yeah

0:02 so l exists, but it got caught at the wrong time

0:02 auxchar: Except the list isn't holding itself, it's holding the var containing itself.

0:02 justin_smith: auxchar: in clojure we don't really do the "tying the knot" thing you can do in haskell thanks to their pervasively lazy evaluation

0:03 auxchar: yes, that's in fact the only option

0:04 auxchar: It would work with a LazySeq, I would imagine.

0:04 justin_smith: even then it would be a hack

0:04 auxchar: Otherwise a mutable list would be needed.

0:04 justin_smith: ,(def l (cons 1 (lazy-seq l)))

0:04 clojurebot: #'sandbox/l

0:04 justin_smith: ,l

0:04 clojurebot: (1 1 1 1 1 ...)

0:05 justin_smith: I'd still consider that a hack, though it works

0:05 auxchar: Yeah.

0:07 Does its behaviour change if l is defined before some part of it's fully evaluated?

0:07 Err, redefined.

0:08 justin_smith: well, that's what happened the second time I evaluated (def l ...) just now - it had a previous value that was not used at all

0:08 def creates the var (or changes it to unbound) before the body is run

0:10 auxchar: But if you partially evaluated l, passed its value to somewhere else, and redfined l, would it change it's behaviour in the other place?

0:10 justin_smith: it depends, sometimes not unless you passed the var somewhere else

0:11 sometimes the other code would just seamlessly see the new l

0:11 by passed the var I mean passed #'l instead of l

0:11 (as an arg)

0:12 anyway, I'm out for the night

0:12 auxchar: Alright, good night.

0:12 I wanna play with this some more.

0:15 (def l (list 1 (lazy-seq l)))

0:15 ,(def l (list 1 (lazy-seq l)))

0:15 clojurebot: #'sandbox/l

0:15 auxchar: ,(l)

0:15 clojurebot: #error {\n :cause "clojure.lang.PersistentList cannot be cast to clojure.lang.IFn"\n :via\n [{:type java.lang.ClassCastException\n :message "clojure.lang.PersistentList cannot be cast to clojure.lang.IFn"\n :at [sandbox$eval49 invoke "NO_SOURCE_FILE" 0]}]\n :trace\n [[sandbox$eval49 invoke "NO_SOURCE_FILE" 0]\n [clojure.lang.Compiler eval "Compiler.java" 6792]\n [clojure.lang.Compiler eval "...

0:15 auxchar: ,l

0:15 clojurebot: (1 (1 (1 (1 (1 (1 (1 (1 (1 (1 #))))))))))

0:19 auxchar: ,(do (def l (cons 1 (lazy-seq l))) (take 3 l) (def m l) m)

0:19 clojurebot: (1 1 1 1 1 ...)

0:19 auxchar: Ok, so that does work.

0:20 Cool.

0:20 Wait.

0:20 ,(do (def l (cons 1 (lazy-seq l))) (take 3 l) (def m l) (def l nil) m)

0:20 clojurebot: (1)

0:20 auxchar: Nope, it's not what I'm looking for.

0:21 ,(do (def l (cons 1 (lazy-seq l))) (take 3 l) (def m l) (def l 4) m)

0:21 clojurebot: #<IllegalArgumentException java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long>

0:22 auxchar: Ok, I think I get what's going on.

0:37 url-: is source for clojurebot online somewhere?

0:40 tolstoy: Is it this one? https://github.com/Raynes/lazybot or this one? https://github.com/hiredman/clojurebot ?

0:41 ,(+ 2 3)

0:41 clojurebot: 5

0:41 tolstoy: .(+ 2 3)

0:48 auxchar: ,((fn [f n] (f f n)) (fn [f n] (f (+ n 1))))

0:48 clojurebot: #error {\n :cause "Wrong number of args (1) passed to: sandbox/eval49/fn--50"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (1) passed to: sandbox/eval49/fn--50"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 32]\n [sandbox$eval49 invoke "NO_SOURCE_FILE" 0]\n ...

0:48 auxchar: ,((fn [f n] (f f n)) (fn [f n] (f (+ n 1))) 1)

0:48 clojurebot: #error {\n :cause "Wrong number of args (1) passed to: sandbox/eval77/fn--80"\n :via\n [{:type clojure.lang.ArityException\n :message "Wrong number of args (1) passed to: sandbox/eval77/fn--80"\n :at [clojure.lang.AFn throwArity "AFn.java" 429]}]\n :trace\n [[clojure.lang.AFn throwArity "AFn.java" 429]\n [clojure.lang.AFn invoke "AFn.java" 32]\n [sandbox$eval77$fn__80 invoke "NO_SOURCE_FILE"...

0:49 auxchar: ,((fn [f n] (f f n)) (fn [f n] (f f (+ n 1))) 1)

0:49 clojurebot: #error {\n :cause nil\n :via\n [{:type java.lang.StackOverflowError\n :message nil\n :at [clojure.lang.Numbers$LongOps opsWith "Numbers.java" 423]}]\n :trace\n [[clojure.lang.Numbers$LongOps opsWith "Numbers.java" 423]\n [clojure.lang.Numbers$LongOps combine "Numbers.java" 419]\n [clojure.lang.Numbers add "Numbers.java" 128]\n [clojure.lang.Numbers add "Numbers.java" 3644]\n [sandbox$eval1...

0:49 auxchar: Yay.

0:53 (#(%1 %1 %2) #(%1 %1 (+ %2 1)) 1)

0:54 ,(#(%1 %1 %2) #(%1 %1 (+ %2 1)) 1)

0:54 clojurebot: #error {\n :cause nil\n :via\n [{:type java.lang.StackOverflowError\n :message nil\n :at [clojure.lang.Numbers$LongOps opsWith "Numbers.java" 423]}]\n :trace\n [[clojure.lang.Numbers$LongOps opsWith "Numbers.java" 423]\n [clojure.lang.Numbers$LongOps combine "Numbers.java" 419]\n [clojure.lang.Numbers add "Numbers.java" 128]\n [clojure.lang.Numbers add "Numbers.java" 3644]\n [sandbox$eval2...

0:55 auxchar: That ought to make for some interesting production code. ^_^

0:58 TEttinger: auxchar, I'm surprised that even can run

1:05 WickedShell: does anyone know when the estimated release for the next version of core.async is? I saw that poll! was avalible when reading the documentation, which is exactly what I need, only to find out that it isn't in the released version

1:18 tolstoy: seancorfield: Lots of commits on clojure/tools.clj since the last release. Any idea when 0.3.2 might be cut? It's been about one year.

1:18 seancorfield: Yours was the last. ;)

3:26 wei_: came up with this function, nil-safe (defn nil-safe [f] (fn [x & args] (if x (apply f x args)))), kind of like fnil but when you just want the fn to return nil when the first input is nil

3:28 tslocke: Is there a core function like group-by but doesn’t group values - i.e. you get the original values from the collection, not a vector of them, as the map values

3:29 wei_: is there something like this in core? or is this unecessary? the use case that prompted it was casting values in a map, etc (update-in attrs [:wingspan] (nil-safe double))

3:29 tslocke: then it wouldn’t be a group would it? could you give an example

3:31 justin_smith: ,(map #(update-in % [:wingspan] (fn [n] (some-> n (* 2)))) [{:wingspan 1} {}])

3:31 clojurebot: ({:wingspan 2} {:wingspan nil})

3:31 tslocke: no it wouldn’t be a group, i.e. you have a vector of maps where each has a unique key e.g. :name, and you want a map from the names to the original maps

3:32 I realise it’s a one-liner but just wondered if there is a canonical solution

3:36 justin_smith: tslocke: it's an easy thing to derive from group-by, and no it is not built in

3:37 ,(into {} (for [m [{:a 0} {:a 1} {:a 2}]] [(:a m) m]))

3:37 clojurebot: {0 {:a 0}, 1 {:a 1}, 2 {:a 2}}

3:38 justin_smith: no need for group-by actually, now that I think about it

3:38 tslocke: right

3:38 thanks

4:11 otfrom: morning

4:24 dstockton: morning

5:00 studentrob: I'm stuck. I need a clojure punching bag. "LazySeq cannot be cast to java.lang.String" http://pastebin.com/WBHD4Gz0

5:03 nm got it i think

5:31 luxbock: studentrob: I'd use a cond to get rid of the nested if's in dist

5:32 studentrob: luxbock: ok thx

5:53 Are there any IDEs that let you step through clojure code? I'm using Light Table , which is handy, but it seems to only show values from the last loop iteration

5:59 luxbock: studentrob: Cursive has a Clojure debugger

5:59 studentrob: ok.. trying to figure out how to download that

5:59 luxbock: so does Emacs with CIDER these days, though you'll have to use the snapshot version

6:00 cfleming: studentrob: https://cursiveclojure.com/userguide/ has the details

6:05 studentrob: Thanks, got it

7:27 DerGuteMoritz: hello everybody, I was wondering whether there is a reason other than "nobody got around to it, yet" for the compiler to not to do arity checks on direct calls?

8:00 TimMc: Perhaps because vars can change? :-/

8:02 Bronsa: DerGuteMoritz: eastwood does that

8:04 TimMc: clojurebot: there's |an| eastwood for that

8:04 clojurebot: Ok.

8:10 crocket: I'm close to the end of braveclojure.com

8:10 braveclojure is a good material for a beginner, but it leaves me as a starter.

8:31 justin_smith: crocket: have you tried http://4clojure.com at all?

8:33 crocket: justin_smith, yes

9:55 DerGuteMoritz: TimMc: ah, mutability strikes again ... that would probably explain it

9:55 Bronsa: thanks, good tip

10:16 zerokarmaleft: crocket: if I were you, I'd think about building a very small project from scratch

10:41 kwladyka: i want use selmer and i want have templates in directory resources/view, i have to use something like (parser/set-resource-path! (clojure.java.io/resource "view")), but how can i add this change of path to work with lein ring server?

10:42 crocket, watch Clojure Inside Out, really :) i am also beginner and this video helped me more then anything else

10:43 crocket, after that do http://www.4clojure.com/problems - first i ignored it but later i found it is very usefull

10:43 justin_smith: kwladyka: a) how would lein ring server make this different? b) consider not using lein ring server unless you are deploying to a container like beanstalk

10:46 kwladyka: justin_smith, a) just i have to run this code to change the path, it is obviously how to do that with lein run in main function, but i don't know where to put this code when using lein ring server. b) so do you recommend use main and main-dev function and in main-dev function add middleware for ring to reaload code in each reload page instead of lein ring server?

10:47 justin_smith: kwladyka: I'd recommend using the setup with makes things most seamless to transition to production.

10:47 kwladyka: justin_smith, because the main reason why i use lein ring server is reloading sources during development

10:47 justin_smith: if you are not deploying to a container, better to use -main (launched from inside a repl) during development

10:47 wrap-reload is easy to add

Logging service provided by n01se.net