#clojure logs

2011-05-30

01:49seancorfield__evenin'
01:49seancorfield__i have a string and want to load and execute a specific function from a namespace based on the string
01:50seancorfield__basically i want (stringA/stringB 42) to execute given two arbitrary strings
01:54seancorfield__i can get a symbol for the namespace and require that
01:55seancorfield__but i can't figure out how to get the function as a qualified symbol
01:55amalloyseancorfield__: resolve
01:55seancorfield__ah, bingo! resolve
01:55seancorfield__jinx
01:55seancorfield__but thanx
01:56amalloy(PS it won't work for *any* two strings like if stringA is 42. but you knew that)
02:00seancorfield__i'm porting my CFML MVC framework to Clojure
02:02seancorfield__it auto-maps /uri/routes to controllers and methods so i'm just playing with ring and figuring out how to calls methods in namespaces based on routes without predefinition
02:08amalloyseancorfield__: have you considered looking at geni's new product, wakeful?
02:09amalloyit's still very new, but i think it already does what you describe
02:09amalloyhttps://github.com/ninjudd/wakeful
02:11seancorfield__that's part of what FW/1 does but not enough :)
02:11amalloysure, of course you want more for a full mvc. but reuse or steal some of it
02:11seancorfield__i'll look at the source code for "ideas" :) thank you!
02:22seancorfield__interesting approach...
02:22seancorfield__why does it use ns-resolve instead of plain resolve?
02:23seancorfield__(or should i just go read the docs :) )
02:23amalloy&(doc ns-resolve)
02:23sexpbotjava.lang.SecurityException: You tripped the alarm! ns-resolve is bad!
02:23amalloy,(doc ns-resolve)
02:23clojurebot"([ns sym]); Returns the var or Class to which a symbol will be resolved in the namespace, else nil. Note that if the symbol is fully qualified, the var/Class to which it resolves need not be present in the namespace."
02:23amalloy,(doc resolve)
02:23clojurebot"([sym]); same as (ns-resolve *ns* symbol)"
02:23seancorfield__ah, ok
02:24seancorfield__i'll need ns-resolve to make fw/1 work then... thanx...
02:24amalloyseancorfield__: no, you could do it with resolve if you wanted
02:24amalloyby reconstituting a single symbol out of two strings, as you were doing
02:25amalloyin fact because ns-resolve wants a namespace, not a string/symbol *denoting* a namespace, plain resolve might be more convenient for your needs. one enver knows
02:26seancorfield__'k thanx... i'll have to keep pushing ahead and see how things work out
02:27seancorfield__my biggest question mark right now is what to do about views... CFML allows code in the HTML template (which I don't like much) but i'm not sure i like enlive's complete separation either
02:27seancorfield__so i haven't figured out how that should pan out yet
02:52thorwili copied my project, removed enlive to replace it with hiccup. did "lein clean" and "lein deps". cleared classes.
02:52thorwilnow i get fun stuff like "java.lang.NoClassDefFoundError: appengine_magic/services/datastore/EntityProtocol (models.clj:39)"
02:52thorwilor "java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:0)"
02:57thorwilnevermind, after clearing classes again, now it works, so i must have had the order wrong
02:59thorwilif only things would be rebuild from scratch if they have to, automatically
03:05amalloythorwil: if that problem were as simple as you make it sound, i'm sure it would work perfectly already
03:08thorwilwhat, (when have-to rebuild) doesn't do it? :)
05:53thorwilwith this short defhtml, http://paste.pocoo.org/show/397592/ hiccup does not produce the <dt>
05:53thorwilwhat am i overlooking?
05:55thorwili already confirmed that l and p have the expected values
06:04thorwilso it returns only the last vector, but i can't put [] all around it :/
06:04hoeckthorwil: that let only returns the last vector [:dd ]
06:05hoeckthorwil: why not?
06:05thorwilbecause java.lang.IllegalArgumentException: [:dt "Updated:"] is not a valid tag name. (NO_SOURCE_FILE:0)
06:09hoeckcan you somehow change the way hiccup handles this? e.g. instead of using a the defhtml macro write a function that returns a vector of tags and insert this into your resulting html tree?
06:11hoeckthorwil: looking at the code, it sould work when you return a seq or list of tags
06:12hoeckthorwil: http://paste.pocoo.org/show/397597/
06:13hoeckah, screw that, I'm wron
06:13hoeckg
06:14thorwilno, works
06:14thorwilthanks, hoeck
06:15thorwiland here i was about to create a defn only to call the defhtml ...
06:16hoeckdefhtml just creates a fn wrapping the body in a (html ...) form
07:25ilyakHi *
07:25ilyakI have a (fn
07:25ilyakHow do I call itself recursively?
07:25ilyak(I know about Y combinator but that's not the point)
07:26ilyakSpecifically, I have a (fn ([arg] (do-something-with arg)) ([] (recur nil))) and it doesn't work
07:26ilyakHow can I recur to another arg-branch? I thought I can
07:27raekilyak: you can name the anonymous function like this: (fn f [...] ...). f will refer to the function itself in the scope of its body
07:27raek,((fn f [] f))
07:27clojurebot#<sandbox$eval3012$f__3013 sandbox$eval3012$f__3013@1acb7>
07:28lucianraek: i love that neat trick. more languages should have it
07:28raek,((fn f [n] (when (pos? n) (cons n (f (dec n))))) 5)
07:28clojurebot(5 4 3 2 1)
07:46ilyakIs it possible to make a finite lazy seq from function?
07:47ilyakLike with (repeatedly), but end the sequence when f returns nil
07:49hoeckilyak: (take-while identity (repeatedly ...))
07:50ilyakhoeck: Yeah, thanks, figured it out
09:51SergeyDhi! Is there an opposite of "{:keys [key1 key2]} my-map" destructuring? I mean the way to rewrite (merge map1 {:key1 key1 :key2 key2 :key3 key3}) to make it shorter, i.e. not to repeat keyX twice
10:03raekSergeyD: not really. the names of the locals are not available at runtime.
10:04raekSergeyD: so that means no function can do it, but in fact a macro could
10:05raekalso, (merge m {:a 1, :b 2}) is more commonly written as (assoc m :a 1, :b 2}
10:05SergeyDraek, yes, I mean a macro or the reader functionality.
10:05SergeyDraek, thanks, I have missed the fact that assoc takes multiple key-value pairs.
10:07raekSergeyD: (defmacro make-map [& names] {:pre (every? symbol? names)} (zipmap (map keyword names) names))
10:08SergeyDraek: thanks :)
10:08raekthis will of course only work if the local variables have exactly the same names as the keys
10:09raekso (make-map (inc a) (inc b)) doesn't make sense
10:10raek(hrm, apparently preconditions don't work in macros as I though...)
10:11SergeyDAnd I have just thought what a cool way to use preconditions )
10:21sn197hi there, are there any cases where (func arg) does not produce the same result as (-> arg func)
10:23sn197for example "(-> [1 2 3 4 5 6] (partial take 2))" yields a different result than "(-> [1 2 3 4 5 6] (partial take 2))". Why?
10:25manuttersn197: re-read what you just typed :)
10:25SergeyDsn197: did you wrote the same code twice?
10:25manutteryou mean the -> version produces a different result than ((partial take 2) [1 2 3 4 5 6]) ?
10:25sn197oops, I meant that the result is different compare to "((partial take 2) [1 2 3 4 5 6])". Bad paste job
10:26manutterOk, your question makes more sense now
10:26manutterbut those should produce the same result
10:26sn197I agree but they don't. I am puzzled
10:27raeksn197: (-> [1 2 3 4 5 6] (partial take 2)) expands to (partial [1 2 3 4 5 6] take 2)
10:28SergeyDsecond that :)
10:28manutterHeh, that's subtle, but I see it now
10:29raek-> does not work with function and applications per se, it just rewrites expressions
10:29sn197aha, one has to be careful then because it's not obvious
10:29manutterIndeed
10:30sn197thanks guys, off to write more clojure code...
12:46ilyakSuppose I have defrecord-ed org.foo.Record
12:46ilyakHow do I get :Record from the instance of that?
12:53ilyak(keyword (.. r getClass getSimpleName))?
12:53ilyakIs there a less pityful way?
12:53opqdonutthat seems like a good solution IMO
12:56ilyakI have (defmulti muz-ru-element identity)
12:56ilyakThen I try to run (muz-ru-element [:foo :bar])
12:56ilyakand it fails with "Wrong number of args (2) passed to: core$identity"
12:56ilyakIs it a bug or feature that it explicitly destructurizes my list? How to combat?
13:03ilyak(defmethod syntax is strange
13:04ilyak:default accepts default dispatch value
13:04ilyakwhy not the default dispatch fn?
13:10ilyakIs there a function that returns the first arg and does nothing else?
13:18cemerickilyak: if your fn accepts rest args, then use first (fn [& args] (first args))
13:18cemerickwhich is equivalent to #(first %&) if you prefer the literal syntax
13:19ilyakcemerick: My form was (fn [x & xs] x)
13:19cemericksure, same thing
13:22danlarkindakrone: good news! pull request merged
13:23dakronedanlarkin: excellent!
15:28bprI'm writing a protocol, and I'd like one of the types i'm extending to be function. In the extend form what do I put for the type?
15:30gfrlogbpr: you're talking about one protocol inheriting from another?
15:30bprwell, i've written a protocol, and I want to extend some existing types to use it
15:31bprand one of those types is function
15:31gfrlogI know IFn is the clojure interface for functions
15:31gfrlogyou want anything that is an IFn to implement your protocol?
15:31bprthanks, that should do
15:31gfrlogokeedokes.
15:31bpryes
15:31gfrlog,IFn
15:31clojurebotjava.lang.Exception: Unable to resolve symbol: IFn in this context
15:31gfrlog,clojure.lang.IFn
15:31clojurebotclojure.lang.IFn
15:32bprthank you
15:32gfrlogyep
15:32bprthat's what I was clumsily trying to ask :-p
15:33gfrlogI just wish I understood protocols well enough to know what you're doing :)
15:35bpryeah, i had to watch a number of talks about protocols before I rly got it. Stuart Halloway has a good one
15:35bpriirc it's titled "Solving the Expression Problem"
15:36bprgoogling for "clojure expression problem" should bring it up. It's on vimeo
15:36gfrlogthe talk called "Protocols"?
15:36bprmaybe
15:36bprlet me find the link
15:36gfrlog$google clojure expression problem vimeo
15:36sexpbotFirst out of 200 results is: Clojure 1.2 Protocols on Vimeo
15:36sexpbothttp://vimeo.com/11236603
15:37gfrlogthat is what I'm looking at
15:37kencauseyclojure.blip.tv
15:37bprhttp://vimeo.com/11236603
15:37bpryup, u got it
15:38gfrlogcool, thanks. I'm on it.
15:44Bronsacan someone explain me why this is happening? http://sprunge.us/gMQT?cl
15:48ChousukeBronsa: .. is a special form and doesn't work like that.
15:48Chousukeit requires a class name as the first argument
15:49Bronsaso, in order to do that the only way is to create a macro?
15:49ChousukeBronsa: java Class instances have .newInstance methods
15:50ChousukeThough if it's specifically the EMPTY constant you need, then I'm not sure what you need
15:50Chousuke:P
15:57gfrlog,(doc sort)
15:57clojurebot"([coll] [comp coll]); Returns a sorted sequence of the items in coll. If no comparator is supplied, uses compare. comparator must implement java.util.Comparator."
15:57gfrlogIf I want to write a fn to pass in as a java.util.Comparator, I should use proxy?
16:41technomancygfrlog: nah, just pass the function to clojure.core/comparator
16:48gfrlog,(doc comparator)
16:48clojurebot"([pred]); Returns an implementation of java.util.Comparator based upon pred."
16:48gfrlogthat's some weak docs right there
16:51gfrloghad to look at the source code to confirm that it meant what I thought it did
17:26imadeI'm having difficulties with eval, please take a look https://gist.github.com/999502
17:27billy_can't seem to figure out why this is saying class not found - http://pastebin.com/xQRJcREz
17:35imadebilly_: did you do 'lein deps' ?
17:37billy_imade: yup
17:37raekimade: eval evaluates at the top level, so it can't use local variables
17:37raekimade: are you sure you actually need eval here?
17:37imadehow else can I dynamically build up such a for loop to yield the desired result
17:38raekimade: a macro?
17:38imadeookey, I need to go read a tutorial about macros then, thanks :)
17:40billy_hmm
17:40billy_apparently the jar lein pulled in is no good
17:40billy_wierd
17:41imadecan clojars find jcurses 1.0.0 ?
17:41raekbilly_: maybe you could try this version: http://www.jarvana.com/jarvana/archive-details/com/baulsupp/kolja/jcurses/0.9.5.3/jcurses-0.9.5.3.jar
17:41billy_i found a working version
17:41raekjcurses is a java project, right?
17:41billy_yea
17:41billy_jcurses 1.0.0 is in clojars
17:42billy_it doesnt appear to work though
17:42raekthen the authors are probably not pushing it to clojars
17:43raekleiningen accesses the central maven repo too, where most of the java libs are
17:43technomancybilly_: I think it's intended to be used with native-deps rather than regular :dependencies
17:43technomancythere is probably some weird jar-in-a-jar stuff going on
17:43billy_technomancy: hmm i didnt know there was such a thing, ill try that
17:44technomancybilly_: it's going to be merged into Leiningen 1.6, but that's still a work in progress
17:45technomancythere aren't any good conventions for distributing native libraries on the JVM yet
17:52billy_technomancy: thanks for the help, clears up all the confusion regarding that
17:59aav-$seen lpetit
17:59sexpbotlpetit was last seen quitting 5 days and 6 hours ago.
18:43nanarpussCurious if anybody knows of a good OAuth library?
19:38Raynesnanarpuss: I've used clj-oauth. It's good.
19:42bdeshamhi all. simple question: I have a list like ((:foo :bar) (:baz :xyzzy)) and I'd like to turn it into (:foo :bar :baz :xyzzy). how can I do this?
19:43amalloy&(apply concat [[1 2] [2 3]])
19:43sexpbot⟹ (1 2 2 3)
19:44darevay&(flatten [[1 2][2 3]])
19:44sexpbot⟹ (1 2 2 3)
19:44amalloydarevay: NO
19:44darevay...which might be too agressive
19:44darevayenlighten me
19:44bdeshamamalloy: great, thanks! I knew it had to be something simple
19:44tomojthis is amalloy's thing
19:44amalloy&(flatten [[[1 2] [3 4]] [[5 6] [7 8]]])
19:44sexpbot⟹ (1 2 3 4 5 6 7 8)
19:45darevaywhich might be what you want :)
19:45bdeshamdarevay: I thought of that but I've actually got vectors in this thing that I need to preserve :-)
19:45tomojit's always the same pattern "I have a list like ...". the question is, _why_ do you have a list like that?
19:45amalloydarevay: sure. on rare occasions that is what you want
19:46darevayI guess that's true. Now that I think of it, I rarely use flatten.
19:47bdeshamtomoj: well, if you're curious... I have a vector like [[(:a :b :c) 3], [(:d :e) 5]] and I'd like to turn it into [[:a 3], [:b 3], [:c 3], [:d 5], [:e 5]]
19:47bdeshamwhich I just figured out how to do ;-)
19:47tomojok
19:47gfrlogthat looks like a good use case for mapcat
19:47darevayNow I at least know how to push amalloy's buttons though :p
19:48tomojmy point is just that framing things like "I have this data and want this data" is less likely to lead to enlightenment
19:48tomojI mean, you learn stuff in getting it done
19:49tomojbut often you'll get better help with more context
19:49gfrlog(mapcat (fn [[ks v]] (for [k ks] [k v])) data)
19:50bdeshamgfrlog: ah, that does exactly what I want! thanks
19:53gfrlogcool
20:09bdeshamtomoj: http://www.perlmonks.org/?node_id=542341
20:25amalloygithub looks like they'll have their one millionth public gist today. we should have a gist-fest to see if we can get clojure to be the language of that gist
20:26bpr`wow, 1 million already? How long have they had gist?
20:26gfrlogdo they have bot deterrents?
20:26amalloybpr`: dunno. they say they've had 250k or so public gists this year
20:27amalloyhttps://gist.github.com/gists
20:27amalloyand afaik from looking at the monthly stats, they mean since january, not since last june
20:30tomojgiven a zipper loc, how do you do a depth-first iteration of the descendants of the loc?
20:31tomojwell, go next until you see right?
20:32tomojno, need to look up too..
20:36FrozenlockGentlemen, I'm in need of some kind of tutorial. I'm offering 20 BTC (~180$ @ current rate) as a bounty if you can help me. Details here: http://forum.bitcoin.org/index.php?topic=10740.0
20:36FrozenlockI hope I'll be giving this to one of you soon ^^
20:39bpr`BCs are worth $9?
20:40tomojFrozenlock: I have no clue after reading that what you are actually trying to do, other than get a clojure dev environment set up
20:40FrozenlockPretty much yeah
20:41gfrlogthere are Java libraries for the networking stuff?
20:41bpr`is there some site acting as a central market for BC?
20:42Frozenlockbpr`: http://bitcoinwatch.com/ for current price. Central market would probably be Mtgox
20:43Frozenlocktomoj: I have some BACnet devices. I want to be able to interact with them with my LAN.
20:43FrozenlockThere is some java libraries for Bacnet, but I have no clue how to use them
20:43Frozenlock...and interact with ethernet with clojure
20:44FrozenlockLike I said: I`m awful :p
20:45FrozenlockWas I more clear?
20:45tomojI got that much, I guess the problem was I have no idea how bacnet works
20:46tomojare you hoping some clojurist will?
20:47FrozenlockNo, I'm hoping the current libraries are enough - I could be wrong
20:47bpr`the bidding price and the asking price are pretty far spread aren't they?
20:49FrozenlockIt's still small market I would say
20:51gfrlogain't nobody know of a way to get the last-insert-id in clojureql do they?
20:51gfrlogit seems surprising that I have no reliable way to create foreign keys :/
21:12bdeshamis there a built-in function to go from {:a 1 :b 5} to [[:a 1] [:b 5]] ?
21:12bdesham(I have code to do it but wondered if there was already a way in core)
21:13gfrlog,(seq {:a 1 :b 5})
21:13clojurebot([:a 1] [:b 5])
21:13gfrlogit's not quite the same thing but likely it's good enough
21:14gfrlogdepending on what you're doing with the result, you might be able to just use the map
21:14gfrloge.g., ##(doseq [pair {:a 1 :b 5}] (prn pair))
21:14sexpbot⟹ [:a 1] [:b 5] nil
21:15bdeshamI think seq might work, let me give it a try
21:15gfrlogA lot of core functions call seq on their inputs anyhow
21:16bdeshamyeah, I was using (for [k (keys v)] [k (v k)]), which seems to do the same thing as (seq v)
21:17gfrlogyeah. learning clojure is fun because your code keeps shrinking
21:18bdeshamhaha, I'm simultaneously pleased and annoyed when I spend an hour writing a function and then find that the same thing is built into the language
21:18bdeshamit happens a lot...
21:19gfrlogI've been using clojure for almost two years now and it still happens
21:20gfrlogtwo recent ones are reset! and mapcat
21:22bdeshamI haven't used atoms yet, but mapcat seems pretty useful
21:23gfrlogI don't know how many times I wrote out (apply concat (map #(blargity blarg) mydatas)
21:23gfrlog)
21:26bpr`i've only just started using clojure. One of the instant pleasure points has been destructuring
21:26gfrlogif only it worked with sets
21:26bpr`it's *so* usefull. You had to use special forms to do destructuring in CL
21:27tomojbpr`: have you seen moustache?
21:27amalloybpr`: surely not special forms. destructuring-bind must be a macro
21:28bpr`how would you want it to work with sets? something like: [foo :foo] #{:foo} ==> (= foo true) and [foo :foo] #{:bar} ==> (= foo false)
21:28bpr`amalloy: yes, it's a macro
21:28bpr`sorry
21:28bpr`tomoj: no
21:29tomojhttp://gist.github.com/109955 I seem to remember that moustache takes destructuring to an extreme, but looking at the walkthrough I'm not sure that it justifies this memory
21:30gfrlogbpr`: I've been doing a lot with undirected graphs, for which I use two-element sets. So something like (let [#{a b} edge] ...) would be nice, where the ordering is undefined.
21:30gfrlogtomoj: compared to pattern matching in other languages?
21:30tomojI really don't know anything about pattern matching in other languages
21:31bpr`gfrlog: oh, that's neat
21:31tomojenlive does this also to a lesser extent I think
21:31bpr`grab a subset real quick...
21:31tomojdestructuring is embedded into these little special grammars
21:31gfrlogbpr`: in my case it would be the entire set, as it would only ever have two elements. But sure, subsets for bigger sets would be fine.
21:32tomojwhat, a random subset?
21:32gfrlogwell at the very least you could just say that the set gets (seq) called on it before destructuring
21:33gfrlogI think that would be pretty natural
21:33tomojI see
21:33gfrlogso the syntax would be (let [[a b] edge] ...)
21:33tomojthat happens to be convenient for minhashing I think..
21:33gfrlogeh?
21:33gfrlogwhat minhashing is?
21:34tomojset similarity by taking minimums of hashes of elements in the sets
21:34tomojexcept, that would be pretty silly
21:34tomojyou'd just (take n) of the hashes
21:36gfrlog...sure
21:36gfrlogso in summary, destructuring is cool, but it could be slightly better.
21:38tomojI think letting the internal order of the set leak out that way would be strange
21:39tomojfor a sorted set it seems to make sense
21:39gfrlogbut that already happens whenever you pass a set to a function for seqs
21:39tomojright..
21:40gfrlogI'm not really asking for special behavior for sets, I'm more wishing that when you try to sequentially destructure something, it gets treated like a seq
21:40gfrlog,(sequential? #{:WHAT})
21:40clojurebotfalse
21:40gfrlograther than that
21:40tomoj&(let [[a b c d] (seq (set (range 10)))] [a b c d])
21:40sexpbot⟹ [0 1 2 3]
21:40tomoj&(let [[a b c d] (seq (set (range 100000)))] [a b c d])
21:40sexpbot⟹ [0 32768 65536 98304]
21:41tomojyeah
21:49gfrlogwhy does a tweet say that clojure contrib is deprecated?
21:50amalloybecause it is?
21:50gfrlogwhere will it all go?
21:50amalloyas of 1.3 clojure-contrib doesn't exist as a monolithic entity
21:51amalloythe libs get split up
21:51gfrlogthis primarily has implications for my project.clj file?
21:51gfrlogor also the namespaces?
22:26amalloygfrlog: the namespaces are getting renamed
22:26amalloyclojure.tools.xml or something, for example
22:28gfrlogI guess the compiler will always check what got missed
23:44bdeshamwhat would be an idomatic way to implement the algorithm shown at http://en.wikipedia.org/wiki/Schulze_method#Implementation ?
23:45bdeshamthere's one pass through a 2-d array, and then another; the results of the second pass depend upon the second pass
23:45bdeshamif that makes sense
23:47bpr`what do you mean the results of the second pass depend on the second pass? Results of processing element 10 in pass 2 depend on the value of pass 2 for elements 0-9?
23:48bdeshambpr`: yes, that's what I was trying to say :-)
23:49bdeshammy attempt to implement this used let [p ...] for the first pass, but I'm not sure how to deal with the fact that the array may be changing in the second pass
23:53bdeshamhttp://pastebin.com/taDAQSM8 - my attempt so far
23:57bpr`my first impulse is to tell you to make each element a ref and just set it's value. But, that's really just punting... I don't know enough clojure yet to know what the idiomatic way would be
23:57bpr`of course if you were to do that, you'd have to use a mutable data structure
23:59bdeshamright... I also don't know enough clojure to know whether there's a more idiomatic way