#clojure log - Dec 04 2010

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

0:06 talios: Ok - now I'm even more confused. My fn works when called directly, but fails from within my deftype/defrecord. May as well go back to gen-class'ing I think. hrm.

0:07 * talios hits more docs

0:46 talios: hrm - it would seem deftype's don't automatically load namespaces. I think sticking with good ole genclass will do.

1:56 cky: talios: Hahaha, small world. :-P

1:56 talios: 'lo cky

1:56 long time :)

1:56 cky: Indeed. :-)

1:57 talios: where abouts are you based these days?

1:57 cky: Durham, NC. (Yes, I was bummed to not have heard about Clojure Conj until a month after the fact.)

1:58 I hope the next Clojure Conj will be in Durham again. I'd love to attend.

1:58 talios: bummer :( wish I could have gone as well. hopefully i'll get to the next one. not a cheap weekend away from Auckland tho :(

1:59 cky: Yeah, I know. :-)

1:59 talios: w00t - tests now fail due to non-implemented code, rather than cocked up code ;)

2:00 cky: :-P

2:02 Anyway, getting late here. Good seeing you again---I'm sure we'll chat some more. :-D

2:02 talios: finally getting around to looking into migrating the clojure-maven-plugin from java to clojure itself. been too long since I've done some actual clojure code tho - i'm all rusty :)

2:03 cky: Wow, you mentioned clojure and maven in the same sentence! I thought only chouser does that. :-P

2:03 talios: I'm the crazy fool who started the plugin :)

2:04 cky: My response was that as far as I can imagine, the one relation clojure and maven share is the letter "e". :-P

2:04 Hahaha, nice.

2:07 quile: that's the most smileys I've seen in an IRC chat room in a while.

2:09 harishtella: Anyone using (vim + screen/tmux ) to develop clojure?

2:14 talios: I have a smiley addition. I have for a long time.

2:26 mmm, is there a simple way to convert a seq into a java.util.List?

2:27 Raynes: I just thought of the most awesome name for a Clojure text editor.

2:27 sexteditor

2:28 I'm going to have to write a text editor for the sole purpose of using that name.

2:28 talios: heh

2:30 Raynes: &(java.util.LinkedList. '(1 2 3))

2:30 sexpbot: ⟹ #<LinkedList [1, 2, 3]>

2:30 Raynes: talios: Like that?

2:31 &(instance? java.util.List (java.util.LinkedList. '(1 2 3)))

2:31 sexpbot: ⟹ true

2:31 Raynes: j.u.List is an interface.

2:32 &(instance? java.util.List '(1 2 3))

2:32 sexpbot: ⟹ true

2:33 talios: doh - my defn is returning PersistentVector not PersistentList ( which is a j.u.List )

2:33 Raynes: &(instance? java.util.List [1 2 3])

2:33 sexpbot: ⟹ true

2:33 Raynes: sexpbot just disagreed.

2:33 &(type [1 2 3])

2:33 sexpbot: ⟹ clojure.lang.PersistentVector

2:34 hiredman: ,(supers (class []))

2:34 clojurebot: #{clojure.lang.Seqable clojure.lang.IEditableCollection clojure.lang.ILookup clojure.lang.Counted clojure.lang.Sequential java.io.Serializable clojure.lang.APersistentVector clojure.lang.IObj clojure...

2:34 hiredman: ,((supers (class [])) java.util.List)

2:34 clojurebot: java.util.List

2:34 Raynes: talios: ^

2:39 * talios finds his bug and decides to run off for doon.

2:39 talios: food even:)

2:40 Raynes: talios: Doon is even better.

2:42 mroessler: Trying to eliminate reflection here, but unsure how: (.withMaximumValue (.dayOfYear yearago))

2:42 my type hints dont' seem to get rid of the warning.

2:49 hiredman: mroessler: are you type hinting yearago?

2:50 mroessler: hiredman: Trying to, yes. Its a joda DateTime object.

2:50 hiredman: ^DateTime yearago

2:51 mroessler: hiredman: Exactly. I have (.withMaximumValue (.dayOfYear ^DateTime yearago)) but I still get a reflection warning. I was surprised.

2:51 hiredman: are you sure that is where you getting the warning?

2:52 mroessler: reference to field dayOfYear can't be resolved. reference to field withMaximum value can't be resolved.

2:53 am I hinting the wrong thing?

2:54 hiredman: dunno

2:54 mroessler: ok. Thanks!

4:22 tufflax: Why would I want to use a keyword with two colons? I know it got something to do with namespaces but I just don't understand why I need them or what they are good for. Can anyone shed some light on that for me?

4:57 LOPP: what's the idiomatic way of reporting and reacting to errors in clojure

5:42 fliebel: morning

5:47 Is there any way to automatically create getters on a record? so getSomething rather than (get :something)

5:50 LOPP: in what way

5:51 as java methods?

5:51 fliebel: yea

5:51 LOPP: or clojure fns named like that

5:51 fliebel: No, Java methods. I need to implement an interface that's only getters.

5:52 LOPP: would help if I actually knew how to implement interfaces in clojure :D:D:

5:53 fliebel: I think I can get a long way with destructuring and the applying to a reify…

5:53 LOPP: but generally you can get methods that need to be implemented by using java reflection

5:55 lucian_: fliebel: there's stuff about that http://clojure.org/java_interop

6:19 fliebel: Man, this is at least the 100th time I need to apply or thread to a macro.

6:20 LOPP: I don;t understand

6:22 fliebel: &(apply reify)

6:22 sexpbot: java.lang.Exception: Can't take value of a macro: #'clojure.core/reify

6:34 hoeck: fliebel: that makes no sense, macros run at compiletime, applying (= invoking with varargs) happens at runtime

6:34 fliebel: hoeck: I know that, but I keep comming up with situations where I have a seq of arguments for a macro.

6:34 hoeck: but you can write a macro and there do `(reify ~@args)

6:35 fliebel: Sure, but that is a last resort to me. I'm now on a different path.

6:38 hoeck: so you're writing a bean class generator and need to generate mutliple getFoo methods?

6:38 fliebel: bean?

6:38 clojurebot: don't forget, NetBeans is evil, and i want you to tell people that whenever they mention it

6:38 hoeck: to me, generating a list of specs and then doing (reify ~@method-specs) sounds reasonable

6:39 fliebel: hoeck: I figured half of them needs a small bit of extra modification, so I'll just write a deftype manually, it's not that much work with a decent editor.

6:40 hoeck: writing macros to replace a few lines of duplication is sometimes a big turing tarpit :)

6:42 fliebel: hoeck: Even if the code to generate the methods is longer than the getters?

6:45 hoeck: especially then

6:45 fliebel: wait. what's a turing tarpit?

6:48 hoeck: oh, my last definition was that this is something where you catch programmers in, doing useless stuff because you can

6:48 wikipedia disagrees with me :/

6:55 fliebel: hrm, can anyone tell me how getServletPath, getRealPath and getContextPath would translate from servlet lingo to ring/clojure?

7:00 charliekilo: fliebel: talke a look at https://github.com/alienscience/compojure-war-example/blob/master/src/context.clj

7:00 fliebel: thanks

7:05 Am I correct that the other ones are just webroot+uri?

7:10 mduerksen: hmm, destructuring of structs is not the same as with maps. example: (defn tst [{:keys [a b]:or {a 1}}] (println a b)) (tst {}) -> 1 nil. this works as expected. when i do the "same" with a struct...

7:11 Raynes: My Das keyboard all of a sudden fritzed out. I'm going to miss that keyboard. It's going to be a long time before I can buy one.

7:11 mduerksen: (defstruct st :a :b) (tst (struct st)) -> nil nil

7:11 is that behavior intended?

7:17 hoeck: mduerksen: (struct st) -> {:a nil :b nil}

7:17 mduerksen: :a has a value, nil

7:17 so destructuring wont use the default you supplied

7:20 mduerksen: hmm, it seems to be the same when merging a struct with a map: (merge {:a 1} (struct st)) -> nil nil

7:20 bartj: is there an idiomatic way of iterating through a hash-map?

7:25 fliebel: Does this satisfy Enumeration<String>? (.elements (java.util.Vector. ["a" "b" "c"]))

7:26 bartj: or in other words:

7:27 I always tend to create a new map like this:

7:28 ,(time (zipmap (keys {:a 1 :b 2 :c 3}) (map #(* 10 %) (vals {:a 1 :b 2 :c 3}))))

7:28 clojurebot: "Elapsed time: 0.592 msecs"

7:28 {:c 30, :b 20, :a 10}

7:31 mduerksen: darn, got disconnected. a solution would be something like this: (merge-with #(if %1 %1 %2) {:a 1} (struct st)). but this is ugly, is there a more elegant way?

7:36 fliebel: &(into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3}))

7:36 sexpbot: ⟹ {:a 10, :b 20, :c 30}

7:36 fliebel: bartj: ^^

7:38 _ato: another: (reduce (fn [m [k v]] (assoc m k (* 10 v))) {} {:a 1 :b 2 :c 3})

7:38 bartj: (time (into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3})))

7:38 ,(time (into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3})))

7:38 clojurebot: "Elapsed time: 0.816 msecs"

7:38 _ato: and also: clojure.contrib.generic.functor/fmap

7:38 clojurebot: {:a 10, :b 20, :c 30}

7:38 _ato: I tend to prefer the zipmap one myself in practice, it's usually more elegant, even if it does create more temporary objects

7:39 bartj: _ato, amazingly, its faster too

7:42 fliebel: Can anyone tell me why this returns java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class? https://gist.github.com/728155

7:42 bartj: _ato, the fmap solution is cool too

7:42 though I am a bit non-plussed asto why only the value of the map-entry gets passed

8:22 Lajla: So like

8:22 why doesn't map make a map.

8:23 I always wondered that

8:24 &(map #(* % %) [1 2 3 4 5])

8:24 sexpbot: ⟹ (1 4 9 16 25)

8:30 Lajla: &(map #(* % %) {:I 2 :worship 4 :his 5 :shadow})

8:30 sexpbot: java.lang.ArrayIndexOutOfBoundsException: 7

8:30 Lajla: &(map #(* % %) {:I 2 :worship 4 :his 5 :shadow 5})

8:30 sexpbot: java.lang.ClassCastException: clojure.lang.MapEntry cannot be cast to java.lang.Number

8:34 fliebel: (map type {:a 1 :b 2})

8:34 &(map type {:a 1 :b 2})

8:34 sexpbot: ⟹ (clojure.lang.MapEntry clojure.lang.MapEntry)

8:35 tscheibl: is there some function similar to 'filter' which does return let's say a vector instead of a lazy sequence which can accept side-effects in the predicate function

8:35 ?

8:36 fliebel: Lajla: So it returns MapEntries rather, which you can put back into a map if you want to.

8:36 LOPP: what the hell

8:36 of course it enumerates entries

8:36 just like java map

8:38 fliebel: &(doc val)

8:38 sexpbot: ⟹ "([e]); Returns the value in the map entry."

8:42 tscheibl: ..hmm.. will try reduce instead of filter

8:48 fliebel: I guess chouser was right… I'm not even touching FastCGI yet, and already seeing heisenbugs. :( I got a deftype that works fine when I paste it in the repl, but gives a classcastexception when I require it. There is nothing but the deftype and a ns declaration in the file.

8:52 LOPP: heisenbugs?

8:53 fliebel: LOPP: I only learnt about them yesterday… Bugs that dissapear as soon as you try to look at them.

8:54 LOPP: well in this case they just don't appear in repl

8:54 so you need a debugger or something]

8:54 fliebel: right

8:54 LOPP: or so I'm guessing

8:57 fliebel: LOPP: You can think of any case why the repl might work and the code not?

8:57 LOPP: nope, I'm not knowledgeable about clojure internals

8:58 tscheibl: ..ok.. 'reduce' saved my day :)

8:58 LOPP: clojure is relatively new so it's bound to have bugs

8:59 lol I can't even find a good eclipse plugin for it

9:01 I wonder what cemerick is using though

9:02 lucian: LOPP: i doubt a lot of lisp people are using eclipse

9:04 fliebel: LOPP: I think it was because my name used hyphens?

9:05 LOPP: really?

9:05 that's just silly

9:05 I saw cemerick use eclipse on one of his videos

9:06 and I was wondering what he was using

9:06 fliebel: It seemingly took my camelcased name, and turned into a hyphenized name. I can't believe my own eyes...

9:06 LOPP: I used some eclipse plugin advertised on clojure.org and it worked poorly/didn't work

9:06 fliebel: LOPP: Might be ccw?

9:06 pdk`: lisp folk seem to be mostly emacs evangeists

9:07 LOPP: yeah I'm using clojure box which is basically emacs

9:07 but I'm used to eclipse

9:07 but that eclipse plugin didn't support autocomplete or anything good

9:07 wait fliebel, you defined the type as a camel case name

9:08 ?

9:08 fliebel: well, I don't know what I'm doing, but Clojure is giving me crap back.

9:09 I did a deftype using a camelcased name, and it's just not there when I require it.

9:10 bartj: are the values returned by keys and vals always in the correct sequence order of the key,val of the map?

9:11 fliebel: bartj: Yes, I believe so.

9:11 bartj: fliebel, is there *any way* there could be a goof-up ? I too am not 100% sure.

9:12 fliebel: bartj: I'm 100% sure someone who know said they are guaranteed to be in hte right order.

9:13 bartj: fliebel, ok, thanks!

9:15 fliebel: technomancy: fliebel: keys and vals is guaranteed to always be consistently ordered when called on the same map

9:15 bartj: ^^

9:18 mduerksen: bartj, fliebel: the same question came into my mind recently. i'm still not sure it is a good idea to depend on the consistent ordering. even if the current implementation guarantees this, i would argue that it isn't guaranteed idiomatically. after all, a map is not necessarily ordered.

9:20 bartj: mduerksen, thank you. yes, depending on it does seem flaky

9:21 fliebel: I don't agree about that. There is not something like a random ordering, it's just not alphabetical or something.

9:23 So even a hash map will always return the same order for the same map. And that is the only promise you get. as soon as you change a tiny bit of the map, nothing is guaranteed anymore.

9:30 * Raynes fixed his das by cleaning it.

9:45 raek: fliebel: did you find the Heisen-bug?

9:46 fliebel: raek: Well, after moving back and forht a few lines, it just stopped happening.

9:47 raek: ah, now it really starts to sound like quantum mechanics!

10:04 mduerksen: fliebel: i'm sorry, my connection seems to be unreliable, did you respond to my last post?

10:05 Raynes: <fliebel> I don't agree about that. There is not something like a random ordering, it's just not alphabetical or something.

10:05 <fliebel> So even a hash map will always return the same order for the same map. And that is the only promise you get. as soon as you change a tiny bit of the map, nothing is guaranteed anymore.

10:06 mduerksen: ^ That's what he said after you last spoke.

10:08 mduerksen: Raynes: thank you.

10:11 fliebel: it's not a random ordering, true. but i still don't see why the ordering of 'keys' has to be the same ordering of 'vals' in terms of what the function name promises. to me, it feels "wrong"

10:13 Belaf: Hi everybody. Is clojure.contrib.duck-streams supposed to work in Windows?

10:13 raek: Belaf: I suppose so

10:14 (since 1.2, most of the stuff in duck-streams is available in clojure.core and clojure.java.io. prefer these for a new project)

10:16 Belaf: I had an issue with it today... oh, thanks, let me check if the one in clojure.core or clojure.java.io works better.

10:18 It was about file-str, by the way. Did it move to another namespace also?

10:19 raek: this does something very similar: http://clojuredocs.org/clojure_core/clojure.java.io/file

10:20 Belaf: Thanks, I'm going to check it.

10:20 raek: you pass it the path segments as arguments, and it returns a file(path) that uses the directory separator of the platform

10:21 p_l|home: oooh, somone tried to make a portable pathname system? :)

10:22 Belaf: The issue with c.c.duck-streams/file-str is actually a bug in replacing the file separator by means of replaceAll. It was already mentioned in this same channel in February this year.

10:24 fliebel: Does anyone know what sendError is supposed to do to a servlet response?

10:31 Belaf: I see that clojure.java.io/file doesn't attempt to translate [/\\] to File/Separator as file-str did, so it might be safer... I'll need to wait and be back on windows to test this :-(

10:33 raek: io/file is simply a wrapper for java.io.File: http://download.oracle.com/javase/6/docs/api/java/io/File.html

10:33 "User interfaces and operating systems use system-dependent pathname strings to name files and directories. This class presents an abstract, system-independent view of hierarchical pathnames."

10:34 fliebel: I believe they use a colon in the abstract stuff?

10:34 Belaf: Allright. Thanks raek, this seems what I was looking for.

10:34 raek: I don't think it is string based

10:35 until it is needed in OS calls

10:44 p_l|home: Belaf: most portable pathname systems don't use string representaion

10:44 *representation

10:44 CL's are struct with a list for directory path

10:47 Belaf: I see. I was using file-str as it was already in duck-streams and I was using duck-streams/copy already. It was working fine in linux, but when I tried it on windows... the clojure.java.io/file solution seems much better. Thanks

10:48 p_l|home: Belaf: pathnames are a hell. Always use a portable variant if it's available, doubly so on Java where you really don't know where your app will end up working

10:48 and I've got access to at least one machine that requires all slots in *CL* pathname spec (which is I think the most broad ever) and still has up-to-date JVM

10:49 Belaf: what do you mean by "all slots in *CL* pathname spec" ?

10:51 p_l|home: Belaf: Common Lisp pathnames are structs, which have slots that contain host, device, directory, filename, extension and version :)

10:52 and yes, I've got access to machines that have all of those *used*

10:52 Belaf: Oh, I see. and the number of slots is limited.

10:53 p_l|home: Belaf: well, limited by the definition of the struct in question. The directory slot contains a proper list of directories

10:54 Belaf: I see that clojure.file.io also provides a copy function... I can drop duck-streams altogether, then :-)

11:20 bartj: Raynes, have you hosted the Clojure quiz some-place?

11:46 candera: Anyone know why, when I lein uberjar this ultra-simple program (https://gist.github.com/728308) and run it via java -jar repro-1.0.0-SNAPSHOT-standalone.jar foo.txt, it fails with a "java.lang.NoClassDefFoundError: clojure/contrib/io/Streams" ?

12:07 raek: candera: are you using matching versions of clojure and contrib?

12:07 oh, saw the additional comments in the gist

12:08 you could use clojure.java.io/reader

12:09 but it is wierd that you get the error

12:28 kaiser: hi, what's the time complexity of conj in a hash-set?

12:28 is it constant?

12:29 raek: well, "pretty much". :) ir

12:29 it's O(log32 n)

12:30 kaiser: hmmm...how do you know, raek?

12:31 raek: so if you have about 4000000000 entries in your hash-set, conjing will have to traverse about 6 or 7 levels

12:31 it is implemeneted as a tree with a branching factor of 32

12:31 kaiser: http://blog.higher-order.net/2009/09/08/understanding-clojures-persistenthashmap-deftwice/

12:32 kaiser: is there a way to put something in a hashset in constant time?

12:33 raek: no, O(log32 n) is what clojure provides.

12:33 kaiser: disj in hash-sets are log32 too?

12:34 raek: which is in practice very close to sontant time (since you cannot have more than 2^32 hash values)

12:34 yes

12:35 kaiser: hmmm...i make a lot of conj operations...

12:35 raek: clojure's persistent data structures are inteded to be used as if their operations are constant time

12:35 kaiser: i understand...

12:37 the 32 in log32 means that y = log32N => 32^y = N

12:39 raek: yes

12:39 kaiser: thanks

12:41 raek: in the screencasts, Rich Hickey himself explains the design choices of the data structures: http://clojure.blip.tv/posts?view=archive&nsfw=dc

12:41 kaiser: gonna see, thanks raek

12:42 raek: "Hammock-driven Development" from the first conference is up now too, I see...

12:44 mtyaka: candera: This looks like a leiningen bug. Are you using 1.4.0? You might want to give 1.3.1 a try.

13:52 LOPP: is there some library I could use to parse HTML in a simiral fashion to XML parsers?

13:53 raek: LOPP: tagsoup is a java lib that has the api of a xml parser

13:53 LauJensen: LOPP: Dont look for anything other than Enlive

13:53 raek: LOPP: it is very often used throught Enlive

13:53 :)

13:53 wtetzner: you could also try NekoHTML

13:54 raek: LOPP: in case you have seen the output from clojure.xml: Enlive uses the same format

14:08 LOPP: ok

14:14 hippiehunter: Is there something similar to if-let that takes more then 2 forms in its binding vector?

14:14 while still checking the value that is

14:19 LOPP: I don't get it

14:19 if sequences are null when there are no more items

14:20 what does rest on an empty list return

14:20 &(seq [])

14:20 sexpbot: ⟹ nil

14:20 LOPP: &(rest (seq []))

14:20 sexpbot: ⟹ ()

14:20 LOPP: weird

14:20 tonyl: hippiehunter: as far as I know, there isn't

14:21 LOPP: what kind of seq is ()?

14:21 tonyl: (class '())

14:21 &(class '())

14:21 sexpbot: ⟹ clojure.lang.PersistentList$EmptyList

14:22 tonyl: rest doesn't check ahead if there is anything in the list, next does

14:22 that is my understanding

14:31 LOPP: but I wasn't using list

14:31 I was using sequences

14:31 &(class (rest (seq [])))

14:31 sexpbot: ⟹ clojure.lang.PersistentList$EmptyList

14:31 LOPP: hm

14:31 weird

14:35 raek: LOPP: sequences may not be nil when there are no elements

14:37 for instance, until (lazy-seq (when (zero? (rand-int 2)) (list "foo"))) is forced, it has not "decided" whether it should be nil or ("foo")

14:37 however, if you call seq on something empty, you always get nil

14:37 () is the empty (persistent) list

15:44 dnolen: Logos 0.1, https://github.com/swannodette/logos, fun stuff. Now to read up on Skew Binary Random Access Lists and Finger Trees.

16:47 psantaclara: has anyone played with aleph?

16:52 digash: i am building binary protocol client based on aleph

16:54 psantaclara: digash: excellent. I'm just trying to get the hello-world example from github working and encountering problems.

16:54 (use 'lamina.core 'aleph.http)

16:54 samx:

16:54 (defn hello-world [channel request]

16:54 (enqueue channel

16:54 {:status 200

16:54 :headers {"content-type" "text/html"}

16:54 :body "Hello World!"}))

16:54 (start-http-server hello-world {:port 8080})

16:54 i took that directly from the readme and it is throwing an exception somewhere in the aleph code base

16:55 digash: i am not using the http server part, but what is the exception?

16:56 psantaclara: java.lang.IllegalArgumentException: No implementation of method: :enqueue- of protocol: #'lamina.core.channel/Channel found for class: aleph.core.channel$splice$reify__2991

16:56 LOPP: guys, what's the best way to handle errors in clojure

16:57 I heard lisp has much better mechanisms for that than just simple exceptions

16:57 psantaclara: the hello-world fn isn't receive a "channel" as its first argument but rather a aleph.core.channel$splice$reify__2991

17:00 digash: psantaclara: hmm, got to run but i used quite a few parts of aleph and have not ran into problems, it is evolving quite quickly so use the latest and greatest if you can

17:01 psantaclara: digash: roger that. Thanks. :)

17:01 digash: i usually use the tcp to establish pipeline-channels and then just enqueue or read-channel etc.

17:05 psantaclara: digash: I'm ultimiately interested in web sockets but i thought i would try a vanilla get request first.

17:12 oh, nice, i just had to use the more recently github clone. the hosted version of aleph on clojars is old.

18:25 raek: LOPP: there are multiple solutions. you could return special values, throw exceptions (you need gen-class to make your own types, though), or use a lib (which can give you even more freedom), such as c.c.error-kit and c.c.condition

18:59 vIkSiT: lo all

19:00 i'm trying to return a value based on an input to a function. so something like (defn myfn [va] (cond ((= (:a val) 1) <assign local variable to use after the cond>))))

19:01 for instance, i may choose to return the contents of a file or the output from another function

19:01 but i'm not sure how to assign local variables using the cond

19:01 ideas?

19:02 raek: you would want to do something like (defn myfn [val] (let [x (if (= (:a val) 1) ...foo... ...bar...)] ...))

19:02 in clojure, you cannot change local variables

19:03 hiredman: vIkSiT: cond also doesn't take pairs like that, check the docs

19:03 raek: so they even aren't called "local variables", but simply "locals" or "local values"

19:03 vIkSiT: aaah right, i can prolly use it like that.

19:03 hiredman, oh hmm. let me check

19:04 raek: the diff from CL and scheme is that you drop the grouping parens in clojure

19:06 vIkSiT: hiredman, this seems to work? http://paste.lisp.org/display/117338

19:11 raek: vIkSiT: in that paste, you didn't have the extra pairs of parens that you had in the snippet you wrote here

19:11 vIkSiT: aah

19:11 gotcha

19:13 btw, has anyone here used aleph?

19:14 I'm trying to figure out how to stop the server (and restart it, to uptake new code)

19:15 raek: vIkSiT: if you replace (start-http-server hello-world {:port 8080}) with (start-http-server #'hello-world {:port 8080}) in the hello world example, you don't need to restart the server

19:15 vIkSiT: aah

19:15 why is this?

19:16 i see. it re-evals the hello-world fn each time?

19:16 raek: when you call the start-http-server function, the current value of hello-world is pulled out

19:16 vIkSiT: great

19:16 raek: (i.e. the current function it holds)

19:17 with the var-quote (#'), it will give the var itself to start-http-server

19:17 var objects happens to implement the function interface (clojure.lang.IFn) and does so by calling the contained value as a function

19:18 vIkSiT: this is useful

19:18 raek: so, if you re-evaluate the defn for hello-world, the server should change (if you are using the modified version)

19:18 vIkSiT: let me try this out

19:18 raek: (well, the server itself does not change per se)

20:24 vIkSiT: hmm, i'm trying to read n lines from a file, pass each line to a functiona call, and store the resultant map into a bigger map

20:24 something like (-> (read-file "filename") (myfn)) ..

20:25 but whats the best way to "accumulate" these results?

20:37 brehaut: vIkSiT: that would depend on what you are going to do with the results surely?

20:38 but using an (into {} (map key-val-generating-mapping input-seq))

20:38 would be a good start

20:38 key-val-generating-mapping would return a vector of the key for the overall map and a value which is the resultant map you talked about earlier

20:43 vIkSiT: http://clojuredocs.org/clojure_core/clojure.core/into

20:49 vIkSiT: brehaut, ah thanks for the info

20:49 was doing something similar: http://paste.lisp.org/display/117341

20:49 brehaut: vIkSiT: no prob

20:49 vIkSiT: but the resultant value is a lazyseq, and i'd like it to be a map of maps

20:49 ideas?

20:49 brehaut: into {} should do that

20:49 vIkSiT: hmm

20:50 brehaut: into pours whatever seq you provide it into the first argument

20:50 vIkSiT: right

20:50 so in the paste above, into should pour {:entry line} into {}

20:50 brehaut: yup

20:51 vIkSiT: but lets say I want v to look like : {:mainresults [{:entry line} {:entry line} ... ]}

20:52 brehaut, how would that happen here?

20:52 brehaut: sorry im a little confused what you mean there

20:53 also looking at your snippet, your use of into unnecessary

20:53 vIkSiT: brehaut, let me explain. i'm basically reading a number of lines, and i'd like to convert this to json..

20:53 brehaut: can you make a snippet of the input and what you want as output please

20:53 vIkSiT: so i need a map of the form : {:main [{:1 a} {:2 b} ... }

20:53 sure

20:55 http://paste.lisp.org/display/117341#1

20:56 rata_: vIkSiT: http://nakkaya.com/2010/06/15/clojure-io-cookbook/

20:57 but why do you want every line to be in one map?

20:57 that's kind of weird

20:58 *each line

20:58 you better put them all in just one map

20:58 vIkSiT: rata_, each line is an entry, and the map contains say, its ID for now (and later on other attributes from parsing that line)

20:58 rata_: or make a vector, that's already indexed by number

20:58 vIkSiT: for instance, I could do something like:

20:59 brehaut: something liek

20:59 (defn f [name]

20:59 {:main (vec (zipmap (map keyword (iterate inc 1))

20:59 (read-file name)))})

20:59 ?

20:59 vIkSiT: http://paste.lisp.org/display/117341#2

20:59 brehaut: wait no thats wrong too

21:00 vIkSiT: (assoc {} :entries (vec (let [v {}]

21:00 (for [line lines]

21:00 (assoc v :entry line)))))

21:00 i do that right now

21:00 but i wasn't sure how to change :entry to the counter

21:00 such that it increments each time

21:00 brehaut: vIkSiT: do you understand immutable datastructures?

21:00 vIkSiT: indeed

21:00 ooh. zipmap

21:02 brehaut: vIkSiT: to start, you shouldnt need to use assoc with an empty map literal there; just use a map literal

21:02 vIkSiT: brehaut, agreed

21:02 brehaut: (in both places)

21:06 vIkSiT: brehaut, how were you converting int to a keyword?

21:07 rata_: vIkSiT: that code is weird and the output you want is strange... I really don't get why you want maps that have just one key-value pair

21:07 brehaut: vIkSiT: i agree with rata_ that its strange

21:07 rata_: vIkSiT: instead of using a map, you should be using a vector

21:07 vIkSiT: rata_, brehaut - each line is actually transformed into a map as well on read

21:08 brehaut: {:main (vec (map (fn [k v] {(-> k str keyword) v}) (iterate inc 1) (read-file name)))})

21:08 thats closer to what you want

21:08 its pretty horrible

21:08 vIkSiT: so it would look like : {:1 {:account "1" :name "abc" :foo "bar"}}

21:08 yes, i can also have a vec of maps

21:08 rata_: vIkSiT: you should transform lines into values, not maps, unless you want each line to be a map of more than just one key-value pair

21:09 vIkSiT: rata_, the latter..

21:09 i'm basically parsing each line of a log file

21:09 rata_: ok... then, a vec of maps is ok

21:10 so (vec (map generating-map-fn (read-file filename))) is all what you need

21:10 and generating-map-fn is a function that receives a string and returns a map

21:12 vIkSiT: righto

21:12 brehaut: im lost now :P

21:12 glad you two seem to have worked it out

21:12 vIkSiT: hehe

21:13 there's one issue still

21:13 lets say the file i read is really long

21:13 duck-streams/read-lines may consume all memory.

21:13 rata_: then you use the second example in the link I gave you

21:13 vIkSiT: is there a way to lazy-read the file?

21:13 ah

21:16 btw, do you guys use clojure on production systems?

21:17 or mostly as a hobby, just yet?

21:17 brehaut: vIkSiT: what counts as a production system? http://brehaut.net/ is running on clojure but its entirely small fry

21:17 vIkSiT: brehaut, ah, sure. i mean data intensive stuff, clusters, et al.

21:17 i know flightcaster.com and runa.com run it, but was curious if someone here does it

21:18 brehaut: well a bunch of the people who have built those system do hang out here

21:18 i know that backtype guys do

21:19 rata_: vIkSiT: I'm developing a Clojure library to simulate biological systems... don't know if that's what you mean

21:19 vIkSiT: ah yes, i know nathanmarz..

21:20 rata_: what's the most similar function to Python string's split?

21:20 vIkSiT: rata_, cool

21:20 i use .split mostly

21:20 rata_: ok =)

21:20 vIkSiT: also re-seq

21:20 brehaut: rata_ clojure.string/split ?

21:21 (1.2.0 onward)

21:21 vIkSiT: interesting.

21:21 rata_: thanks =)

21:22 brehaut: clojure.string brings across stuff previously in contrib.strutils i believe

21:36 yikes, a clj quick reference ive found is 56 pages

21:37 rata_: good bye guys... see you soon

22:03 hippiehunter: how do I make an array of strings for java interop?

22:04 danlarkin: (into-array ["foo" "bar"])

22:05 hippiehunter: doesnt that make an array typed as object?

22:05 danlarkin: why don't you try it and find out

22:07 hippiehunter: (into-array ["bla"]) works but (array (vec ("hello"))) doesnt

22:07 interesting

22:08 danlarkin: that's because vec doesn't do what you think it does

22:08 hippiehunter: yeah i gathered that

22:08 danlarkin: ,(vec "hello")

22:08 clojurebot: [\h \e \l \l \o]

22:08 hippiehunter: ,(vec ("hello"))

22:08 clojurebot: java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn

22:09 danlarkin: there you're trying to invoke the string "hello"

22:09 perhaps you mean to quote that list

22:09 hippiehunter: yeah i did

22:09 ,(vec '("hello"))

22:09 clojurebot: ["hello"]

22:09 rata_: hi

22:10 danlarkin: into-array doesn't need to take a vector, any collection will do

22:11 if you already have a list you can just pass that in, no need to vec it

22:13 rata_: do you know how to store time intervals and associated data to then be able to efficiently find within which time interval a certain time is?

22:23 vIkSiT: hmm, has anyone here used aleph?

22:23 i was wondering how i would update a channel in real time, in order to stream a series of numbers to the page?

23:45 rata_: chouser: I'm seeing your Conj talk about finger-trees... they are amazing!! =)

23:46 brehaut: rata_: got a link for that?

23:47 rata_: brehaut: http://talk-finger-tree.heroku.com

23:47 brehaut: thanks

23:52 * rata_ wonders why clojure.data.finger-trees isn't in clojars

23:54 rata_: I think counted-sorted-set is exactly what I need =)

Logging service provided by n01se.net