#clojure logs

2010-02-20

03:21LauJensenMorning team
03:41woobyhi LauJensen
04:08Hali_303why is this false? (contains? [:p] :p)
04:12Hali_303never mind, I should read the docs instead :D
06:56raek,(contains? [:p] :p)
06:56clojurebotfalse
06:56Chousukeclojurebot: contains?
06:56clojurebotcontains? 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 the java method .contains
06:57raekHali_303: contains? only works for maps and sets...
06:57Chousukeno, it works for vectors too
06:57Chousuke(doc contains?)
06:57clojurebot"([coll key]); Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'."
06:57Chousuke,(contains? '[a b c] 2)
06:57clojurebottrue
06:57kotarakraek: no linear search, for vectors it tests whether the index is contained
06:57raekah, yes...
06:57Hali_303thanks guys! i'm still learning clojure :)
06:58raekof course, the indices are the keys of the vector
06:58Hali_303what are you using for web development? does anyone use compojure for some real production apps?
07:07raekI'm using compojure, but not for a "production" project... :)
07:08raekat most, about 20 persons will use it
07:11Hali_303raek: are there some example projects on the web using compojure? I'd be interested how to do authentication and validation
07:27raekHali_303: no, I'm sorry. I've only used compojure for two weeks
07:27Hali_303raek: no problem, I'll keep searching
07:28raekauthentication sounds like something that should be fairly easy to be done in middleware
08:20avarushi
11:49rrc7cz-hmhow might you go about converting "a__b__c" = 1, "d" = 2 into {:a {:b {:c 1}} :d 2}?
11:49rrc7cz-hmwhere some delimiter signals a nesting level
11:54kotarak,(apply merge (for [[k v] (partition 2 ["a_b_c" 1 "d" 2])] (let [ks (.split k "_")] (assoc-in {} ks v))))
11:54clojurebot{"d" 2, "a" {"b" {"c" 1}}}
11:54kotarak,(apply merge (for [[k v] (partition 2 ["a_b_c" 1 "d" 2])] (let [ks (map keyword (.split k "_"))] (assoc-in {} ks v))))
11:54clojurebot{:d 2, :a {:b {:c 1}}}
11:56rrc7cz-hmwow
11:56kotarakrrc7cz-hm: has some gotchas though.
11:57kotarak,(apply merge (for [[k v] (partition 2 ["a_b_c" 1 "d" 2 "a" :boooo])] (let [ks (map keyword (.split k "_"))] (assoc-in {} ks v))))
11:57clojurebot{:d 2, :a :boooo}
11:58rrc7cz-hmkotarak: unfortunately I'll be iterating over a seq of key-val pairs which could appear in any order. I guess the last one would override all previous then
11:59kotarakrrc7cz-hm: yes, you have to merge the different levels.
11:59kotarakrrc7cz-hm: that makes things more complicated.
12:00rrc7cz-hmkotarak: thanks for the start though; this is a good base to build on
12:02kotarak,(reduce (fn [m [k v]] (let [ks (map keyword (.split k "_"))] (assoc-in m ks v))) {} (partition 2 ["a_b_c" 1 "d" 2 "a_f" 3]))
12:02clojurebot{:d 2, :a {:f 3, :b {:c 1}}}
12:03kotarakrrc7cz-hm: maybe this (^^^^) is more what you need?
12:04rrc7cz-hmkotarak: that's exactly it
12:04rrc7cz-hmbasically I have nested maps that I convert to flat maps with __ deliminating levels. this is so I can put the map in an html form
12:05kotarakrrc7cz-hm: I hope you don't trust this data when you get it back...
12:05rrc7cz-hmso there are inputs like <input type="text" name="a_f_s" value="1" />
12:05rrc7cz-hmkotarak: what do you mean?
12:06kotarakrrc7cz-hm: Naa. It's ok. My fear was you want to carry state with that.
12:06kotarakrrc7cz-hm: in a hidden field or so.
12:06rrc7cz-hmkotarak: it's for selecting product options, which can get quite complex. Right now I have the nested maps converted to the flat one just fine
12:07rrc7cz-hmkotarak: I'm trying to now convert it back for comparison
12:07kotarakrrc7cz-hm: that's a nice application actually. :)
12:07rrc7cz-hmkotarak: I will then walk the various product configurations (nested maps) and try to find the best match from what I got from the UI
12:08rrc7cz-hmkotarak: yeah, it's the only way I've been able to think of for handling arbitrarily complex product customizations
13:14hamzadoes future objects use a thread pool or each one fires up a new thread?
13:16{newbie}future object have to me "executed" by an external source
13:16{newbie}like and Executor
13:16{newbie}s/and/an
13:18hamzakk thanks.
14:02jlillyis there a shortcut for (def myvar (inc myvar)) ?
14:03AWizzArdNo, because this should not be done within programs. Clojure is dynamic - this is only allowed for administration purposes.
14:03jlillytrying to preserve state for the length of a loop
14:04jlillyie: determining an outcome based on a nested if statement.
14:04AWizzArdIn a loop you can have your own flags/counters
14:04AWizzArdYou can modify them with recur
14:04Chousukedefs anywhere but on the top level usually means you have non-idiomatic code
14:04Chousukeand that you need to restructure it.
14:04Chousukebut how, is difficult to tell until I can see the code in question :)
14:05kotarak,(loop [x 1] (if (= x 5) :done (recur (inc x)))
14:05clojurebotEOF while reading
14:05kotarak,(loop [x 1] (if (= x 5) :done (recur (inc x))))
14:05clojurebot:done
14:05jlillyhttp://pastie.org/834439
14:07Chousukehmm
14:08jlillyso my first inclination is to make it (def robot1-wins (inc robot1-wins))
14:08jlillybut I understand that's a bad idea.
14:09jlillyperhaps I really want to pull out the "who won" if block into a function
14:13Chousukehmm
14:17mattreplare protocols and datatypes expected to change much now?
14:18Chousukejlilly: http://gist.github.com/309849
14:20Chousukejlilly: rather than explicit loops, generating a sequence of the stuff you want to process is often easier :)
14:20Chousukejlilly: in the gist, I generate an infinite sequence of battle results and then take 50 of them
14:21Chousukejlilly: next, it's reduced to a triple containing r1-wins, r2-wins and ties
14:23Chousukejlilly: the (or winner :neither) thing in condp is just there in case winner is nil (which won't be the case here, but I put it there regardless)
14:26Chousukemattrepl: I think they're pretty close to their final form, but since they're not in a release yet, they might change.
14:26mattreplChousuke: thanks
14:28maravillashow might i destructure a list of arguments to pass to a java constructor? that is, something along the lines of (apply new JCheckBox args), if "new" were a function, but...
14:28Chousukemaravillas: you can't do that
14:29Chousukemaravillas: but you can do (let [[a b c] args] (JCheckBox. a b c)) :)
14:29maravillasah, darn. ii wanted to be able to handle multiple constructor overloads with one statement
14:30ChousukeThat's unfortunately not possible. :)
14:30maravillasoh well. thanks :)
16:16{newbie}has anyone here used clojure for numerical algorithms?
16:47ugglangnight
17:09jlillyChousuke: thanks for that gist. Makes things much nicer. :)
17:54{newbie}hi! was the 1.1.x brach of clojure contrib already release?
17:54{newbie}ed*
18:02Chousuke{newbie}: yes. though I'm not sure where to download it :P
18:03{newbie}from github?
18:03AWizzArdYou can download Clojure from http://build.clojure.org/ too.
18:07{newbie}AWizzArd: are these versions compiled against each other?
18:07AWizzArdYes.
18:08{newbie}nice! thanks
18:16jcromartieo hai
18:16jcromartieIs there a more idiomatic way to do this: (assoc response :body (json-str (:body response))) ?
18:16jcromartiebasically to alter a hash
19:01dermatthias.
19:04tomojhmm, it seems like amap for dot products on float arrays is slower than map on lazy seqs
19:12chouserwhoa
19:14AWizzArdThat would be surprising.
19:22tomojI probably screwed up, then
20:58hamzagents, can someone tell me why this does not work, http://paste.lisp.org/display/95334 ?
21:01somniumhamza: I think the namespace created by 'create-ns is completely empty (ie lacking clojure.core)
21:03hamzaany way to import definitions from clojure.core?
21:03somnium,(doc refer)
21:03clojurebot"([ns-sym & filters]); refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude list-of-symbols :only list-of-symbols :rename map-of-fromsymbol-tosymbol For each public interned var in the namespace named by the symbol, adds a mapping from the name of the var to the var to the current namespace. Throws an exception if name is already mapped to something else in the current name
21:04scgilardibut you'll have to fully qualify it: (clojure.core/refer 'clojure.core)
21:05hamzathanks alot that solved it..
21:20zabHi. I'm trying to upload a very simple Clojure app to App Engine. Once uploaded, I keep getting this stack trace: http://pastebin.com/dabf3cd9
21:20zabpoints to clojure.lang.DynamicClassLoader?
21:20zabSeems like GAE's sandbox doesn't like it? java.security.AccessControlException
21:26somniumzab: I think compojure.http.multipart disagrees with AE's security policy
21:26zabsomnium: Yeah I've already commented it out of Compojure sources, and recompiled
21:29somniumor you can do (:use [compojure.http :exclude [multipart]]), still getting the error after excluding?
21:32zabhmm I deleted src/compojure/http/multipart.clj, commented it out, recompiled and deployed. Same exception raised.
21:32zabstack trace also shows it rising from clojure and not compojure though?
21:33somniumthere might be others, are you doing (:use compojure) in the ns?
21:33zabyeah
21:33zab(:use compojure.http compojure.html)
21:35zaboh, no longer getting that exception. Now getting java.lang.NoClassDefFoundError for my servlet class.
21:41somniumzab: dunno, last time I used it with sdk 1.3 this stub was working: http://paste.pocoo.org/show/180670/
22:25slyphonis it possible to deref inside a destructuring ?
22:25slyphonoh, hrm, that probably doesn't make sense
22:31tomojyou can deref to get the thing you're destructuring..
22:32slyphoni'm destructuring a nested hash-map like structure
22:32tomojthe leaves are refs?
22:32slyphonyeah
22:32slyphonwell, one of the branches is a ref
22:32tomojdon't think you can do that, then
22:33slyphoni may be overdoing it with the refs
22:33slyphonyeah
22:33slyphonit probably is more sensible to do it inside a let in a dosync
22:40slyphoncan you mix the :keys form with the symbol/keyword forms? like (let [{:keys [a b c] foo :foo} thing] ...)
22:41slyphonhrm
22:42slyphonoh, duh
22:44zaboh man, I tried everything to get a Compojure app running on GAE. This was with the latest 1.3.1 GAE SDK. Nothing worked.
22:44zabThen I downgraded the SDK to 1.2.1 (the last one that I could find), and now everything is working.
22:49zabOkay I retract everything I said. 1.3.1 is now working. Problem was I was not copying across lib/appengine-tools-api.jar
22:49zabSeems it's necessary for it to work in deployment, but not for the dev server.
23:13Crowbar7Evening
23:47sdmHi, I'm just starting to learn clojure ... is it possible to do a loop or dotimes inside of a doto?
23:48sdm(doto (String.) (dotimes [i 10] (.concat i))) => #<CompilerException java.lang.IllegalArgumentException: dotimes requires a vector for its binding (REPL:1)>
23:48sdmam I doing something crazy?
23:49somnium,(macroexpand-1 '(doto (String.) (dotimes [i 10] ...)))
23:49clojurebotjava.lang.RuntimeException: java.lang.IllegalArgumentException: dotimes requires a vector for its binding
23:50somniumsdm, hmm, not sure why he choked
23:50hamzayou can't, it will mess dotimes
23:51hamza(clojure.core/let [G__27 (String.)] (dotimes G__27 [i 10] ...) G__27)
23:52sdmOkay... so doto and dotimes (or loop) collide the binds?
23:54hamzawhen in a doto block every function used will be supplied x in its first argument, so not just dotimes it may mess a bunch of things.
23:56sdmahh I see, I thought doto did something only functions starting with . (like (.concat ...) that makes sense
23:56sdmthank you!
23:56hamzanp
23:57Crowbar7So, I'm quite new to Clojure and was wondering a couple of things. I'm building a really fairly crappy IRC bot that makes a thread whenever a trigger is caught. writing an re-find for everyone one in a cond seems a little lengthy. Would it be possible to just have the keywords checked in a map then using the functions names tied to the keyword to spawn the thread? Or am I doing this whole thing absolutly horrible?
23:58Crowbar7The reason for threading is proof of concept / fun and because I hate it when http scraping bots hang because they are still collecting data ro something and I can't query them.