#clojure logs

2010-06-27

00:00polypusall that said, my fantasy is a lightweight gedit/textmate like editor with paredit written in and scriptable in clojure
00:16itistodayi think i know why you guys like paredit so much, it's because you stack up your parenthesis instead of using them to specify scope like braces in C
00:17itistodayor rather, i bet that's one of the major reasons
00:32itistodaynight!
00:43TeXnomancyI know I'm late, but I think the reason people balk at having parens on their own line is that it makes it obvious that you're still counting them manually
00:44TeXnomancyif you just go with the flow and let paredit handle your parens then you don't care how many there are... why waste space on them?
00:45TeXnomancydid they ever get those windows issues figured out?
04:40quizmeapprox. how much memory does it take to deploy ring on a 64-bit Ubuntu box?
05:38LauJensenGood morning all
05:39patrkrismornin'
05:45BahmanMorning LauJensen!
10:40polypus,(= (fn []) (fn []))
10:40clojurebotfalse
10:41polypusis that false guaranteed to always be the case?
10:49Chousukepolypus: should be, as functions do an identity comparison
10:49polypusChousuke: ty. thought so.
10:51polypusfor a larger datastructure, is it's hash (or whatever is compared in an identity equality), cached?
10:52polypusi assume so given that DSs are immutable
10:52ChousukeHmm, I'm not sure if Clojure does anything like that
10:58polypusmornin all, btw
11:25mmarczykpolypus: yeah, hash codes are cached
11:25polypusmmarczyk: ty
11:30systayI'm having a problem where if I do an action on one item in the seq, everything works fine. when I try to do it on all of the items using map, I get a "org.neo4j.graphdb.NotInTransactionException: No transaction found for current thread". Could it be that clojure is running stuff in multiple threads without telling me about it?
11:39polypussystay: probably you are not cosuming your whole seq inside the transaction. try wrapping it in a dorun or doall.
11:40polypusyou can get simlar errors with binding in pure clojure, i got bit by that the other day. won't forget it
11:40polypuss/cosuming/consuming
11:53systaypolypus: I solved it by wrapping the function map was running in a transaction. it feels sub-optimal, but speed is not an issue right now. I'll try the doall though
11:57polypussystay: yeah probably is suboptimal, try (transaction (dorun (map ...)))
11:58systaypolypus: but dorun returns nil, right? I think I want doall
11:58polypusyeah, if you need the head doall
11:59systaypolypus: that worked wonders. thanks! :)
11:59systaylazy is tricky to wrap my head around
12:00polypussystay: np :) once you get bit enough times you won't forget :)
12:05systayI love clojure. It's soooo refreshing to work in it, compared to my dayjob...
12:05polypuswoot
14:34serp_does clojure have support for some kind of event system? I would like to somehow register a function with an event and get have it become called when the event is triggered
14:40Chousukeserp_: there are watchers for reference types.
14:41serp_yes, but that's not exactly what I want.
14:41serp_I guess I could have a dummy reference for each event type, but that doesn't feel too clean
14:47semperosswank/slime confusion
14:47semperoshave very simple hard-coded grammar (copy from Paradigms of Artificial Intelligence Programming in Clojure): http://lisp.pastebin.com/LfRBQFD4
14:48semperoswrote it as part of a lein project, under src/hardcoded_grammar.clj
14:48semperosstarted swank with lein swank from project root
14:48semperosconnected with slime (M-x slime-connect) in emacs
14:48semperosat repl, did (use 'pai.hardcoded-grammar)
14:49semperosget normal output for simple functions like (noun) and (article)
14:49semperosbut when I call the (noun-phrase) or (verb-phrase) functions, it's as if the str-utils2 (join) function doesn't work correctly
14:49semperosoutput like "aman" instead of "a man"
14:49semperosif I follow the same process running a simple clojure + clojure-contrib inferior lisp process
14:49semperosand use my file
14:49semperosthose functions work as expected
14:49semperos"a man"
14:50semperosany thoughts? (and apologies for lengthy expl.)
14:58polypuswhat's the advantage of == over = for numbers, performance?
15:01jcromartieso I had this latent thing in the back of my mind that was bothering me
15:01jcromartiewhen working in most OOP languages I usually use really long variable names
15:02jcromartiebut in Clojure one word or one letter is usually fine
15:02jcromartiebut it bothered me to see such short identifiers
15:02bobo_polypus: depends on if you want 2.0=2 to be true or not.
15:02bobo_if i understood it correct
15:02qbgjcromartie: Several functional languages do that
15:02jcromartieso I had this cognitive dissonance because it's been ingrained that "identifiers should be more descriptive"
15:03jcromartiebut the thing that I realize is: in FP, identifiers describe simpler things
15:03jcromartielike simple values
15:03polypusserp: see http://richhickey.github.com/clojure-contrib/dataflow-api.html
15:04polypusserp_: also http://github.com/gcv/dgraph
15:04polypusserp_: also http://github.com/straszheimjeffrey/dataflow
15:05polypus,[(= 2.0 2) (== 2.0 2)]
15:05clojurebot[true true]
15:05polypusbobo_: no diff
15:05serp_polypus: was those links really for me?
15:07polypusserp_: yeah, may be of use depending on your problem
15:11serp_I don't understand how it is related, but I'll have a look. thanks
15:13polypusserp_: (let [registered (atom [])] (defn register [f & args] (swap! registered conj [f args])) (defn fire [] (doseq [[f args] @registered] (apply f args))))
15:21serp_polypus: that would work. I wonder though, since it's not built-in, if I am trying to force clojure into doing something it doesn't want to do
15:23serp_I'll ponder some more..
16:05systay,(doc ==)
16:05clojurebot"([x] [x y] [x y & more]); Returns non-nil if nums all have the same value, otherwise false"
16:05systay,(doc =)
16:05clojurebot"([x] [x y] [x y & more]); Equality. Returns true if x equals y, false if not. Same as Java x.equals(y) except it also works for nil, and compares numbers and collections in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison."
16:53LauJensen,(do (println (= [1 2 3] [1.0 2.0 3.0])) (println (== [1 2 3] [1.0 2.0 3.0])))
16:53clojurebotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number
16:54LauJensen,(clojure-version)
16:54clojurebot"1.2.0-master-SNAPSHOT"
16:54LauJensen$(do (println (= [1 2 3] [1.0 2.0 3.0])) (println (== [1 2 3] [1.0 2.0 3.0])))
16:54sexpbotjava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.Number
16:54LauJensenOdd
16:54mmarczykcan't use == with vectors
16:54LauJensenmmarczyk: Works fine locally, prints true \n false
16:55mmarczykreally? now *that* is odd :-)
16:55polypusi want to repeatedly drop items from a sequential collection at given inices. i never have to re-add items to the collection. which collection would be most performant, and is there a single function which drops at a specific index, cuz i can't see one.
16:55polypuss/inices/indecis
16:56mmarczykLauJensen: which branch?
16:57LauJensenmaster, 1.2 snapshot
16:57polypusLau: yeah i thought i remembered that behavior. i get the cast exception noe that i updated
16:57polypusnow*
16:57LauJensenoh ok, its just me thats still in the old-school then
16:59mmarczykahh, wait, right
17:00mmarczykbut the old behaviour was that it would *always* return false
17:00mmarczykeven for, say, (== [1 2 3] [1 2 3])
17:01polypusmmarczyk: i think i remember it returning true, but i may be wrong
17:01mmarczykbasically clojure.lang.Numbers.equiv had an overload returning false in absence of a better idea
17:02LauJensenpolypus: perhaps you could use replace to alter your collection
17:02LauJensen,(replace {1 5 2 6} [1 2 3])
17:02clojurebot[5 6 3]
17:02mmarczykhttp://github.com/richhickey/clojure/blob/1.1.0/src/jvm/clojure/lang/Numbers.java#L181
17:03mmarczykso if either x was not a Number or y was not a Number, false would be returned with no actual comparison being performed
17:03mmarczykthat's 1.1; I don't remember anything in between that and the current behaviour, but that might be a lapse in my memory
17:04LauJensenDont think there has been any change
17:04mmarczykpolypus: as in (drop-every-nth 3 [1 2 3 1 2 3]) => (1 2 1 2) ?
17:05mmarczykpolypus: or actually generalised... (skip-at [2 5] [1 2 3 1 2 3]) => (1 2 1 2)
17:06mmarczykpolypus: or are you hoping for efficient access by index after you drop an item?
17:06polypusmmarczyk: no, i need to drop some arbitrary index from the collection in a loop where i don't know before hand the index
17:06LauJensenpolypus: Do you only have the index, or the value as well ?
17:06polypus(loop [c coll] (recur (drop-some-index 0 coll))
17:06polypusonly the index
17:07mmarczykpolypus: well ok, but how do you work with the collection? do you generally go left-to-right, while occasionally needing to mark an item n slots ahead for skipping, or do you use it as a vector, where efficient lookup by index is required?
17:09polypusefficient lookup is required, i guess i should use a map huh?
17:09LauJensenOr a set if possible
17:09mmarczykyeah, one idea would be to use a (sorted-map) with numeric keys, dissoc for item removal, subseq to start a sequential walk at a given index
17:10mmarczyk$(seq (sorted-map 1 :a 2 :b 3 :c))
17:10sexpbot=> ([1 :a] [2 :b] [3 :c])
17:10mmarczyk$(seq (dissoc (sorted-map 1 :a 2 :b 3 :c) 2))
17:10sexpbot=> ([1 :a] [3 :c])
17:11LauJensenWould something like this work?
17:11LauJensen(defn drop-idx [idx coll] (reduce #(if (= (key %2) idx) %1 (conj %1 (val %2))) [] (zipmap (range (count coll)) coll)))
17:11clojurebotinits is http://paste.lisp.org/display/63514
17:11mmarczyk$(subseq (dissoc (sorted-map 1 :a 2 :b 3 :c 4 :d 5 :e) 2) <= 2)
17:11sexpbotjava.lang.ClassNotFoundException: clojure.core$mk_bound_fn$fn__4192
17:11mmarczykhuh? whatever
17:12mmarczykwould have been a better example with >= anyway
17:12polypusok, ty guys. i have to copy paste this stuff and digest a bit. my situation is actually slightly more complicated than i stated cuz i have two collections which are both indexed by the same indices, but which are used in different ways.
17:13LauJensenalright :)
17:14mmarczykah, the sorted-map would of course not reindex itself properly...
17:14mmarczykanyway, good luck & have fun :-)
18:18Raynesmmarczyk: Another one of those stupid bugs. I guess I'll spend all day tomorrow with Licenser. See if we can figure out what is causing that thing.
18:18mmarczykRaynes: always happy to put yummy bugs on your plate ;-)
18:19RaynesIt's the same thing that causes rseq and iterate to fail.
18:20RaynesIt's subseq causing it in this particular situation.
18:20mmarczykRaynes: how about whitelisting clojure.core/mk-bound-fn?
18:20Raynes$(rseq [1 2 3])
18:20sexpbotjava.lang.ClassNotFoundException: clojure.lang.APersistentVector$RSeq
18:21RaynesIt's not *exactly* the same. But you might be on to something, I suppose.
18:21Raynes$(take 3 (iterate inc 0))
18:21sexpbotjava.lang.NoClassDefFoundError: clojure/core$iterate$fn__3750
18:21RaynesHrm, it is differen't.
18:21Raynesdifferent*
18:21mmarczyknot sure how you'd go about whitelisting inner classes
18:21RaynesI don't think that's it though.
18:22RaynesBecause it still works when it's not started up with swank.
18:22RaynesWhich is isane.
18:22Raynesinsane* /me can't type today.
18:23mmarczykhm, right
18:24Raynesmmarczyk: I can fix it dirtily by just running it through the shell script instead of a swank server, but that sucks, because I don't get to muck with it as much.
18:25mmarczykyeah, I can see that
18:25RaynesI mean, I can still live-update because I have a reload command for reloading plugins, but still.
18:25mmarczyksure
18:27mmarczyk$(clojure.lang.Var/intern "clojure.core" "foo")
18:27sexpbotjava.lang.SecurityException: Code did not pass sandbox guidelines: ()
18:27RaynesI'll go ahead and do that for now.
18:27mmarczykso ClassNotFound isn't likely to be whitelist-related
18:27mmarczykI guess
18:28Raynesmmarczyk: The next thing I need to test is whether or not a fresh sandbox is working via a swank server with rseq and friends.
18:28RaynesIf it is, then something is wrong with sexpbot.
18:28mmarczykgood idea
18:28RaynesIf not, I can just throw it on Licenser's plate. :D
18:29mmarczyk:-)
18:29Raynes$(rseq [1 2 3])
18:29sexpbot=> (3 2 1)
18:29RaynesEnjoy. <3
18:29mmarczyk:-)
18:30RaynesI'd rather not run it in swank than have people not like sexpbot because half of everything is broken. :p
18:31RaynesAlso, that thing you tried to do earlier should work now. $#(subseq (dissoc (sorted-map 1 :a 2 :b 3 :c 4 :d 5 :e) 2) <= 2)#$
18:31sexpbot=> ([1 :a])
18:36mmarczykohhh, $#(:is-this-cool? (reify clojure.lang.ILookup (valAt [_ _] true)))#$
18:36sexpbotjava.lang.NullPointerException
18:36mmarczykhuh?, again
18:36RaynesThat's your bug, not mine. :p
18:37mmarczyknot at all, works at my repl
18:38RaynesThat's weird.
18:38Raynes,(:is-this-cool? (reify clojure.lang.ILookup (valAt [_ _] true)))
18:38clojurebottrue
18:39RaynesLicenser: ^ ping
18:39mmarczyk:-)
18:39RaynesIt still isn't my bug.
18:39RaynesIt's his! :p
18:39RaynesI'll gist it and show him later.
18:43mmarczykgood, making clj-sandbox more robust is a great service to the community :-)
18:43RaynesIndeed. Just making it work is a service to the community. >_>
18:46mmarczykthat's another valid way of putting it ;-)
19:09lancepantzhey guys
19:10lancepantzanyone know binding that makes the *slime compilation* buffer disappear after a compile error?
19:12rfgC-x k :)
19:12rfgWell C-x o then C-x k
19:12lancepantzbut then you have to type in the name of a buffer
19:13rfglancepantz: I would also like to know.
19:15lancepantz:/
20:19lancepantz,(let [foo {:a 1 :b 1 :c nil}] (into {} (filter #(not (nil? (val %))) foo)))
20:19clojurebot{:a 1, :b 1}
20:19lancepantz^ anyone know of a more idiomatic way to remove nil values from maps?
20:20tomojremove is at least a bit more idiomatic
20:21tomoj,(into {} (remove (comp nil? val) {:a 1 :b 1 :c nil}))
20:21clojurebot{:a 1, :b 1}
20:21tomoj(filter val ..) works if you don't have to bother about false
20:22lancepantz,(into {} (remove (comp nil? val) {:a 1 :b 1:c nil :d false}))
20:22clojurebotInvalid number: 1:c
20:22lancepantz,(into {} (remove (comp nil? val) {:a 1 :b 1 :c nil :d false}))
20:22clojurebot{:a 1, :b 1, :d false}
20:22tomojvs:
20:22tomoj,(into {} (filter val {:a 1 :b 1 :c nil :d false}))
20:22clojurebot{:a 1, :b 1}
20:23lancepantzoh, i follow
20:23lancepantzcool, thanks tomoj
20:57Lajlatomoj, I challenge you to become a greater programmer than I.
21:04defnI issue a formal challenge to try and write code as poor as mine.
21:05Lajladefn, give me a sample code.
21:05defnLajla: That was a joke, bub.
21:05LajlaI issue a formal challenge to prove that evolution happens according to MY demands.
21:05LajlaWhich includes that rock magically can turn into human beings, this is what evil satanic scientists believe.
21:07tomoj<3
23:05tomojlein-js was disappointing :(
23:11somniumwhat is it?
23:12somniumomg
23:13somniumhttp://benfirshman.com/projects/jsnes/
23:13somnium(found searching for lein-js on github)
23:14tomojit just copies src/js to war/js or something trivial like that
23:43maravillassorry tomoj, i'm just messing about with stuff
23:43maravillasmy plans are to wrap up juicer
23:44tomojno reason to be sorry
23:44tomojI was just puzzled at what strange thing could come out of combining leiningen and javascript
23:44maravillasah :)
23:45BahmanHi all!