#clojure logs

2008-11-11

07:48tWipwhat rev should I take as the latest is marked not to be used?
07:50blackdogi'm using 1037
07:51hoecktWip: 1088 is the latest one without the do not use warning
07:52tWipokey, just checking
07:52tWipwhen was doseq changed, as my code using it does not work in 1088 either
07:53hoeckbut i successfully tried the 1093 aot compilation, reveiving a 50% speedup in startup time, from 2s to roughly 1s
07:53hoecktWip: what was changed in doseq?
07:54blackdogtakes a vector now
07:54blackdoglike let
07:54tWipyeah
07:55tWipbasic usage like (doseq i (range 10) (println i)) should now be (doseq [i (range 10)] (println i)) I guess
07:55tWipbut the api page still says (doseq item list & body)
07:58hoeckah, it's stated in the svn logs (http://clojure.svn.sourceforge.net/viewvc/clojure?view=rev&sortby=log&revision=1090)
07:59tWipbetter start reading those then :)
09:27SnowBuddygood morning
09:30SnowBuddyso i was playing with the -> macro, and i can't figure out how i might use it in practice. how is (-> x (form ...)) different from (form x ...) and (-> x (form ...) (form)) different and/or preferred over (form (form x ...))?
09:33Carksnowbuddy : here is an example : (-> file FileReader. BufferedReader.)
09:34Carkinstead of (new BufferedReader (new FileReader file))
09:34rhickeySnowBuddy: (sometimes (backwards (think (to (hard (be (can (it))))))))
09:34SnowBuddy:D
09:35SnowBuddyCark: are new and class. interchangeable for creating a new object?
09:35Carki beleive so
09:36rhickeyalso a nice fit for nested associative data structures
09:36Carki use it a lot : (-> scroll-pane .getViewport .getView)
09:36Carklot less parenthesis this way
09:37SnowBuddythat makes sense, thanks :)
09:40cemerickI'm trying to push for some sanity in how Netbeans works with dependencies that provide classfiles generated from non-Java-the-language sources: http://www.netbeans.org/issues/show_bug.cgi?id=152943
09:42rhickeycemerick: good luck! This is an area that really needs more attention - mixed lang projects, and removing Java presumptions from IDEs in general
09:43cemerickrhickey: feel free to vote it up, if you like
09:43cemerickI have to think it'd be a super-easy change on their part.
09:45cemerickI'll bet that that fellow comes back with "well, you should have a clojure/scala/groovy/fortress/jruby/whatever project type, rather than a Java project type"
09:47Lau_of_DKAfternoon gents
09:47Lau_of_DKQuick question: I vaguely remember some talk about the Java libs being opensource - are they?
09:47tWipwhich java libs?
09:48Carkclojure api ?
09:48dudleyfLau_of_DK: If you mean the Java standard library, almost all of it is GPL now
09:49Lau_of_DKok, thanks dudleyf , thats what I mean
09:49tWipwikipedia seems to have a quite good article on OpenJDK
09:50tWipseems it's GPL+linking exception
09:50dudleyftWip: Yeah, I think it's GPL with the Classpath exception
10:00knoboDoes anyone have experience with clojure on symbian?
11:25SnowBuddyam i correct in thinking that assoc is basically a replace-value-at function?
11:26leafwSnowBuddy: wrong. It creates a copy of the map, with structural sharing, that has that key with its value changed.
11:29SnowBuddyunless you mean something i don't understand by "with structural sharing", that's what i said. it goes without saying that a copy is made, but the result is the same as if the value at a specific key was replaced. at least, that's how i'm reading it
11:31ChouserSnowBuddy: yes, assoc creates a new collection that has the value at "key" replaced with the "value" given.
11:31Chouserfor maps, you can also use assoc to add new keys
11:32SnowBuddybut not for vectors because the index has to be within [0, (count v)), right?
11:33Chouseryou can assoc on a vector at the next largest index
11:33Chouser(assoc [:hi] 1 :there)
11:33Chouserbut it's usually nicer to use conj for that.
11:43SnowBuddydoes if use an implicit do, or will i have to use a do when the clause of an if has more than one expression?
11:43Chouserif does not have an implicit do, but when does.
11:44SnowBuddyah, i forgot about when :P
11:46Chouserthat's what I'm here for. :-)
11:47SnowBuddyi'll get it eventually :)
11:53ChouserI wonder how hard it would be to compile Clojure to elisp.
11:54gnuvincelexical vs dynamic scoping is probably gonna be a bitch to deal with.
11:55Chouserelisp has no lexical binding at all?
11:55cooldude127i don't think so
11:56ChouserI guess if you make sure you generate completely unique names for Clojure's lexicals, that would cover it.
11:56cooldude127why do we want clojure in elisp?
11:56Chouseryou'd want a clean way to translate generated names back into Clojure names.
11:57Chouserbecause emacs sings a siren song, but elisp makes my teeth itch
11:57cooldude127oh lol
11:58cooldude127i love emacs
11:58cooldude127but i don't write much elisp
11:58cooldude127my .emacs is a hodgepodge of copied-and-pasted code
12:09drewrI find I'm doing (apply conj ... ) a lot to flatten lists. Is there already a fn for that that I'm missing?
12:10drewrActually, it's more like:
12:10drewruser> (reduce #(apply conj %1 %2) #{} [[1 2 3 4] [3 4 5 6 7]])
12:10drewr#{1 2 3 4 5 6 7}
12:11wwmorgan(apply concat [[1 2 3 4] [3 4 5 6 7]]) => [1 2 3 4 3 4 5 6 7]
12:12Chouserwwmorgan: actually, concat returns a seq
12:12wwmorganChouser is right
12:13Chouserbut since drewr is going from vector to set, (set (apply concat ...))
12:14drewrOh, duh, set incrementally adds the elements so there wouldn't be dups anyway.
12:14drewrThanks.
12:31duck1123Chouser: there's a branch of emacs that provides lexical scoping
12:31duck1123I haven't looked into it too much
13:18Lau_of_DKGood evening all
13:18AWizzArddoes Clojure have something like CLs function "member" ?
13:18AWizzArdHi Lau
13:19AWizzArdin principle it is similar to filter... only that member returns the nthcdr, including the found element itself while filter would just return that element and not necessarily the following ones
13:20kotarakAWizzArd: drop-while?
13:21AWizzArdlet me have a look...
13:22AWizzArdkotarak: yes, thx
13:30Carkwhat's the function that does that : (unkown f g) => (fn[x] (apply f (g x))) ?
13:31Lau_of_DK-> ?
13:31ChouserCark: g returns a seq?
13:31Carkallright got it : comp
13:32Chousercomp's not going to do apply for you
13:32Carkfunction composition .... couldn't put the finger on the name of that operation !
13:32Carki'll do it myself =P
13:32Carkthanks !
13:35Carkyes the apply was a mistake in the question
13:45Lau_of_DKGuys - I need to get a little into Clojures multi-threading capabilities, where do I start ?
13:45cooldude127Lau_of_DK: clojure.blip.tv
13:45cooldude127the concurrency talk is amazing
13:45kotarakLau_of_DK: the ant example
13:45cooldude127yeah that one
13:45Lau_of_DKAlright, anything else?
13:45kotaraksorry. I'm not the in multi-threading myself..
13:53duck1123has anyone read that java concurrency book rich mentions?
13:53Lau_of_DKNo
13:53duck1123and would it be worth reading?
13:57AWizzArdI remember that he mentioned one book.. if you have the video open: what is the name of that book?
13:58duck1123I think it was something like Java Concurrency in practice
13:58duck1123I don't have the video open
13:59AWizzArdcooldude127: do you have the vid open? Did Rich mention http://www.javaconcurrencyinpractice.com/ ?
13:59cooldude127no i don't have it open, i watched it a few weeks ago
14:02gnuvinceIt was "Java Concurrency in Practice".
14:02duck1123gnuvince: have you read it?
14:03gnuvinceNo.
14:06dudleyfduck1123: Read it
14:06dudleyfIt's excellent
14:06duck1123fair enough, I shall
14:07duck1123I know where I can get a hold of a copy, I just wasn't sure if it was worth my time
14:09dudleyfIf you don't appreciate Clojure's immutability-by-default now, you will once you start reading it ;-)
14:13zak_I think Clojure really gets the right mix of immutability and workarounds.
14:15duck1123I've been feeling guilty for changing variables in other languages
14:17drewrduck1123: I know how you feel. Mutating makes me feel dirty.
14:26ChouserI have more a feeling of manic daring. for( var i = 0; i < 10; ++i!!! mua-ha-ha!!!
14:27ChouserI'm in ur code, changing ur variables. Whacha gonna do about, huh!?
14:28zak_If I caught a lolcat doing that, I might have it neutered.
14:29duck1123of course, I had to keep stopping myself from putting the parens outside the function call yesterday when doing c++
14:29cooldude127i've sometimes put parentheses around my sentences
14:30cooldude127i feel so dumb
14:30duck1123I've nested 3 deep when writing.
14:30cooldude127lol
14:31zak_I sometimes unconciously type an opening paren when I'm thinking about what I'm about to write.
14:31cooldude127hehe
14:35abrooksdrewr: Thanks for the string/name patch. I've been thinking that it was missing.
14:39Hunzak_: that happen's to me when i'm writing python. wrote a small script to remove the parens afterwards
14:44drewrabrooks: Thanks. I was wondering if it was a valid suggestion.
15:00Lau_of_DKHas anybody else experienced (read-line) crashing the Slime repl ?
15:06AWizzArdis there a != or something like that in Clojure, or do we have to say (not (= ..)) ?
15:06kotaraknot=
15:06AWizzArdthx
15:12Chouseralso when-not
15:15AWizzArdInstead of CL's unless. And I am quite happy with that. As a non-native speaker I always said to myself "when not" when I saw a unless to understand better what happens.
15:16AWizzArdHow can I find the current directory in Clojure/Java?
15:17gnuvince(System/getProperty "user.dir")
15:18AWizzArddanke
15:19dudleyfJava doesn't really have a concept of "current directory" like in a shell or a scripting language, though
15:20dudleyfdoes it?
15:20leafwdudleyf: it does
15:20leafwSystem.getProperty("user.dir");
15:20leafwaka (System/getProperty "user.dir")
15:21leafwthere is also java.io.tmp.dir and user.home ....
15:21dudleyfHuh. I always read that as "user.home"
15:22leafw"usr.dir" is the current dir :)
15:23AWizzArdAnd is there a way to change it in a relative way? (System/setProperty "user.dir" "..") makes (System/getProperty "user.dir") return ".."
15:24leafwhum
15:25leafwSystem/getProperties returns you the actual table
15:25leafwperhaps you can change that
15:25leafwthere's also System/setProperties <a new Properties object>
15:26Hunin my experience, changing directory in a program is a bad idea
15:26Hunusing a path api with absolute paths works better
15:26leafwsame experience here.
15:26dudleyfThe stuff I'm reading suggests that user.dir is read-only
15:26leafwplus the Properties object has limited priviledges access control or something weird
15:27Chouserlooks like "no": http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4045688
15:27Hunit tends to make your program shellscripty
15:34deklundquit
15:34jgracinhi! how do I construct an empty List<String>?
15:34jgracinArrayList that is
15:35duck1123 /whoami
15:35wwmorganjgracin: in clojure or java?
15:35Lau_of_DK./You are duck
15:35jgracinwwmorgan: clojure
15:35duck1123lol, I thought that would work
15:35wwmorgan(list)
15:36wwmorganer, (java.io.ArrayList.)
15:36jgracinwwmorgan: I need to pass it to java code which expects List<String>
15:37wwmorganjgracin: I believe that works. What error are you getting?
15:38jgracinwwmorgan: java.utll.ArrayList creates List<Object> which is not List<String>
15:39jgracinmaybe something with 'empty'...
15:39wwmorganjgracin: generics in java are handled through type erasure. By the time the java code is compiled, it doesn't care what's in the collection
15:40AWizzArdjgracin: if you can test it easily: do you still get the same message when you do #^strings(list) ?
15:40wwmorganlisppaste8: url
15:40lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
15:41jgracinI'm actually getting no matching ctor because List<String> is expected... I think, let me recheck
15:41AWizzArddoes List<String> mean that it *must be* a list of Strings? Or is a super class like Object also fine?
15:42jgracinAWizzArd: must be Strings.
15:42AWizzArdok
15:42Chouserit's a generics thing, which only matters at Java compile time. By the time it's running and clojure's calling into it, the generic doesn't matter.
15:42deklundgotta theoretical functional question.... it looks like (re-groups ...) only works after a call to (re-find ...)
15:42deklunddoes this violate the concept of immutability?
15:43jgracinwwmorgan and Chouser: that must be it. I'll recheck
15:43Chouserdeklund: yes it does, as do many Java classes.
15:43deklundi.e. why do I need to re-find first on that match object before I can get the groups?
15:43deklundahhh
15:43Chouserdeklund: use re-seq instead to regain the illusion of immutability. :-)
15:44deklundso... once I start integrating with java classes, I sacrifice pure functionality... makes sense
15:44deklundthanks a bunch
15:45Chouseryep
15:47danlarkinso where's planet.clojure.org in the pipeline
15:51duck1123we could probably set something up with Yahoo Pipes
16:05duck11233B
16:22abrooksHm. There's no Clojure swag at cafepress.com.
16:24dudleyfabrooks: http://www.zazzle.com/clojure
16:25duck1123there needs to be better slogans
16:26duck1123I still like my: I get more work done when I'm lazy
16:26duck1123or similar
16:27abrooksduck1123: ;-)
16:27abrooksdudleyf: Ah, zazzle, right.
16:28ZakThere doesn't appear to be a black men's shirt.
16:28ChouserZak: you can customize the back women's shirt, I think.
16:32Chouseryeah, click on the black shirt (so you get the logo colors that look good on black) and then "select a different shirt style"
16:32hiredmanis this coljure swag, or libertarian swag?
16:32Chouserhehe
16:38duck1123not one of those designs has a collar
16:40kotaraklazyness is the source of intelligence
16:40SnowBuddyquick question. when i say (conj (conj nil 1) 0) i expected (1 0) as a result, but it's actually (0 1). am i missing something?
16:40AWizzArdSnowBuddy: compare conj on lists and on vectors
16:41wwmorganSnowBuddy: lists grow at the head
16:42SnowBuddyah, i see. thanks :)
16:47SnowBuddyhow does cons compare with conj? can i use a vector with cons as well?
16:47danlarkinSnowBuddy: cons is for lists only
16:47AWizzArdgive it a try in the repl
16:47hiredmancons is for seqs
16:48SnowBuddyAWizzArd: i did, that's why i asked to be sure ;)
16:48wwmorgancons returns a seq, conj returns whatever was passed into it
16:48SnowBuddyso is seq a list?
16:48Chousukeno
16:48danlarkinsorry, yes, cons is for seqs
16:48ChousukeSnowBuddy: but a list is a seq
16:49Hunbut a seq is not in every case a list.
16:49Chousukeyeah
16:49Chousukeyou can make seqs out of vectors or maps for example
16:50danlarkinspeaking of... is seq? acting properly? (seq? (seq [])) == false
16:50SnowBuddyso if it says it works on a seq, why does cons seem to only produce a list?
16:51ChousukeSnowBuddy: I suppose that's because seqs print as lists
16:51danlarkinoh--- nevermind, it's empty
16:51wwmorgan(instance? clojure.lang.ISeq (cons 1 [2 3])) => true
16:52Chousukewhen a seq is evaluated I suppose its most natural form is a list.
16:53SnowBuddyso to get a vector from a seq i would need to say something like (vec (cons 1 (cons 2 nil)))?
16:53Chousukeyeah
16:53Chousukeuser=> (list? (cons 1 [1 2])) -> false, though :)
16:54hiredman(apply vector :a [:b :c])
16:54Lau_of_DKIsnt there some trick in Java like (Date/now) which just gives me 22:51:22 ?
16:54SnowBuddyuser=> (seq? (cons 1 [1 2])) -> true :)
16:54hiredmanSnowBuddy: that will add :a to the beginning of the vector
16:54wwmorgan(conj (conj [] 1) 2) => [1 2]
16:55SnowBuddyphew, i'll get it...eventually
16:55hiredmanif that is what you want to do
16:56danlarkinSnowBuddy: running #'clojure/class on each of these forms can be illuminating... (class (cons 1 [2 3]))
16:56Chouserand compare that to (class (cons 1 '(2 3)))
16:57SnowBuddyah
16:57SnowBuddybbl. thanks
17:00johnwaynerJust to confuse things more, I think that ISeqs print as lists at the repl, but they aren't necessarily lists.
17:01NafaiSo did I hear AOT compilation for Clojure is in the works?
17:02rhickeyNafai: the AOT compiler is done, just working through the library and API logistics
17:02Nafairhickey: Cool!
17:03rhickeyClojure can AOT compile its bootstrap script and run from that bytecode
17:03rhickeyjust working on the interactions between AOT compiled code and load/require et al
17:04NafaiWill this need any special classloaders to work?
17:04Lau_of_DKrhickey, are you going to write a lengthy document that explains all this, the work behind it and its many uses in Clojure?
17:04rhickeyLau_of_DK: probably not
17:05rhickeyNafai: no special classloaders if you AOT compile - still thinking about AOT proxy, which currently needs a classloader
17:05jgracinrhickey: does compiling to .class files mean we won't have to use gen-and-save-class?
17:05jgracinto interact with Java frameworks.
17:05rhickeyjgracin: folding genclass into AOT is next
17:06jgracincool!
17:06NafaiThis is exciting
17:08AWizzArdMy new signature for usenet (like comp.lang.lisp): "Lisp is not dead. It's just the URL that has changed: http://clojure.org&quot; :-)
17:08hoeckhaha
17:09NafaiAWizzArd: Nice!
17:11ChouserAWizzArd: can I put that on a shirt?
17:11AWizzArdof course
17:11kib2AWizzArd: excellent
17:13Chouserhttp://www.zazzle.com/i_get_more_done_when_im_lazy_clojure_shirt-235544064302391169
17:14AWizzArdhehe
17:19rhickeyFrom Stuart Halloway's book: "Clojure feels like a general-purpose language beamed back from the near future"
17:20H4nsi like the book so far, it is quite an easy read and conveys a lot of information.
17:21ZakThough I think any general-purpose language in an early stage of development SHOULD feel like it comes from the future.
17:21AWizzArdrhickey: yeah, a job well done.. even small details are nice, like when-not vs. unless. I already told Chouser that for me (as a non-native speaker) a translation was needed.. I always read "unless" as "when-not".
17:21H4nswhat i find a little disturbing is that it refers to the manual.pdf file in the google group, which is propably outdated today, but certainly in a few weeks.
17:22H4nsrhickey: have you ever considered adding a (or my) style sheet for the printable version of the wiki pages? that way, it would be easier to maintain a current version. my manual process was rather tedious.
17:25jgracinI'm trying to use Spring from Clojure. Spring has ClassPathXmlApplicationContext which loads resources from classpath. However, it cannot find anything. Only RT/ROOT_LOADER can getResource() stuff...
17:25jgracinwhich I would expect SystemClassLoader would.
17:26jgracinWhat am I doing wrong?
17:26jgracinbasically, (new org.springframework.context.support.ClassPathXmlApplicationContext "classpath:appcontext/spring-initial.xml")
17:26jgracinsays it cannot find resource
17:27jgracinand via RT it's there (minus "classpath:" prefix which is mandatory in Spring)
17:27jgracinand (.getResource (classLoader/getSystemClassLoader) can't find it either
17:31Chouserjgracin: are you using add-classpath instead of -cp on the command-line?
17:31hiredmanhave you tried it without the classpath prefix?
17:31Chouserhttp://www.zazzle.com/lisp_is_not_dead_shirt-235516896396062966
17:31jgracinChouser: yes
17:31jgracinoh, I get it
17:32jgracinChouser: thanks!
17:36rhickeyH4ns: my brother Tom is in charge of the style sheet stuff
17:36H4nsrhickey: so i could send him my suggested style sheet changes.
17:37rhickeyH4ns: he's heard, I think
17:38H4nsrhickey: ok.
18:04AWizzArdGuys, we should also see if we can make some additions to the computer language shootout in Clojure.
18:07Lau_of_DK(defn time-it
18:07Lau_of_DK [expr]
18:07Lau_of_DK (let [start (System/nanoTime)
18:07Lau_of_DK result (expr)]
18:07Lau_of_DK #^{:time (/ (double (- (. System (nanoTime)) start)) 1000000.0)}
18:07Lau_of_DK result))
18:07Lau_of_DKDrinks are on Rich for the person who spots the error? :)
18:10duck1123just guessing, result is evaluated in the let
18:10wwmorgan(expr) needs to be an IObj ?
18:10Lau_of_DKan IObj ?
18:11wwmorganyeah. If you passed in (fn [] 4) it'd break I think
18:12AWizzArdLau_of_DK: not wrong but evil: this function has only one arity but still you put it's parameter vector on a separate line (and not to the function name, where it belongs)
18:13wwmorganAlso #^ is reader syntax. You probably want with-meta
18:14H4nsAWizzArd: you are wrong. in clojure, the docstring goes between the function name and the argument vector, so it is not uncommon to put the argument vector on a new line
18:14wwmorganotherwise you're attaching metadata to the symbol result, when what you want is to be attaching metadata to the IObj result
18:15AWizzArdH4ns: yeah, only that there is no docstring.
18:15ZakDoes the new AOT compiler have the ability to generate a main method for the class files it creates (e.g. from an appropriately-named fn)?
18:15wwmorganthen that's the bug: there should always be a docstring
18:15Lau_of_DKdefmacro time
18:15Lau_of_DK "Evaluates expr and prints the time it took. Returns the value of
18:15Lau_of_DK expr."
18:15Lau_of_DK [expr]
18:15Lau_of_DK `(let [start# (. System (nanoTime))
18:15Lau_of_DK ret# ~expr]
18:15H4nsAWizzArd: i did not say that there is one. i said that in clojure, there is nothing wrong with putting a newline after the function name.
18:15Lau_of_DK (prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))
18:15Lau_of_DK ret#))
18:15H4nsLau_of_DK: would you consider using a pastebin?
18:15H4nslisppaste8: url
18:15lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
18:15Lau_of_DKThis is the original, and I just want to wrap the result around the return as meta
18:15hiredmanif you add a docstring that describes the bug, it is now a feature
18:15Lau_of_DKH4ns, no thank you
18:16H4nsLau_of_DK: thank you! very kind.
18:16Lau_of_DKH4ns, no probs :)
18:17wwmorganLau_of_DK: use with-meta instead of #^, but you still have the problem that expr has to be an IObj
18:18AWizzArdH4ns: it is also not wrong in CL, but not common. I can't see it being common in Clojure. When I look at Richs ants.clj or into the book by Stuart Halloway I see the parameters in the same line as the function name, as long there is no docstring present or the function has 2+ arities
18:18Lau_of_DKwwmorgan, can you just educate me on what IObj is ?
18:18H4nsAWizzArd: *shrug* i'm not the one to argue here. i'd just not claim that it is "evil"
18:19wwmorganLau_of_DK: this chart may be old but it should be accurate: http://clojure.googlegroups.com/web/chart.png?gda=0kdaHzsAAABoLitVpBTEcNIQc_NHg39SwaZsbT3VqBTlVOBvdHb7yiuq-FEWrXmgYiTWWcOQKecGRdr3QrylPkw2aRbXD_gF
18:19AWizzArdH4ns: well okay, when you present it like this then I agree that evil is maybe not the right word.
18:20wwmorganIObjs include vars, symbols, and clojure collections
19:03gnuvince_I am using HTMLParser to extract information from a web page. HTMLParser does not allow filtering the value of an attribute with a regular expression, so I need to use their visitor pattern method. The .visitAllNodesWith method returns void. How can I accumulate the tags I'm interested in into a collection? I'm using a proxy object for the method call: (proxy [NodeVisitor] [] (visitTag [tag] (what goes here?)))
19:05gnuvince_Global ref?
19:06Chouserwell, since it's all happening in a single thread (presumably) you could use (binding ...) and (set! ...)
19:07Chouserhave you considered tagsoup and zip-filter? That's how I've done web-page scraping.
19:07gnuvince_I looked at TagSoup.
19:07gnuvince_Didn't like it.
19:07gnuvince_There's no documentation on the website.
19:08Chouserok. It worked well for me because I could plug it into the clojure.xml parser and then use zip-filter on it.
19:08gnuvince_HTMLParser seems closer to what I want to do anyway.
19:09Chouserok
19:09gnuvince_How is binding different from let?
19:10Chouserbinding is dynamic rather than lexical
19:10gnuvince_ah
19:10gnuvince_this should be mentioned in the documentation stirng.
19:10gnuvince_string
19:10Chouserheh, yeah, perhaps. :-)
19:12gnuvince_I'm unsure how to use binding...
19:12gnuvince_Shouldn't: (let [x 10] (binding [x 20] (prn x)) (prn x)) work?
19:15hiredmangnuvince_: do you get unable to resolve symbol x?
19:15gnuvince_yes.
19:15gnuvince_well, var x
19:16hiredmannm
19:17hiredmanoh
19:17hiredmanyou need to create the var
19:17hiredmanbefore you can bind
19:17gnuvince_Isn't it created in the let?
19:18hiredman*shrug*
19:18Chouseryeah, now that I think about it, the differences between binding and let are more profound than just "lexical" and "dynamic"
19:18Chouserbinding is for vars. A var is a real object that manages mutable state. let creates an immutable local.
19:18hiredmanlet seems to override binding
19:19Chouserhiredman: shadow them, yes.
19:19hiredmanChouser: the s-exp gnuvince_ pasted prints 10 twice for me
19:19hiredmanso even inside the binding, x is still 10
19:20Chouser(def x) (defn px [] (println "x is" x)) (binding [x 10] (px))
19:21hiredmanyeah, now wrap the binding in a (let [x 20] ...)
19:21gnuvince_I'll paste the code in a couple minutes
19:21gnuvince_We'll see if binding could make it better
19:21hiredmanChouser: nm, my repl must be unclean
19:22Chouserhiredman: heh, ok.
19:31gnuvince_lisppaste8: url
19:31lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
19:31lisppaste8gnuvince pasted "html parser" at http://paste.lisp.org/display/70171
19:32gnuvince_Could this be improved (i.e. made more modular) with binding?
19:34gnuvince_Hmmm
19:34ChouserI don't think the structure of your code would be significantly different.
19:34gnuvince_I still need to pre-define imgs outside the let
19:34Chouseryou'd still need a (def imgs ...)
19:34Chouserright
19:35Chouserthough actually, you don't need that with ref
19:35Chouseryou could put your (ref []) inside your let
19:36Chousukehmm, is that a proper way to use refs? what if some thread alters the ref to point somewhere else between (empty? @imgs) and the rest?
19:36gnuvince_I don't know if it's the proper way
19:36Chousersimilarly you could use with-local-vars to get a local var and then use set!
19:37gnuvince_all I know is that .visitTag returns void.
19:37gnuvince_So I need to store my results *somewhere*
19:37Chousukemaybe you should do something like (let [images @imgs] ..
19:40gnuvince_Chouser: with-local-vars allows mutations?
19:41lisppaste8Chouser annotated #70171 with "a couple untested alternatives" at http://paste.lisp.org/display/70171#1
19:41Chousergnuvince_: yep
19:42Chouserboth those alternatives should satisfy Chousuke -- no external access to imgs, so no way some rogue thread could mess you up.
19:45sohailis there a ctypes for java?
19:45ChouserJNA
19:46sohailthat's the one
19:46Chousersohail: http://groups.google.com/group/clojure/browse_thread/thread/77e626c5440bf1a0
19:46sohailhave any experience with it Chouser ?
19:46gnuvince_Chouser: thanks for the help
19:46Chousergnuvince_: np!
19:46Chousersohail: nope, just what abrooks has told me.
19:46gnuvince_Your first suggestion is what I should've thought of :-/
19:46sohaillooks good
19:47gnuvince_I'm embarassed
19:47sohailthat's nothing
19:47gnuvince_By the way, does this style of coding happen to anyone else: lots of things in the let declaration, but only a few lines in the actual body?
19:48sohailone time in grade 3, we were supposed to change for gym and I thought I had my shorts underneath my pants
19:48gnuvince_sohail: ok, that's more embarassing
19:48sohailit is
19:50gnuvince_I've had the good fortune to repress all bad childhood memories.
19:50gnuvince_Maybe that,s why I couldn't remember this...
19:50gnuvince_Maybe this conversation has happened before!
19:50danlarkinfreaking deja vu!
19:53Chousergnuvince_: sometimes, yes. Feels kind of imperative, doesn't it.
19:53Chouseryou know it's really bad when you start re-using the same name
19:54gnuvince_Chouser: it does, but is it really better to have a 6 line expression like people in Haskell sometimes end up with
19:54Chouser(let [x 10 x (/ x 5) x (replicate x x) x (map inc x)] x)
19:54Chousergnuvince_: yeah, I don't know.
20:31lisppaste8Chouser annotated #70171 with "tested alternative using zip-filter" at http://paste.lisp.org/display/70171#2
20:32Chousernot the most impressive showing for zip-filter, I'll admit.
20:33gnuvince_What's zip-filter?
21:01Chouserclojure.contrib.zip-filter, for selecting particular nodes from a zip tree.
22:02bradbevhow does one do modulus in Clojure? ie, 2 % 5
22:04duck1123_rem
22:04hiredmanmod
22:04bradbev(rem ...)
22:04bradbevthanks :)
22:04hiredmanbah, that is horrible
22:04hiredmanI was so sure I knew the answer
22:05bradbevI expected mod also
23:43sohailChouser, jna is pretty awesome man :-)
23:43sohailno messy JNI needed
23:43sohailjust like cffi from CL
23:47NafaiAny decent language has a built in FFI :)
23:49sohailit was only a matter of time before someone did it for Java
23:49sohailthough CL doesn't have a cffi
23:49sohail*ffi
23:50NafaiProbably more correct to say any decent language implementation