2010-12-04
| 00: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. |
| 00:46 | talios | hrm - it would seem deftype's don't automatically load namespaces. I think sticking with good ole genclass will do. |
| 01:56 | cky | talios: Hahaha, small world. :-P |
| 01:56 | talios | 'lo cky |
| 01:56 | talios | long time :) |
| 01:56 | cky | Indeed. :-) |
| 01:57 | talios | where abouts are you based these days? |
| 01:57 | cky | Durham, NC. (Yes, I was bummed to not have heard about Clojure Conj until a month after the fact.) |
| 01:58 | cky | I hope the next Clojure Conj will be in Durham again. I'd love to attend. |
| 01: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 :( |
| 01:59 | cky | Yeah, I know. :-) |
| 01:59 | talios | w00t - tests now fail due to non-implemented code, rather than cocked up code ;) |
| 02:00 | cky | :-P |
| 02:02 | cky | Anyway, getting late here. Good seeing you again---I'm sure we'll chat some more. :-D |
| 02: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 :) |
| 02:03 | cky | Wow, you mentioned clojure and maven in the same sentence! I thought only chouser does that. :-P |
| 02:03 | talios | I'm the crazy fool who started the plugin :) |
| 02:04 | cky | My response was that as far as I can imagine, the one relation clojure and maven share is the letter "e". :-P |
| 02:04 | cky | Hahaha, nice. |
| 02:07 | quile | that's the most smileys I've seen in an IRC chat room in a while. |
| 02:09 | harishtella | Anyone using (vim + screen/tmux ) to develop clojure? |
| 02:14 | talios | I have a smiley addition. I have for a long time. |
| 02:26 | talios | mmm, is there a simple way to convert a seq into a java.util.List? |
| 02:27 | Raynes | I just thought of the most awesome name for a Clojure text editor. |
| 02:27 | Raynes | sexteditor |
| 02:28 | Raynes | I'm going to have to write a text editor for the sole purpose of using that name. |
| 02:28 | talios | heh |
| 02:30 | Raynes | &(java.util.LinkedList. '(1 2 3)) |
| 02:30 | sexpbot | ⟹ #<LinkedList [1, 2, 3]> |
| 02:30 | Raynes | talios: Like that? |
| 02:31 | Raynes | &(instance? java.util.List (java.util.LinkedList. '(1 2 3))) |
| 02:31 | sexpbot | ⟹ true |
| 02:31 | Raynes | j.u.List is an interface. |
| 02:32 | Raynes | &(instance? java.util.List '(1 2 3)) |
| 02:32 | sexpbot | ⟹ true |
| 02:33 | talios | doh - my defn is returning PersistentVector not PersistentList ( which is a j.u.List ) |
| 02:33 | Raynes | &(instance? java.util.List [1 2 3]) |
| 02:33 | sexpbot | ⟹ true |
| 02:33 | Raynes | sexpbot just disagreed. |
| 02:33 | Raynes | &(type [1 2 3]) |
| 02:33 | sexpbot | ⟹ clojure.lang.PersistentVector |
| 02:34 | hiredman | ,(supers (class [])) |
| 02: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... |
| 02:34 | hiredman | ,((supers (class [])) java.util.List) |
| 02:34 | clojurebot | java.util.List |
| 02:34 | Raynes | talios: ^ |
| 02:39 | talios | food even:) |
| 02:40 | Raynes | talios: Doon is even better. |
| 02:42 | mroessler | Trying to eliminate reflection here, but unsure how: (.withMaximumValue (.dayOfYear yearago)) |
| 02:42 | mroessler | my type hints dont' seem to get rid of the warning. |
| 02:49 | hiredman | mroessler: are you type hinting yearago? |
| 02:50 | mroessler | hiredman: Trying to, yes. Its a joda DateTime object. |
| 02:50 | hiredman | ^DateTime yearago |
| 02:51 | mroessler | hiredman: Exactly. I have (.withMaximumValue (.dayOfYear ^DateTime yearago)) but I still get a reflection warning. I was surprised. |
| 02:51 | hiredman | are you sure that is where you getting the warning? |
| 02:52 | mroessler | reference to field dayOfYear can't be resolved. reference to field withMaximum value can't be resolved. |
| 02:53 | mroessler | am I hinting the wrong thing? |
| 02:54 | hiredman | dunno |
| 02:54 | mroessler | ok. Thanks! |
| 04: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? |
| 04:57 | LOPP | what's the idiomatic way of reporting and reacting to errors in clojure |
| 05:42 | fliebel | morning |
| 05:47 | fliebel | Is there any way to automatically create getters on a record? so getSomething rather than (get :something) |
| 05:50 | LOPP | in what way |
| 05:51 | LOPP | as java methods? |
| 05:51 | fliebel | yea |
| 05:51 | LOPP | or clojure fns named like that |
| 05:51 | fliebel | No, Java methods. I need to implement an interface that's only getters. |
| 05:52 | LOPP | would help if I actually knew how to implement interfaces in clojure :D:D: |
| 05:53 | fliebel | I think I can get a long way with destructuring and the applying to a reify… |
| 05:53 | LOPP | but generally you can get methods that need to be implemented by using java reflection |
| 05:55 | lucian_ | fliebel: there's stuff about that http://clojure.org/java_interop |
| 06:19 | fliebel | Man, this is at least the 100th time I need to apply or thread to a macro. |
| 06:20 | LOPP | I don;t understand |
| 06:22 | fliebel | &(apply reify) |
| 06:22 | sexpbot | java.lang.Exception: Can't take value of a macro: #'clojure.core/reify |
| 06:34 | hoeck | fliebel: that makes no sense, macros run at compiletime, applying (= invoking with varargs) happens at runtime |
| 06:34 | fliebel | hoeck: I know that, but I keep comming up with situations where I have a seq of arguments for a macro. |
| 06:34 | hoeck | but you can write a macro and there do `(reify ~@args) |
| 06:35 | fliebel | Sure, but that is a last resort to me. I'm now on a different path. |
| 06:38 | hoeck | so you're writing a bean class generator and need to generate mutliple getFoo methods? |
| 06:38 | fliebel | bean? |
| 06:38 | clojurebot | don't forget, NetBeans is evil, and i want you to tell people that whenever they mention it |
| 06:38 | hoeck | to me, generating a list of specs and then doing (reify ~@method-specs) sounds reasonable |
| 06: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. |
| 06:40 | hoeck | writing macros to replace a few lines of duplication is sometimes a big turing tarpit :) |
| 06:42 | fliebel | hoeck: Even if the code to generate the methods is longer than the getters? |
| 06:45 | hoeck | especially then |
| 06:45 | fliebel | wait. what's a turing tarpit? |
| 06:48 | hoeck | oh, my last definition was that this is something where you catch programmers in, doing useless stuff because you can |
| 06:48 | hoeck | wikipedia disagrees with me :/ |
| 06:55 | fliebel | hrm, can anyone tell me how getServletPath, getRealPath and getContextPath would translate from servlet lingo to ring/clojure? |
| 07:00 | charliekilo | fliebel: talke a look at https://github.com/alienscience/compojure-war-example/blob/master/src/context.clj |
| 07:00 | fliebel | thanks |
| 07:05 | fliebel | Am I correct that the other ones are just webroot+uri? |
| 07: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... |
| 07: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. |
| 07:11 | mduerksen | (defstruct st :a :b) (tst (struct st)) -> nil nil |
| 07:11 | mduerksen | is that behavior intended? |
| 07:17 | hoeck | mduerksen: (struct st) -> {:a nil :b nil} |
| 07:17 | hoeck | mduerksen: :a has a value, nil |
| 07:17 | hoeck | so destructuring wont use the default you supplied |
| 07:20 | mduerksen | hmm, it seems to be the same when merging a struct with a map: (merge {:a 1} (struct st)) -> nil nil |
| 07:20 | bartj | is there an idiomatic way of iterating through a hash-map? |
| 07:25 | fliebel | Does this satisfy Enumeration<String>? (.elements (java.util.Vector. ["a" "b" "c"])) |
| 07:26 | bartj | or in other words: |
| 07:27 | bartj | I always tend to create a new map like this: |
| 07:28 | bartj | ,(time (zipmap (keys {:a 1 :b 2 :c 3}) (map #(* 10 %) (vals {:a 1 :b 2 :c 3})))) |
| 07:28 | clojurebot | "Elapsed time: 0.592 msecs" |
| 07:28 | clojurebot | {:c 30, :b 20, :a 10} |
| 07: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? |
| 07:36 | fliebel | &(into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3})) |
| 07:36 | sexpbot | ⟹ {:a 10, :b 20, :c 30} |
| 07:36 | fliebel | bartj: ^^ |
| 07:38 | _ato | another: (reduce (fn [m [k v]] (assoc m k (* 10 v))) {} {:a 1 :b 2 :c 3}) |
| 07:38 | bartj | (time (into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3}))) |
| 07:38 | bartj | ,(time (into {} (map #(vector (key %) (* 10 (val %))) {:a 1 :b 2 :c 3}))) |
| 07:38 | clojurebot | "Elapsed time: 0.816 msecs" |
| 07:38 | _ato | and also: clojure.contrib.generic.functor/fmap |
| 07:38 | clojurebot | {:a 10, :b 20, :c 30} |
| 07: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 |
| 07:39 | bartj | _ato, amazingly, its faster too |
| 07: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 |
| 07:42 | bartj | _ato, the fmap solution is cool too |
| 07:42 | bartj | though I am a bit non-plussed asto why only the value of the map-entry gets passed |
| 08:22 | Lajla | So like |
| 08:22 | Lajla | why doesn't map make a map. |
| 08:23 | Lajla | I always wondered that |
| 08:24 | Lajla | &(map #(* % %) [1 2 3 4 5]) |
| 08:24 | sexpbot | ⟹ (1 4 9 16 25) |
| 08:30 | Lajla | &(map #(* % %) {:I 2 :worship 4 :his 5 :shadow}) |
| 08:30 | sexpbot | java.lang.ArrayIndexOutOfBoundsException: 7 |
| 08:30 | Lajla | &(map #(* % %) {:I 2 :worship 4 :his 5 :shadow 5}) |
| 08:30 | sexpbot | java.lang.ClassCastException: clojure.lang.MapEntry cannot be cast to java.lang.Number |
| 08:34 | fliebel | (map type {:a 1 :b 2}) |
| 08:34 | fliebel | &(map type {:a 1 :b 2}) |
| 08:34 | sexpbot | ⟹ (clojure.lang.MapEntry clojure.lang.MapEntry) |
| 08: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 |
| 08:35 | tscheibl | ? |
| 08:36 | fliebel | Lajla: So it returns MapEntries rather, which you can put back into a map if you want to. |
| 08:36 | LOPP | what the hell |
| 08:36 | LOPP | of course it enumerates entries |
| 08:36 | LOPP | just like java map |
| 08:38 | fliebel | &(doc val) |
| 08:38 | sexpbot | ⟹ "([e]); Returns the value in the map entry." |
| 08:42 | tscheibl | ..hmm.. will try reduce instead of filter |
| 08: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. |
| 08:52 | LOPP | heisenbugs? |
| 08:53 | fliebel | LOPP: I only learnt about them yesterday… Bugs that dissapear as soon as you try to look at them. |
| 08:54 | LOPP | well in this case they just don't appear in repl |
| 08:54 | LOPP | so you need a debugger or something] |
| 08:54 | fliebel | right |
| 08:54 | LOPP | or so I'm guessing |
| 08:57 | fliebel | LOPP: You can think of any case why the repl might work and the code not? |
| 08:57 | LOPP | nope, I'm not knowledgeable about clojure internals |
| 08:58 | tscheibl | ..ok.. 'reduce' saved my day :) |
| 08:58 | LOPP | clojure is relatively new so it's bound to have bugs |
| 08:59 | LOPP | lol I can't even find a good eclipse plugin for it |
| 09:01 | LOPP | I wonder what cemerick is using though |
| 09:02 | lucian | LOPP: i doubt a lot of lisp people are using eclipse |
| 09:04 | fliebel | LOPP: I think it was because my name used hyphens? |
| 09:05 | LOPP | really? |
| 09:05 | LOPP | that's just silly |
| 09:05 | LOPP | I saw cemerick use eclipse on one of his videos |
| 09:06 | LOPP | and I was wondering what he was using |
| 09:06 | fliebel | It seemingly took my camelcased name, and turned into a hyphenized name. I can't believe my own eyes... |
| 09:06 | LOPP | I used some eclipse plugin advertised on clojure.org and it worked poorly/didn't work |
| 09:06 | fliebel | LOPP: Might be ccw? |
| 09:06 | pdk` | lisp folk seem to be mostly emacs evangeists |
| 09:07 | LOPP | yeah I'm using clojure box which is basically emacs |
| 09:07 | LOPP | but I'm used to eclipse |
| 09:07 | LOPP | but that eclipse plugin didn't support autocomplete or anything good |
| 09:07 | LOPP | wait fliebel, you defined the type as a camel case name |
| 09:08 | LOPP | ? |
| 09:08 | fliebel | well, I don't know what I'm doing, but Clojure is giving me crap back. |
| 09:09 | fliebel | I did a deftype using a camelcased name, and it's just not there when I require it. |
| 09:10 | bartj | are the values returned by keys and vals always in the correct sequence order of the key,val of the map? |
| 09:11 | fliebel | bartj: Yes, I believe so. |
| 09:11 | bartj | fliebel, is there *any way* there could be a goof-up ? I too am not 100% sure. |
| 09:12 | fliebel | bartj: I'm 100% sure someone who know said they are guaranteed to be in hte right order. |
| 09:13 | bartj | fliebel, ok, thanks! |
| 09:15 | fliebel | technomancy: fliebel: keys and vals is guaranteed to always be consistently ordered when called on the same map |
| 09:15 | fliebel | bartj: ^^ |
| 09: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. |
| 09:20 | bartj | mduerksen, thank you. yes, depending on it does seem flaky |
| 09:21 | fliebel | I don't agree about that. There is not something like a random ordering, it's just not alphabetical or something. |
| 09:23 | 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. |
| 09:45 | raek | fliebel: did you find the Heisen-bug? |
| 09:46 | fliebel | raek: Well, after moving back and forht a few lines, it just stopped happening. |
| 09: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 | Raynes | <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 | Raynes | mduerksen: ^ That's what he said after you last spoke. |
| 10:08 | mduerksen | Raynes: thank you. |
| 10:11 | mduerksen | 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 | raek | (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 | Belaf | 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 | raek | "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 | raek | until it is needed in OS calls |
| 10:44 | p_l|home | Belaf: most portable pathname systems don't use string representaion |
| 10:44 | p_l|home | *representation |
| 10:44 | p_l|home | 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 | p_l|home | 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 | p_l|home | 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 | raek | oh, saw the additional comments in the gist |
| 12:08 | raek | you could use clojure.java.io/reader |
| 12:09 | raek | 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 | kaiser | is it constant? |
| 12:29 | raek | well, "pretty much". :) ir |
| 12:29 | raek | 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 | raek | it is implemeneted as a tree with a branching factor of 32 |
| 12:31 | raek | 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 | raek | 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 | kaiser | 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 | raek | :) |
| 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 | hippiehunter | while still checking the value that is |
| 14:19 | LOPP | I don't get it |
| 14:19 | LOPP | if sequences are null when there are no more items |
| 14:20 | LOPP | what does rest on an empty list return |
| 14:20 | LOPP | &(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 | tonyl | &(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 | tonyl | that is my understanding |
| 14:31 | LOPP | but I wasn't using list |
| 14:31 | LOPP | I was using sequences |
| 14:31 | LOPP | &(class (rest (seq []))) |
| 14:31 | sexpbot | ⟹ clojure.lang.PersistentList$EmptyList |
| 14:31 | LOPP | hm |
| 14:31 | LOPP | weird |
| 14:35 | raek | LOPP: sequences may not be nil when there are no elements |
| 14:37 | raek | 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 | raek | however, if you call seq on something empty, you always get nil |
| 14:37 | raek | () 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 | psantaclara | (use 'lamina.core 'aleph.http) |
| 16:54 | psantaclara | samx: |
| 16:54 | psantaclara | (defn hello-world [channel request] |
| 16:54 | psantaclara | (enqueue channel |
| 16:54 | psantaclara | {:status 200 |
| 16:54 | psantaclara | :headers {"content-type" "text/html"} |
| 16:54 | psantaclara | :body "Hello World!"})) |
| 16:54 | psantaclara | (start-http-server hello-world {:port 8080}) |
| 16:54 | psantaclara | 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 | LOPP | 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 | psantaclara | 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 | vIkSiT | 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 | vIkSiT | for instance, i may choose to return the contents of a file or the output from another function |
| 19:01 | vIkSiT | but i'm not sure how to assign local variables using the cond |
| 19:01 | vIkSiT | ideas? |
| 19:02 | raek | you would want to do something like (defn myfn [val] (let [x (if (= (:a val) 1) ...foo... ...bar...)] ...)) |
| 19:02 | raek | 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 | vIkSiT | 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 | vIkSiT | gotcha |
| 19:13 | vIkSiT | btw, has anyone here used aleph? |
| 19:14 | vIkSiT | 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 | vIkSiT | why is this? |
| 19:16 | vIkSiT | 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 | raek | with the var-quote (#'), it will give the var itself to start-http-server |
| 19:17 | raek | 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 | vIkSiT | something like (-> (read-file "filename") (myfn)) .. |
| 20:25 | vIkSiT | 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 | brehaut | but using an (into {} (map key-val-generating-mapping input-seq)) |
| 20:38 | brehaut | would be a good start |
| 20:38 | brehaut | 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 | brehaut | vIkSiT: http://clojuredocs.org/clojure_core/clojure.core/into |
| 20:49 | vIkSiT | brehaut, ah thanks for the info |
| 20:49 | vIkSiT | 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 | vIkSiT | 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 | vIkSiT | 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 | vIkSiT | brehaut, how would that happen here? |
| 20:52 | brehaut | sorry im a little confused what you mean there |
| 20:53 | brehaut | 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 | vIkSiT | sure |
| 20:55 | vIkSiT | http://paste.lisp.org/display/117341#1 |
| 20:56 | rata_ | vIkSiT: http://nakkaya.com/2010/06/15/clojure-io-cookbook/ |
| 20:57 | rata_ | but why do you want every line to be in one map? |
| 20:57 | rata_ | that's kind of weird |
| 20:58 | rata_ | *each line |
| 20:58 | rata_ | 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 | brehaut | (defn f [name] |
| 20:59 | brehaut | {:main (vec (zipmap (map keyword (iterate inc 1)) |
| 20:59 | brehaut | (read-file name)))}) |
| 20:59 | brehaut | ? |
| 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 | vIkSiT | (for [line lines] |
| 21:00 | vIkSiT | (assoc v :entry line))))) |
| 21:00 | vIkSiT | i do that right now |
| 21:00 | vIkSiT | but i wasn't sure how to change :entry to the counter |
| 21:00 | vIkSiT | such that it increments each time |
| 21:00 | brehaut | vIkSiT: do you understand immutable datastructures? |
| 21:00 | vIkSiT | indeed |
| 21:00 | vIkSiT | 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 | brehaut | thats closer to what you want |
| 21:08 | brehaut | its pretty horrible |
| 21:08 | vIkSiT | so it would look like : {:1 {:account "1" :name "abc" :foo "bar"}} |
| 21:08 | vIkSiT | 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 | vIkSiT | i'm basically parsing each line of a log file |
| 21:09 | rata_ | ok... then, a vec of maps is ok |
| 21:10 | rata_ | so (vec (map generating-map-fn (read-file filename))) is all what you need |
| 21:10 | rata_ | 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 | brehaut | glad you two seem to have worked it out |
| 21:12 | vIkSiT | hehe |
| 21:13 | vIkSiT | there's one issue still |
| 21:13 | vIkSiT | lets say the file i read is really long |
| 21:13 | vIkSiT | 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 | vIkSiT | ah |
| 21:16 | vIkSiT | btw, do you guys use clojure on production systems? |
| 21:17 | vIkSiT | 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 | vIkSiT | 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 | brehaut | 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 | vIkSiT | i use .split mostly |
| 21:20 | rata_ | ok =) |
| 21:20 | vIkSiT | also re-seq |
| 21:20 | brehaut | rata_ clojure.string/split ? |
| 21:21 | brehaut | (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 | brehaut | 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 | hippiehunter | 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 | danlarkin | perhaps you mean to quote that list |
| 22:09 | hippiehunter | yeah i did |
| 22:09 | hippiehunter | ,(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 | danlarkin | 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 | vIkSiT | 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:54 | rata_ | I think counted-sorted-set is exactly what I need =) |