#clojure log - Dec 28 2011

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

1:06 quizme_: how do you select a subset of attributes from a sequence of hashes? {"id1" {:name "Bob" :age 21 :favorite-icecream "vanilla" } "id2" {:name "Fred" :age 22 :favorite-icecream "chocolate" } …..} I only want a sequence with :name and :age, but not :favorite-icecream.

1:07 can you do that with restructuring?

1:07 i mean destructuring

1:08 i want the result to look like {"id1" {:name "Bob" :age 21} "id2" {:name "Fred" :age 22}}

2:03 http://pastie.org/3083295

2:32 clj_newb: how does reload-all and reload differ?

2:34 how does reload-all and reload differ?

3:03 gf3: is there an idiomatic naming scheme for conversion functions? e.g. `namespace-to-filename`

3:31 clj_newb: are the values java.awt.event.KeyEvent/VK_A -> java.awt.event.KeyEvent/VK_Z guaranteed to be consecutive?

3:33 CmdrDats: clj_newb: I wouldn't count on it, no

3:42 kral: morning

3:43 CmdrDats: good morning :)

3:49 sgronblo2: Anyone know of any video presentations for writing web apps in clojure? I've already seen the one on ring on blip.tv.

4:08 clj_newb: is there a way to get a list of all the files in clojure.core? I want to answer questions like: "what function will tell me if X is a substring of Y"

4:08 s/files/functions/

4:12 jakeskik: clj_newb: http://clojuredocs.org/quickref/Clojure%20Core

4:29 clj_newb: jakeskik: thanks

4:31 why does every? have a ?; but some does not have a ? ?

4:34 pyrtsa: some doesn't in general return true or false but the first truey item it finds.

4:35 clj_newb: pyrtsa: makes sense now; thanks!

5:31 when an assertion fails; waht is thrown/generated?

5:32 I'm writing my own assertion-like macro (the default asertion is not expressive enough, even w/ its msg argument); and I want it to generate the same runtime objects as asert does

6:42 CmdrDats: anybody know of a site that one can automatically upload your library code docs and samples to when you do a lein build (similar to clojars, but for documentation)?

6:52 clj_newb: is there a builtin for converting lists/vectors into maps?

6:52 inquiring minds want to know :-)

6:56 CmdrDats: if your vector is in the format [key value key value] , you can just (apply hash-map myvector)

6:57 clj_newb: whoa

6:57 cool

6:58 dumb question: what if it's in the form of [ [k1 v1] [k2 v2] [k3 v3] ... ] ?

7:00 CmdrDats: ##(apply merge [[:k1 1] [:k2 2]])

7:00 lazybot: ⇒ [:k1 1 [:k2 2]]

7:00 CmdrDats: hmm, no

7:01 clj_newb: i want somethign liek flatten

7:01 but only 1 level

7:01 CmdrDats: ##(apply hash-map (flatten [[:k1 1] [:k2 2]]))

7:01 lazybot: ⇒ {:k1 1, :k2 2}

7:01 clj_newb: ##(flatten [ [ [ 1 2] 3 ] ])

7:01 lazybot: ⇒ (1 2 3)

7:01 clj_newb: this is bad, as I do have nested vectors

7:01 CmdrDats: ah

7:03 ##(apply into {} [[:k1 1] [:k2 2]])

7:03 lazybot: clojure.lang.ArityException: Wrong number of args (3) passed to: core$into

7:04 CmdrDats: ##(into {} [[:k1 1] [:k2 2]])

7:04 lazybot: ⇒ {:k1 1, :k2 2}

7:04 CmdrDats: that works :P

7:04 ##(into {} [[:k1 [:epic :vector]] [:k2 "simple"]])

7:04 lazybot: ⇒ {:k1 [:epic :vector], :k2 "simple"}

7:05 CmdrDats: (i always forget about into for some reason)

7:08 clj_newb: ##(doc into)

7:08 lazybot: ⇒ "([to from]); Returns a new coll consisting of to-coll with all of the items of from-coll conjoined."

7:08 clj_newb: brilliant; thanks!

7:13 CmdrDats: cool :) anytime

7:19 Somelauw: Is there ever any difference between merge and conj? They seem to behave exactly the same.

7:21 cemerick: Somelauw: For maps, no, but I'd classify that as an implementation detail you shouldn't rely upon.

7:22 Somelauw: When should I favor merge over conj?

7:29 cemerick: Somelauw: per the docs of `merge`, it should be used when combining maps.

7:36 Somelauw: So conj shouldn't be used when combining maps? Or should conj only be used when adding a single pair of key value.

7:46 zawzey: Hi, trying to download with clojurescript. but having lots of problems trying to get the sample code to run

7:48 https://gist.github.com/1527832

7:49 cemerick: Somelauw: IMO, no, conj should only be used to add an entry to a map; the fact that it merges maps as well is likely vestigial.

7:49 http://groups.google.com/group/clojure/browse_frm/thread/e499d7d184aba772

8:19 Somelauw: thanks

9:27 fbru02: Hi all, this must be a stupid question : if I have a closure over a function "foo" let's say (def bar (foo 2)) : is there a way having the var #'bar to get '(foo 2)

9:28 ?

9:29 CmdrDats: fbru02: I doubt there is a way to do that as (foo 2) would get evaluated when you (def bar …)?

9:30 you could (def bar `(foo 2)) and then you can get the actual closure function via (eval bar) maybe?

9:32 fbru02: CmdrDats: you a right , i think it gets evaluated right away to a IFn obj

9:34 CmdrDats: fbru02: ye, a bit difficult to reverse engineer from there :P (except maybe with some macro/metadata kung-fu)

9:35 fbru02: CmdrDats: yeah meaybe i put it in the metadata :) thanks ! :)

9:35 CmdrDats: fbru02: cool, glad i could help

10:17 TimMc: fbru02_: You could write a macro to do that.

10:18 fbru02_: TimMc: can't think how now :/

10:19 TimMc: Instead of def, you would use your macro.

10:20 I believe serializable-fn does exactly this, check it out.

10:21 fbru02_: TimMc: thanks will look into that :)

10:31 clj_newb: is there a clojure builtin to read all files in the current directory?

10:32 so it would return me a []

10:32 where for files, it stores a string, and for directories, it stores some object that I can recursively read

10:33 http://rosettacode.org/wiki/Walk_a_directory/Recursively#Clojure

10:33 victory

10:39 stuartsierra: clj_newb: file-seq is what you want

10:40 maybe

10:49 TimMc: clj_newb: slurp

10:53 miggyx: Hi guys, can anyone recommend a book on Clojure? I have some Amazon gift vouchers to use up and I want to make them count :)

10:55 antares_: miggyx: the joy of clojure is my personal favorite but it is not for complete beginners. Clojure Programming from O'Reilly (not in print yet, AFAIK) and Practical Clojure are also good.

10:55 miggyx: Programming Clojure 1st edition from PragProg is pretty outdated, 2nd edition I haven't read yet

10:55 miggyx: antares_: by complete beginners, do you mean to functional programming in general or specifically clojure?

10:56 antares_: miggyx: a little bit of both :) if you are well versed in multiple different languages, then you probably should go with The Joy of Clojure

10:56 miggyx: antares_: sounds like a plan - thanks :)

11:03 antares_: order placed :)

11:05 antares_: miggyx: I hope you enjoy it :)

11:06 miggyx: antares_: me too - always keen to stretch the mind :)

11:14 tscheibl: was sinf WMS, LCNS und MOPS?

11:14 oops sorry... wrong window

11:57 ambrosebs: what does with-loading-context do, and why is it necessary to wrap the body of each `ns` form with it?

12:07 I see it has something to do with classloaders, but whats the diff between (with-loading-context (require ...)) and (require ....)

12:27 clj_newb: is ther esime java lib I can import; which will give me one of those "choose a file: dialogs" that can navigagte the file system (and return to clojure the filename)

12:28 Is there some java lib I can import which will give me one of those "choose a file: dialogs" that can navigagte the file system (and return to clojure the filename that the user has chosen)? Thanks!

12:29 ldh: clj_newb: I've used seesaw (https://github.com/daveray/seesaw) to do Swing stuff from Clojure

12:33 clj_newb: seesaw provides this?

12:33 i've just been using java interop via proxy

12:34 dabd_: The following code that uses http-agent https://gist.github.com/1528807 is not working. Could it be because of the shutdown-agents being called out of place? Why is the println in the handler function not showing anything in the console? thx

12:35 ldh: clj_newb: IIRC, seesaw provides a more clojure-y way to do the regular Swing stuff

12:45 tmciver: dabd_: It looks like file in your let binding is just a String; you're trying to call a java.io.File method (getCanonicalPath) on that String.

12:46 clj_newb: suppose I need to do real time java

12:46 i.e. have a timer ticking down to be accurate to teh seconds

12:46 what options do I need to pass to the jvm?

12:49 dabd_: tmciver: I also tried with File. but it does not work either

12:52 tmciver: dabd_: I'm not familiar with http.agent but I'm wondering if you have access to 'url' in your handler function.

12:53 dabd_: I suspect you may be able to get the uri through the agent that is passed in to your handler function.

14:22 amalloy: anyone have an opinion about writing (concat foo [bar]) vs `(~@foo ~bar) to add something to the end of a sequence?

14:24 duck1123: wouldn't it be less runtime for the latter?

14:24 not that it's going to make a whole lot of difference

14:26 Raynes: amalloy: I wouldn't beat you with a 2x4 if you did the former while I would if you did the latter.

14:27 amalloy: duck1123: no, they're the same

14:27 &'`(~@foo ~bar)

14:27 lazybot: ⇒ (clojure.core/seq (clojure.core/concat foo (clojure.core/list bar)))

14:27 Raynes: Except one of them looks like perljure.

14:28 duck1123: I would probably use the former if faced with that situation

14:36 TimMc: amalloy: Define snoc and no one will complain.

14:39 amalloy: ugh, snoc. that name always sounds insufferably "clever" to me

14:39 TimMc: How about (tacnoc [bar] foo)?

14:40 It doesn't have to be *called* snoc. How about append?

14:40 Heck, you could even take multiple seqs, and call it concat.

14:41 s/seqs/colls/

15:55 wingie: would you write a game with a functional programming style?

15:55 or is it better with oop?

15:55 TimMc: Sure, why not?

15:56 wingie: since we have objects like soldier, weapon, grenade, tank etc isn't oop more suitable and fits the mind/game?

15:56 TimMc: wingie: How is this not an object? {:type :character, :subtype :NPE, :health 30, :healthmax 100}

15:57 s/NPE/NPC/

15:58 amalloy: wingie: since you have functions like "shoot", "eat", "travel", isn't fp more suitable?

15:58 wingie: amalloy: could have those as methods too

15:58 amalloy: obviously. my point is that you've framed the question in a way that assumes a particular answer, but it's easy to frame it differently

15:58 wingie: TimMc: won't we need inheritance for a game? eg. Corprol extends Soldier

15:59 Corpral

15:59 TimMc: wingie: Multimethods.

15:59 amalloy: Corporal

15:59 wingie: :)

15:59 why didn't i choose Lieutenant instead

15:59 amalloy: heh. i'd probably spell that one wrong. those big messes of vowels are confusing. bureau, really?

16:00 wingie: :)

16:00 english. hah!

16:00 are you guys using ClojureScript?

16:00 for writing frontend apps

16:01 amalloy: anyway, you're saying "i will need all these oop techniques to build a game", which is true if and only if you choose to do it in an oop language. it's not clear what you hope to get from asking your question

16:01 TimMc: wingie: So, I think the question you were trying to ask is: Does a game require lots of mutation?

16:01 wingie: amalloy: just wanted to know if it would fit one's mind using a FP lang to code a game

16:01 since OOP was kinda targeting systems like that

16:02 or if OOP would be a better choice in some areas, and FP in others

16:02 TimMc: by mutation you mean state changes?

16:03 amalloy: heh. you definitely need mutation if you're playing zerg, am i right?

16:04 wingie: yeah

16:04 how did you know im playing Starcraft =)

16:04 and Zerg

16:07 guns: I am trying to run Marginalia over Noir, and I get this error: "Map literal must contain an even number of forms" The stack trace:

16:07 https://gist.github.com/1529739

16:07 How do I go about debugging this?

16:08 TimMc: guns: Can you generate docs for just one file at a time?

16:08 guns: TimMc: You can pass paths to Marginalia?

16:08 okay I will try

16:08 TimMc: guns: dunno

16:09 gf3: is there an idiomatic naming scheme for conversion functions? e.g. `namespace-to-filename`, etc...

16:09 TimMc: I've used foo->bar occasionally.

16:10 gf3: TimMc: good call, thank you

16:22 mcrittenden: given a 3x3 multi-dimensional vector, I need to figure out if ANY of the values are numbers and return true if so, otherwise false. any hints on the best way to do this?

16:24 TimMc: &(some number? (apply concat (apply concat '[[[a b] [c]] [[d]]])))

16:24 lazybot: ⇒ nil

16:24 TimMc: &(some number? (apply concat (apply concat '[[[a b] [9]] [[d]]])))

16:24 lazybot: ⇒ true

16:25 TimMc: mcrittenden: Wait, is it 3-dimensional, or n-dimensional but always 3 on a side?

16:25 wingie: can't it be said that functional programming and oop is different abstraction layers .. fp is low level (micro) and oop is an higher abstraction (macro). oop is using fp in the same way objects in this world is bound by the law of nature. so its just a matter of what level you wanna work on? And a stateful object (human) is not a function that runs and exits .. but runs and never exits (til its

16:25 destroyed) why it never leaves its state and thus is stateful. Thoughts?

16:26 mcrittenden: TimMc it will always be [[val val val][val val val][val val val]]

16:26 TimMc: mcrittenden: Yeah, then the code above will work.

16:26 amalloy: (first (for [xs matrix, x xs, :when (number? x)] x))

16:26 finds you the first number, as a bonus

16:27 mcrittenden: is one preferred over the other? amalloy TimMc

16:28 amalloy: i think most people prefer TimMc to amalloy. as for the code, write whatever you like

16:28 TimMc: haha

16:28 mcrittenden: haha

16:28 thanks a ton guys

16:28 Raynes: I don't always talk to programmers, but when I do, I prefer amalloy.

16:28 TimMc: mcrittenden: I like amalloy's solution better, for the record -- but maybe with better binding names.

16:28 Raynes: Keep hacking my friends.

16:28 amalloy: tbh though i hate the apply concat, personally. i'd write either that for, or possibly (some #(some number? %) matrix)

16:29 * TimMc hacks Raynes' friends

16:30 mdeboard: TimMc: lol

16:30 Keep drinking my beer.

16:33 TimMc: wingie: oop and fp are at the same level -- they're just different ways of modeling process and state.

16:33 wingie: and they're not incompatible, either

16:41 wingie: TimMc: if everything is pure functions without side effects, how can a "person" be stateful?

16:42 hroarke: wingie: Imagine a top-level game loop function like (defn update-world [timestamp world input] ...) that returns a new world.

16:42 update-world can be pure, and you're still updating state.

16:43 TimMc: wingie: Why do you think there's any relationship between computers and the real world?

16:44 wingie: TimMc: since FP reminds me about math so Im trying to figure it all out

16:45 Raynes: (defn make-blue [person color] (assoc-in person [:hair :color] "blue"))

16:46 licenser: Raynes: that is wrong: (defn make-blue [person] (update-in person [:blood-alcohol] inc)) ^^

16:46 wingie: could someone write that in javascript =)

16:47 licenser: it is in javascript :P with cljs

16:48 wingie: do we have a compiler bot? =)

16:48 Raynes: &(+ 3 3)

16:48 lazybot: ⇒ 6

16:48 Raynes: We have two, actually.

16:48 ,(+ 3 3)

16:49 clojurebot: 6

16:49 licenser: Rthat was your cue,

16:49 mono he means something like ,(cljs '(+ 3 3)) -> 3+3

16:49 TimMc: wingie: There's no bot here to compile CLJS , no.

16:50 Raynes: I assumed he wasn't talking about cljs.

16:50 licenser: I wonder why is the cljs compiler so unbelievable slow?

16:51 TimMc: wingie: And I'm working on a try-cljs with some other folks, but it is kind of broken-ish.

16:51 Raynes: Yeah, it uses hiccup! It can't possibly work with hiccup.

16:51 wingie: TimMc: yeah .. didn't get the impression it was solid

16:51 Raynes: ~guards

16:51 clojurebot: SEIZE HIM!

16:51 TimMc: wingie: I should really put up a warning on that page.

16:53 hroarke: So, core.logic is pretty close to magic.

16:53 But, a little under-documented...

16:54 Is there any way to stream out relations and their facts, so I can save them persistently?

16:54 amalloy: licenser: it has to compile all of clojure.core twice in order to decide (+ 1 1) is 1+1, which i assume causes most of the dealy

16:55 TimMc: (+ 1 2) is instantaneous on my craptop.

16:55 clojurebot: 3

16:55 TimMc: Thanks, clojurebot.

16:56 licenser: amalloy: oi why twice/

16:57 amalloy: once to get the compiler itself going (since it's written in clojure), and then again to compile the cljs you gave it

16:57 (i realize it doesn't have to do the first step if you have a persistent compiler up)

16:57 (or even the second, probably)

16:58 emezeske: yeah, the only way to go with cljs is a persistent compiler

16:58 I have one that watches my cljs dir for changes, and it rebuilds everything in a fraction of a second

16:59 licenser: ^^ I see

16:59 emezeske: cljs-watch?

16:59 emezeske: licenser: nah, I rolled my own for some reason

17:00 licenser: ^^

17:00 is it better? :P

17:01 emezeske: yeah, I think maybe

17:01 licenser: is it on github (or alternatives)? ^^

17:01 emezeske: not yet.. I guess if you want to see it I could throw it up there real quick without any packaging

17:01 clojurebot: Huh?

17:02 licenser: emezeske: well if it is better then cljs-watch I'd love to see it since I am using clojurescript on one of my projects ^^ that is if you won't mind - I guess others might like that too

17:03 TimMc: I'm curious how deep you had to go into the layers of the compiler to do that.

17:03 emezeske: licenser: gimme a few, I'll put a rough copy on github. I'm not sure if it's better than cljs-watch, but maybe you can tell me!

17:04 licenser: emezeske: take all the time you need I really appreciate it :)

17:05 emezeske: licenser: I actually have a bunch of cljs I want to put up eventually. I have a framework for sharing code between clj and cljs

17:05 licenser: neat

17:05 so I don't use clojure on the server side so I won't end up using that right away ^^

17:06 emezeske: ah, yeah, interesting

17:07 licenser: so cljs+json works great as a client only thing

17:07 emezeske: yeah I was doing that for a while, was nice

17:07 I do use clj on the server side though, so I switched to just shuffling clojure expressions back and forth :)

17:09 licenser: emezeske: *nods* that is nice too ^^

17:15 darrint: I'm having trouble figuring out the state of the art for handling errors. I did (assert (= 200 statusCode)) which bails but doesn't show me what the code actually was. Any guidance?

17:15 I'd like to pack more info into my exception if I fail.

17:16 TimMc: &(doc assert)

17:16 lazybot: ⇒ "Macro ([x] [x message]); Evaluates expr and throws an exception if it does not evaluate to logical true."

17:16 TimMc: You could have a message that includes the info.

17:18 darrint: oh kay. I'm an an idiot. Thanks TimMc.

17:21 amalloy: TimMc: you should go into neurosurgery. irate patients: "I'm an idiot now. Thanks, TimMc.

17:25 emezeske: licenser: super-ultra-rough version up at https://github.com/emezeske/cljs-autobuild

17:26 licenser: I'm sure it's broken; I ripped it out of my private repo

17:26 licenser: emezeske: thanks :) I'll have a look at it :)

17:27 TimMc: emezeske: I see clojure.contrib in there...

17:27 Is that the 1.3-compat version?

17:28 emezeske: I'm not actually sure how that works in my project. I think I don't explicitly depend on it, and some other dep I pull in does...

17:29 The project.clj is probably very wrong, I just sort of tacked it in there

17:34 licenser: emezeske: it crashes with 'Could not locate clojure/contrib/command_line__init.class or clojure/contrib/command_line.clj'

17:35 emezeske: hmm, I guess it needs to depend on some clojure.contrib jar

17:36 licenser: clojure.tools.cli is supposed to replace c.c.command_line

17:36 emezeske: ahh

17:37 so maybe add [org.clojure/tools.cli "0.2.1"] to the :dependencies?

17:37 licenser: probably will need to change some code to :use it instead of c.c

17:38 Raynes: tools.cli has an entirely different API.

17:38 It isn't a drop-in replacement.

17:38 TimMc: emezeske: I guess the parts of contrib you are using are 1.3 compatible.

17:39 licenser: sneaky sneaky

17:39 emezeske: Raynes: is tools.cli meant to fully replace contrib.command-line?

17:39 Raynes: Yes.

17:39 emezeske: Hmm, guess I should port it then

17:41 licenser: looking at it it does not look too complicated

17:46 emezeske: yeah, should just take a few

17:49 * licenser will leave his hands of it so there aren't mixups :P

17:53 emezeske: licenser: I changed it to use the new cli

17:53 * licenser pulls

17:57 licenser: emezeske: looks good :)

17:58 emezeske: licenser: thanks for testing it!

17:58 now that it's up, I think I might add some features

17:58 like an option to find *.cljs files automatically

17:58 licenser: emezeske: thanks for setting it up :) now I'm trying out if it actually compiles stuff :P

17:59 emezeske: awesome

17:59 licenser: not bad it seems to compile now lets see if the output makes sense

18:00 lets see lets see :)

18:00 emezeske: gogo!

18:01 licenser: lets fire up the erlang server ^^

18:01 gf3: if anyone has a moment to help me out, I'm having an issue using the second argument in clojail's sandbox function to pass in some bindings

18:01 emezeske: whoa, you are erlang on the backend?

18:02 licenser: emezeske: yap :)

18:02 gf3: whenever I try to bind #'doc I get the following error "Unable to resolve var: doc in this context"

18:02 emezeske: licenser: now that's a unique stack :P

18:02 licenser: emezeske: it is a quite excellent one ^^

18:02 amalloy: gf3: does #'doc work in isolation?

18:02 licenser: they are a good fit in my eyes

18:02 emezeske: I can believe it

18:03 gf3: amalloy: in the context of the sandbox or the runner?

18:03 amalloy: i'd guess the runner

18:03 gf3: amalloy: no

18:03 amalloy: well then

18:03 gf3: amalloy: actually, in neither

18:03 Raynes: What are you trying to do, precisely?

18:04 amalloy: he just needs to get his namespace forms right. doc in in clojure.repl

18:04 gf3: Raynes: I just want to use a different `doc` in the sandbox for prettier output

18:04 licenser: emezeske: if you ever want to sneak a peak it's up on gitup

18:04 hub

18:04 Raynes: Probably don't need to rebind doc.

18:04 gf3: Raynes / amalloy: I wrote a macro to clean up the standard doc output

18:04 Raynes: It doesn't exist at all in clojure.core in 1.3.

18:04 So, you can just pass your code in the :init option.

18:05 emezeske: licenser: yeah, link it! I'm curious

18:06 licenser: emezeske https://github.com/Licenser/erlpic

18:06 Raynes: gf3: https://github.com/flatland/lazybot/blob/develop/src/lazybot/plugins/clojure.clj#L36

18:06 gf3: Raynes: hmm, let me try that again, thank you

18:07 licenser: and emezeske it compiles like a charm :)

18:07 emezeske: licenser: that's great.

18:07 * Raynes notes that that code still hasn't graduated Special Ed.

18:08 licenser: I agree ^^ thanks mate

18:08 Raynes: gf3: I'm also curious as to what you're using clojail for. :>

18:08 Always fun to hear what people are doing with it.

18:09 gf3: Raynes: amazing, thank you, I'm not sure why I didn't try that initially since I was using :init to (use) other libs

18:09 Raynes: I'm sure for the same reason everyone else uses clojail, IRC bots

18:09 licenser: emezeske: if you look at the erlang stuff, feel free to poke me, it is horribly (mostly not at all) documented and a rather complex system ^^ but I'll glady explain things

18:09 Raynes: Haha.

18:09 licenser: gf3: there is also try-clojure :P

18:09 Raynes: Well, I *did* use it for tryclj.

18:10 emezeske: licenser: got a link that explains what EPIC is?

18:10 gf3: Raynes: I saw that, your source was actually very helpful to me

18:10 licenser: emezeske: not really no, the whole source material is not open sourced yet sadly but I probably should do that at some point. In short words it is a game engine for turn based combat

18:11 * licenser has this crazy dream to build the ultimate web game :P

18:11 gf3: actually, Raynes, since I have you here, what is the purpose of this? https://github.com/Raynes/tryclojure/blob/master/src/tryclojure/models/eval.clj#L27-28

18:12 licenser: EPIC is the part of the game that handles combat logic, including stuff like custom AI scripts and fun like that ^^

18:12 Raynes: gf3: It is an extra precaution against keeping defs from residing in memory.

18:12 I'm not sure it is actually necessary, but it doesn't hurt.

18:12 gf3: ahh neat, thanks

18:13 emezeske: licenser: sounds like a fun project!

18:13 licenser: emezeske: it is started it with a few friends like 4 years back, they all ditched out over time sadly but I hate giving up since I love the idea behind it :P

18:14 emezeske: :)

18:16 licenser: sadly I am stuck now at the GUI - and my gui-guy (I love the word) ditched me too but I hate guis so much :P

18:17 emezeske: bleh

18:18 licenser: emezeske: exactly, so I hope that cljs gets me around the tight spot there, since I am way more inclined to write clojure then javascript :P

18:21 emezeske: licenser: yeah, I hear that!

18:24 licenser: so I still struggle a lot with it, I rather set up a network of dedicated erlang servers then write a webpage :P

18:27 but one day, like 2020 I will have a game :P

18:28 emezeske: w00t!

18:29 licenser: so then likely all the technique will be outdated :P

18:29 emezeske: your game will just be retro

18:30 licenser: heh outdated not retro

18:38 gf3: hey Raynes, you know what would be cool, is if you could link to tryclj.com with some code pre-filled, a la coffeescript

18:39 http://jashkenas.github.com/coffee-script/#try:alert%20%22Hey%20there%2C%20Raynes!%22

18:40 licenser: emezeske: I'd have one request for your cljs-autobuild, show the time it used to build the file :)

18:40 emezeske: licenser: yeah, I want that too.

18:41 licenser: I seem to remember running into some difficulty with that; maybe I'll revisit it

18:41 licenser: also a DWIM mode would be nice so I could write (ns evil.gui) (make-my-damn-gui)

18:43 emezeske: licenser: hmm, I'm not sure what you mean. just so you could compile via a REPL?

18:44 licenser: emezeske: DWIM is Do What I Mean, it is a joke mate :)

18:45 emezeske: hahaha

18:45 I read "make" in (make-my-damn-gui) as "compile" :P

18:45 as opposed to actually make :)

18:46 licenser: mono, I meant make as in do it for me :P

18:46 shoud slap a sudo in front of that perhaps

18:46 emezeske: haha

18:49 licenser: *ponders* perhaps winning in the lottery and can buy a gui-guy is a more realistic goal o.O

19:12 emezeske: thanks mate you just gave me the energy to tackle the thing again :P

19:12 gf3: hmm, I wonder why strings weren't made collections...

19:12 licenser: gf3: probably for performance reasons

19:13 emezeske: licenser: glad to hear it!

19:14 licenser: just pushed my changes to print the time taken to compile

19:14 gf3: licenser: ahh, likely

19:14 tmciver: gf3: it can be ##(seq "Strings")

19:14 lazybot: ⇒ (\S \t \r \i \n \g \s)

19:14 licenser: neat neat :D

19:14 gf3: tmciver: yes, they're seq-able, but they aren't collections

19:15 e.g.: ##(contains? "abc" "b")

19:15 lazybot: ⇒ false

19:15 tmciver: gf3: curious, what do you need that you can't get with seq?

19:15 ahh

19:15 gf3: tmciver: of course it's all possible, I just thought it'd be interesting to use the collection goodies

19:16 tmciver: gf3: Yes, I see.

19:19 amalloy: augh. that usage of contains? would be wrong with seqs too

19:20 gf3: also another cool feature could be strings as functions of their chars

19:20 actually, on that note, it seems inconsistent that vectors and hashmaps are functions of their members, but not lists

19:21 amalloy: it'd be cool if lots of things were functions, but it's never going to happen on the jvm. invoking functions needs to be fast, which means it needs to be a host-level thing like calling an interface method, which means you can't make built-in host objects support it

19:22 gf3: amalloy: do lists map to built-ins?

19:22 amalloy: no, that was a point about strings

19:22 gf3: ahh

19:22 amalloy: (and clojure chooses to use java.lang.String for strings, instead of inventing a clojure.lang.String, to make interop seamless. jruby has these sorts of features, but a lot more plumbing/busywork about mapping back and forth to real-java)

19:23 if lists were functions of their indices, you would be tempted to use them in inefficient ways for no reason

19:24 tmciver: gf3: I too dumb to make this work in any case: ##(coll? (seq "abc"))

19:24 lazybot: ⇒ true

19:24 tmciver: but ##(contains? (seq "abc") \a)

19:24 lazybot: ⇒ false

19:25 tmciver: what's wrong?

19:25 amalloy: contains?

19:25 clojurebot: contains?

19:25 clojurebot: No entiendo

19:26 amalloy: wth

19:26 ~contains?

19:26 clojurebot: It's greek to me.

19:26 amalloy: who deleted that factoid?

19:27 tmciver: contains? is greek to me too. ;)

19:27 amalloy: clojurebot: contains? |is| for checking whether a collection has a value for a given key. If you want to find out whether a value exists in a Collection (in linear time!), use clojure.core/some or the Java method .contains

19:27 clojurebot: Ik begrijp

19:27 gf3: ahh

19:28 tmciver: ,(.contains "abc" "a")

19:28 clojurebot: true

19:29 tmciver: would that be an idiomatic approach then?

19:29 using a character doesn't work: ##(.contains "abc" \a)

19:29 lazybot: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.CharSequence

19:30 technomancy: there comes a time for every Clojure beginner when he thinks to himself "wait, vectors, maps, and sets are all functions... why aren't lists functions?" ... and then he realizes it doesn't make any sense

19:30 regexes, on the other hand...!

19:32 amalloy: haha

19:32 technomancy: also doesn't make sense, just for different reasons

19:33 technomancy: that's just, like, your opinion, man.

19:37 amalloy: technomancy: if i were a better man, i'd have a response cleverly crafted to sound like that Ocean Marketing guy

19:43 emezeske: I'd like to create a leiningen plugin that requires Clojure 1.3, which as I've read, is supported by lein 2.0. Does anyone know whether lein 2.0 is generally usable at this time?

19:44 technomancy: emezeske: it's a long way out

19:45 emezeske: technomancy: thanks!

19:45 technomancy: emezeske: there's a trick in doc/PLUGINS.md that explains how to use 1.3 from lein 1.x; you basically create a dummy project to eval inside

19:45 emezeske: technomancy: aha! that's exactly what I need.

19:47 darq: hello. i have a tree and i would like to output the path to the leafs using clojure.walk .. is it possible with clojure.walk?

19:48 darrint: Do I need to restart emacs/slime if I add deps to project.clj?

19:50 darq: You have to start a new swank server (lein swank) ... so yes.. you must reconnect

19:50 amalloy: the full path to each leaf? it's pretty easy without clojure.walk

19:50 darq: yes . to each leaf

19:54 technomancy: darrint: yes, unless you use https://github.com/cemerick/pomegranate

19:55 amalloy: darq: sketch at https://gist.github.com/1530833

19:57 you can write something similar if you want your tree and nodes to just be sequences, by testing coll? to see if it's a sequence. but in that case interior nodes can't have values, so the path is not very interesting

19:59 darq: thx.

19:59 TimMc: tmciver: The idiomatic approach would be ##(not= -1 (.indexOf "abc" "b"))

19:59 lazybot: ⇒ true

20:00 amalloy: &(.contains "abc" "b")

20:00 lazybot: ⇒ true

20:00 tmciver: TimMc: why that and not .contains?

20:01 amalloy: i suspect TimMc's point was that .indexOf has an overload for Character, but he forgot to actually do that

20:01 tmciver: ,(not= -1 (.indexOf "abc" \b))

20:01 clojurebot: #<IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: indexOf for class java.lang.String>

20:01 amalloy: welp, i lose again

20:02 $javadoc String indexOf

20:02 lazybot: http://download.oracle.com/javase/6/docs/api/java/lang/String.html#indexOf(int)

20:02 TimMc: wait wait wait .contains works?

20:02 tmciver: TimMc: nice of you to join the conversation. :)

20:02 amalloy: of course, why wouldn't it?

20:03 TimMc: Ah, I missed the bot responses.

20:03 amalloy: I guess because everything since Java v1.3 is new to me.

20:04 amalloy: TimMc: funny you should mention that, i was just reading through old javadocs to see if indexOf always took an int rather than a char

20:04 TimMc: I last used Java in 2001 and picked it up again in about 2007.

20:04 amalloy: but .contains has worked for substrings since at least 1.1

20:04 TimMc: amalloy: String#contains says "since 1.5"

20:04 amalloy: man, really?

20:05 my memory has betrayed me

20:05 TimMc: I wonder if that refers to a widening from String -> CharSequence.

20:05 Nope, not there in 1.4.2.

20:05 weavejester: I remember using Java 1.4 some years ago and being annoyed by String#contains

20:06 amalloy: weavejester: it allegedly wasn't there in 1.4, but i remember it too

20:06 weavejester: amalloy: No, I mean I remember it not being there.

20:06 amalloy: It only worked with chars

20:07 * amalloy <=== all alone, imagining code that never existed

20:08 TimMc: weavejester: That doesn't work now, does it?

20:08 &(.contains "abc" \b)

20:08 lazybot: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.CharSequence

20:09 amalloy: TimMc: it does, if you write in java, because 'a' will be upcast to an int

20:09 wait, that's probably not true either

20:10 weavejester: Hm... I've just checked and .contains didn't exist in 1.4

20:10 Maybe I'm thinking of indexOf or something...

20:10 TimMc: yep

20:10 amalloy: just tested, java does upcast characters to ints

20:10 TimMc: correct

20:11 Oh, wild -- I never noticed that indexOf can take an int.

20:11 What are the semantics of that?

20:12 &Character/MAX_VALUE

20:12 lazybot: ⇒ \￿

20:13 TimMc: &(.indexOf "abc" (inc Character/MAX_VALUE))

20:13 lazybot: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number

20:13 TimMc: &(.indexOf "abc" (int (inc Character/MAX_VALUE)))

20:13 lazybot: java.lang.ClassCastException: java.lang.Character cannot be cast to java.lang.Number

20:14 TimMc: &(int \b) ; that's annoying

20:14 lazybot: ⇒ 98

20:14 TimMc: Oh wait, it's inc that's complaining.

20:15 &(.indexOf "abc" (inc (int Character/MAX_VALUE))) ; no complaints

20:15 lazybot: ⇒ -1

20:15 gf3: bah, I keep expecting ('(a b c) 'a) to work like (some #(= % 'a) '(a b c))

20:16 amalloy: TimMc: it's to account for the fact that unicode characters no longer fit in a java char

20:16 weavejester: Oh, it was .replace I was thinking of.

20:16 In 1.4 it was only for chars

20:16 In 1.5 and above it's overloaded for CharSequences as well.

20:17 TimMc: amalloy: They never did.

20:17 amalloy: so if you cast a character to an int, it looks up that character like a one-character string. if it's an int larger than a character, it goes into the "be careful, characters might be really large" mode

20:17 weavejester: gf3: ('#{a b c} 'a) does :)

20:18 amalloy: TimMc: really? i was under the impression that they picked the size of char in order to fit all standardized characters of the time

20:18 gf3: weavejester: amazing, thank you

20:18 weavejester: sets can only contain unique members though, correct?

20:18 TimMc: amalloy: I think surrogate pairs have been around since forever.

20:18 Maybe I'm wrong!

20:18 weavejester: gf3: Yes, and they're unordered

20:19 gf3: But if you have a list, and want to check it for something...

20:19 gf3: Then sometimes you can just do ((set xs) x)

20:19 It works well in maps and things

20:20 By which I mean clojure.core/map, not hash-maps :)

20:20 gf3: weavejester: thanks for the tip, I'll be using that

20:20 amalloy: (some #{x} xs) is surely nicer

20:23 technomancy: in 1.2 sets can contain duplicate numbers

20:23 if one is an Integer and one's a Long

20:23 gf3: technomancy: hax

20:24 TimMc: technomancy: I noticed that ##{(long 5) :a, (int 5) :a} throws now!

20:24 lazybot: java.lang.IllegalArgumentException: Duplicate key: 5

20:24 TimMc: So glad.

20:25 amalloy: "The Unicode standard has since been changed to allow for characters whose representation requires more than 16 bits."

20:26 That's Character in 1.5

20:27 amalloy: TimMc: so, that sounds like it means two bytes used to be enough, yeah?

20:27 TimMc: yep

20:28 I guess I should keep read the "History of Unicode" section in that book I have in my cubicle at work.

20:28 s/keep//

20:29 technomancy: TimMc: it still falls back to the broken behaviour if you use the Java methods, which is arguably correct since the interfaces require you to be wrong.

20:29 amalloy: technomancy: well, sets can already have duplicate elements, sorta: ##(let [o (reify Object (hashCode [this] (rand-int 1000)) (equals [this x] false))] (hash-set o o))

20:29 lazybot: ⇒ #{#<sandbox22696$eval25262$reify__25263 sandbox22696$eval25262$reify__25263@303> #<sandbox22696$eval25262$reify__25263 sandbox22696$eval25262$reify__25263@2d6>}

20:30 technomancy: heh

20:41 TimMc: Clearly, the Java devs should have made j.l.Character an enum. That would have solved it.

20:44 amalloy: TimMc: worked for the haskell booleans (i think? not sure if that was something they *did* do, or just something that would be easy)

20:47 xandrews: what do people use in place of the old clojure.contrib.repl-utils/show ?

20:48 TimMc: If it doesn't exist, that would be a nice little project.

20:51 amalloy: clojure.reflect, right?

20:52 &(require '[clojure.reflect :as refl])

20:52 lazybot: ⇒ nil

20:53 amalloy: &(keys (ns-publics 'clojure.reflect))

20:53 lazybot: java.lang.SecurityException: You tripped the alarm! ns-publics is bad!

20:54 amalloy: &(refl/reflect (java.util.Date.))

20:54 lazybot: ⇒ {:bases #{java.io.Serializable java.lang.Comparable java.lang.Object java.lang.Cloneable}, :flags #{:public}, :members #{#clojure.reflect.Constructor{:name java.util.Date, :declaring-class java.util.Date, :parameter-types [java.lang.String], :exception-types [], :f... https://gist.github.com/1531104

20:56 xandrews: wow. lots of info there. show just prints out the method names and argument types. I'll need to write something to make it a bit more readable. Thanks!

20:57 chipdude: &(refl/reflect (java.util.Date))

20:57 lazybot: java.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn

20:57 chipdude: &(refl/reflect java.util.Date)

20:57 lazybot: ⇒ {:bases #{java.io.Serializable java.lang.Comparable java.lang.Object java.lang.Cloneable}, :flags #{:public}, :members #{#clojure.reflect.Constructor{:name java.util.Date, :declaring-class java.util.Date, :parameter-types [java.lang.String], :exception-types [], :f... https://gist.github.com/1531121

20:57 chipdude: k

21:16 aaelony: is this the right forum to ask a beginner's swank-clojure with Emacs question? I've finally decided to try emacs, have done lein deps with a project.clj containing swank-clojure as a dev dependency, have done M-x clojure-jack-in, and now I've got a simple (ns foo) expression that I'd like to send to the repl. C-x c-e gives me a backtrace, what do I need to do to get this to work?

21:18 amalloy: IME you have to C-c C-k the file it's in, to load the code

21:20 aaelony: thanks! that works :)

22:17 gf3: technomancy: ping

22:34 unlink: How do I interact with Java properties in clojure 1.3

22:34 ...now that clojure-contrib has been split up?

22:36 mindbender: unlink: what do you mean by Java properties

22:37 unlink: j.u.Properties

22:41 mindbender: unlink: I don't think you have to do anything special to use properties

22:41 from my repl I can do this without errors: (def prop-obj (doto (java.util.Properties.) (.putAll {"a" 1 "b" 2})))

22:41 unlink: mindbender: Ah, yes, I'd like to *parse* properties files.

22:42 mindbender: are you having any issues doing that?

22:44 amalloy: $javadoc java.util.Properties

22:44 lazybot: http://download.oracle.com/javase/6/docs/api/java/util/Properties.html

22:45 amalloy: observe the Properties#load method. give it an input stream, and your file is parsed

22:45 unlink: Basically, I'm looking for something like (defn load-properties [f] (doto (java.util.Properties.) (.load (clojure.java.io/reader f))))

22:46 like this (but not deprecated): http://richhickey.github.com/clojure-contrib/java-utils-api.html#clojure.contrib.java-utils/read-properties

22:46 lazybot: Nooooo, that's so out of date! Please see instead http://clojure.github.com/clojure-contrib/java-utils-api.html#clojure.contrib.java-utils/read-properties and try to stop linking to rich's repo.

22:47 amalloy: so...you know exactly what code you want, and you've already written it. tada, problem solved, you're done!

22:48 unlink: no, I was done after I complained about not being able to find it outside of clojure-contrib. My problem was a social one.

23:47 ldh: i'm struggling with getting vimclojure/nailgun to work (i suspect classpath issues). now i'm trying lein-nailgun, but when I add ["lein-nailgun" "0.1.0"] to my leiningen :dev-dependencies,

23:47 then do "lein deps" and then "lein" I get "Warning: problem requiring leiningen.hooks.classpath hook: java.lang.ExceptionInInitializerError (classpath.clj:1)"

23:47 problems persist until I delete the lein-nailgun dependencies from lib/dev

Logging service provided by n01se.net