#clojure logs

2011-06-25

01:24justinlillywhat's the name of that site where you can submit answers to problems with clojure? Like: Reverse a list. and you paste in a function that will do it.
01:26justinlillyaha! 4clojure.org
01:28amalloyjustinlilly: do we have .org? i thought we just had .com
01:30amalloyah, right. dbyrne bought that when someone mis-tweeted the domain
03:21bsod1I installed clojure-contrib, and it has a clojure-contrib-xx.jar in target/, should I still build it, because I don't have mvn installed(and my package manager doesn't have too)..
03:27amalloybsod1: don't build it or install it. just use leiningen or cake. you can just say "i need contrib" for a project, and the build tool will go fetch you a prebuilt jar
03:49bsod1amalloy: I'm trying to install vimclojure, is leiningen OK? I think vimclojure needs contrib installed
03:50amalloybsod1: i'm an emacs user, alas. link me to your vimclojure install guide and maybe i can help?
03:50bsod1amalloy: http://www.duenas.at/new_homepage/vimclojure and http://blog.darevay.com/2010/10/how-i-tamed-vimclojure/
03:53amalloyjesus, this is messier than getting slime/swank versions right
03:54amalloymaybe gfrlog knows? he's probly in bed but i don't know who else uses vim
03:55bsod1amalloy: how can I test if I installed clojure and clojure-contrib?
03:55amalloyat any rate i don't see any reason you should have to build the clojure or contrib jars. you can just get them from clojars
03:58amalloybsod1: i haven't tried to do any of this by hand for like a year; i'm not much help. you might try the simpler "use leiningen to get up and running" before the apparently-huge hurdle of vimclojure
03:59amalloyhttps://github.com/technomancy/leiningen
04:00faust45hi guy's
04:00faust45just have a question, is it possible have async io in clojure?
04:01amalloyyes
04:01amalloyjava.nio or aleph are good places to look
04:01midshttps://github.com/ztellman/aleph
04:03faust45thanks guy's
06:55bsod1how can I be sure I installed clojure and clojure-contrib correct?
06:56Vinzentbsod1, just add it to the project.clj's :dependencies
06:57Vinzentor what do you mean by "install"?
06:58bsod1Vinzent: I'm new to clojure, I downloaded latest version of clojure and clojure-contrib, and build clojure, now should I be in the same directory with clojure to run it? is only way to run clojure `java -cp clojure.jar clojure.main` ?
07:00Vinzentbsod1, I think you should download and install leinengen - build tool for clojure. Then, you can just run lein new my-project && cd my-project && lein deps && lein repl and you'll got working clojure REPL
07:01bsod1Vinzent: will it work for vimclojure repl? I'm trying to setup vimclojure
07:03Vinzentbsod1, I'm using emacs, but I believe that vimclojure compatible with leiningen
07:04VinzentSee https://github.com/technomancy/leiningen/wiki/Plugins: lein-nailgun Launch a vimclojure nailgun server.
07:17bsod1what sould I add to my project.clj to use clojure-contrib?
07:40terombsod1: http://clojure.org/downloads, see the bottom of the page
07:48longfinis there anyone who knows swank-clj?
07:58teromLink in the Leiningen plugins page for lein-nailgun (https://github.com/brandonw/lein-nailgun) gives 404 for me. (Found it on clojars, though: http://clojars.org/lein-nailgun or http://clojars.org/org.clojars.gfodor/lein-nailgun)
08:11bsod1(:require clojure.xml) gives me ClassNotFoundException, what did I do wrong? should I install clojure-contrib for this?
08:22faust45bsod1: something like this http://friendpaste.com/6mi5vQswJGTpctHMvd2I7k
08:23bsod1faust45: thanks but I'm not running REPL vie lein, I'm using nailgun
08:25faust45bsod1: why not lein?
08:28bsod1faust45: if you explain me how can I use lein with vimclojure..
08:30faust45bsod1: i dunno how to integrate vimclojure with lein, but you can use them separate
09:08hugodlongfin: you have a question on swank-clj?
09:08longfinyes...
09:09longfinin-ns doesn't work when using swank-clj
09:09longfinbut it works using swank-clojure...
09:14hugodlongfin: in-ns at the repl?
09:15longfinyes. using slime
09:15hugodyou found a bug…
09:18hugodhttps://github.com/hugoduncan/swank-clj/issues/10
09:18longfinokay..
09:46hugodlongfin: ,!p works, if you are looking for alternatives
09:47longfinok thanks
10:14Norrit_Hi, I have a little question. I want to use a string to reference a binding var, something like this: (let [name "World"] (str "Hello " (find-var (symbol "name"))))
10:14Norrit_Any ideas how I can do that?
10:23VinzentNorrit_, you should use binding to rebind the var. Also, as wroted in find-var's docs, symbol must be namespace-qualified
10:23Vinzent(str @(find-var (symbol "user/foo")))
10:28Norrit_Vinzent, that doesnt seem to work .. it only returns an empty string
10:29VinzentNorrit_, you should do (def foo "your-string") in the user namespace before that
10:30Norrit_Ah ok, now I get it .. but is there no way to access "local" let bindings?
10:31VinzentI have no idea why someone may want to access to local bindings in this way :)
10:31Norrit_Hehe :-)
10:33Norrit_I want to write something like the el-strings in java ... (let [foo "bar"] (print (my-string "Hello ${foo}")))
10:34VinzentI guess it's better to use format for this purpose, but if you really want this, probably you should write my-string macro and manually extract the symbols from the given string
10:37Norrit_Well, first of all I want to play around with the language ;-) but I will try to write the macro .. thanks for your help
10:38VinzentNorrit_, ah, ok :) it'd be something like this (defmacro foo [s] `(str ~(str s) " is " ~s)), (let [q 5] (foo q)) => "q is 5"
10:40Norrit_that looks nice, I will give it a try
12:37gfrlogis there ever a reason to use a single ref?
12:37offby1?
12:37offby1oops, never mind
12:37gfrlograther than an atom
12:38manutterI'd say only if you know there's going to be more refs later one
12:38gfrlogmanutter: so essentially no :)
12:39manutterAtom ought to cover any single-update transaction you would need
12:39gfrlogI was just making sure I didn't misunderstand what refs did. I've never had a reason to use one.
12:39gfrlogthough I've used atoms and agents and vars plenty.
12:39manutterSo far I haven't needed them either
12:39gfrlogstrange, that
12:39manutterbut I'm not in the kind of coding that would require synchronized updates of multiple entities, so I wouldn't need them
13:16__name__Why can you not use macros with apply?
13:16__name__,(apply and [true true])
13:16clojurebotjava.lang.Exception: Can't take value of a macro: #'clojure.core/and
13:18Scriptor__name__: from looking at the source, it calls applyTo() on the passed function
13:18Scriptormaybe macros don't have that method?
13:20Scriptorso it looks like there are 5+ parser libraries for Clojure, which ones do people have experience with here so I'll have better luck with asking questions? :p
13:22Scriptorfnparse seems to have the most documentation
13:49sritchiehas anyone run into this error before? -XX:MaxPermSize=128M
13:49sritchiewhoops
13:49sritchiejava.lang.OutOfMemoryError: PermGen space
13:49derp__I am trying to create a lazy sequence of lists such as (999 999) (999 998) ... (0 0)
13:49derp__and I am using this as a guide: http://clojure.org/lazy#Making%20Clojure%20Lazier--Recipe%20-%20How%20to%20write%20lazy%20sequence%20functions%20in%20new%20model
13:49derp__but I still don't really have a clue how to do this
13:50sritchiederp_: (for [x (range 1000) y (range 1000)] [x y])
13:50sritchie,(for [x (range 5) y (range 5)] [x y])
13:50clojurebot([0 0] [0 1] [0 2] [0 3] [0 4] [1 0] [1 1] [1 2] [1 3] [1 4] ...)
13:51sritchie,(type (for [x (range 1000) y (range 1000)] [x y]))
13:51clojurebotclojure.lang.LazySeq
13:51derp__sritchie: thank you again
13:52jamiltronThat's pretty cool.
13:54derp__now how would one create that list in reverse?
13:54derp__cause I am assuming accessing the last causes it to compute all members, which would be a waste, right?
13:55jamiltronUse (range 5 0 -1) to reverse it.
14:04gfrlogI'm using clojure.contrib.json, and I want to be able to add to the set of types that it can encode. You'd think it would have been implemented as a multimethod to make that easy, but it doesn't look like it has, and I looked at clj-json and that seems to be the same situation. Is there no clean way to do this?
14:06gfrlogoh wait I think there is a protocol in c.c.json. That's probably what I need.
14:16gfrloghigh five, clojure.
14:21derp__just out of curiosity, what is the functional way of finding the max number in a list?
14:22mrBliss`,(reduce max [1 3 4 2 9 8 3])
14:22clojurebot9
14:22derp__mrBliss: thanks
14:25bsod1can anyone help me? vimclojure's eval paragraph(<leader>ep) always gives me an exception, but eval file(<leader>ef) works
14:29derp__I am running into a weird error with this code: http://pastebin.com/yXNirFe0
14:29derp__I am getting a null pointer exception after a little bit
14:29derp__I think it has something to do with java heap size or something, no?
14:29sritchiederp__: ,(reduce max [1 5 3 2 9 7])
14:30sritchie,(reduce max [1 5 3 2 9 7])
14:30clojurebot9
14:30sritchiewhoops
14:30sritchieshould have read other comments
14:30sritchiesorry, mrBliss`
14:30bsod1can anyone help me? vimclojure's eval paragraph(<leader>ep) always gives me an exception, but eval file(<leader>ef) works
14:32sritchiederp__: (defn palindrome? [num] (let [s (str num)] (= s (->> s reverse (apply str)))))
14:33derp__sritchie: what does the ->> syntax mean?
14:33sritchiederp__: sorry, you weren't asking for a new version of that function, didn't mean to just toss it out there
14:33sritchie->> is the threading macro
14:33sritchieit takes the first form, and "threads" it into the second form at the last position, then keeps doing that
14:33gfrlogyou can use ->> even funnerer than that...
14:34gfrlog(defn palindrome? [num] (->> num str reverse (apply str) (= (str num))))
14:34gfrlogI guess that's mildly repetitive though :/
14:34sritchieand if something doesn't have parens inside of the body of ->> , just pretend it does. So, in this case, we start with s -- that gets threaded into (reverse) at the last position, making (reverse s)
14:35sritchiethen that gets threaded into the next form, making (apply str (reverse s))
14:35derp__wow, that's crazy
14:35sritchiecommas are whitespace, so you can use commas to visualize... (->> s (reverse ,,,) (apply str ,,,))
14:35gfrlogderp__: it seems pretty weird until you've been writing ugly code for a while :)
14:36gfrlogand by ugly I mean "heavily nested"
14:37gfrlogand "makes more sense when you read it backwards"
14:37derp__seems like an awfully complicated technique
14:37derp__or does it just become another useful tool after becoming familiar with the language?
14:37gfrlogderp__: exactly
14:37gfrlogbecause otherwise we end up writing things like (a (b (c (d))))
14:38gfrloginstead we can (-> (d) (c) (b) (a))
14:38gfrlogwhich better reflects the order of the operationsa and isn't so painfully nested
14:38gfrlogderp__: so the reason your code is crashing is because you have a recursive function with no base case :)
14:39derp__ah, now I'm sort of getting it
14:40gfrlogderp__: you could try fixing that just for fun, but it might be ultimately more helpful to rework palFinder
14:40gfrlogall the recursion isn't necessary
14:41gfrlogyou could do everything there with (filter)
14:41sritchiederp__: here's an example from my own code: https://gist.github.com/1046756
14:41sritchiethe second version uses threading to make everything a little clearer
14:41derp__gfrlog: wow, can't believe I missed that, thank you
14:41gfrlogderp__: no problem
14:41gfrlogderp__: I had to stare at it for a few minutes myself
14:48sritchiederp__: there's a nice opportunity for the threading macro in your final solution
14:49gfrlogI like the contrib macros -?> and -?>>
14:50sritchiegfrlog: here are some fun threading macros I've been helping with: https://github.com/pallet/thread-expr
14:50sritchiedifferent flow control macros like for->, if->, for->> etc that work within the body of a call to one of the threading macros
14:51gfrlogsritchie: I have to say those examples are not immediately clear :)
14:51gfrlogyou should add "expands to..." after each of them
14:51sritchiehaha, that's an excellent point
14:52sritchieI'll tweak those shortly
14:52gfrlogeasy to forget when you already know them yourself
14:52sritchiederp__, don't take this as nitpicky, but one style thing that I might recommend is the use of lowercase letters in var names, with dashes between words instead of caps
14:53sritchiethat'll distinguish your variables from java methods
14:53sritchiehugod: :) maybe we can just change the word "Examples" to "Koans"
14:53gfrloghugod: better than not writing examples ;)
14:54sritchiehugod, all of the pallet threading stuff really helped, writing this text based blackjack game I'd been playing with
14:54hugodwell, they're copied from the unit tests, which probably explains it
14:55sritchieit was nice to realize that game state threading made as much as sense as the incremental transformations on threaded requests
14:56hugodsritchie: glad you have found other uses for them
14:56hugodI still think there has to be a better solution than threading for pallet…
14:57sritchieI stalled on my monad investigation
14:57sritchieI'm working through the seasoned schemer... reasoned schemer and core.logic come next
14:57sritchieyou've made enough intriguing comments in that direction
15:00derp__sritchie: thanks for the suggestion, I just got used to camelcaps after writing java for so long ;P
15:08dnolenhmm odd :import doesn't convert - to _
16:30aaelonyhi, I'm trying to access the :name element of the following, but something is not right because it returns nil
16:30aaelonytest=> (pprint (take 1 (:properties (first j))))
16:30aaelony({:name "blah",
16:30aaelony :newValue "e92c6344-3af5-47c2-abd1-fce681f48fd0",
16:30aaelony :oldValue "2ba3ebeb-94c5-4528-9bec-45eeb6d4da40"})
16:30aaelonynil
16:30aaelonytest=> (:name (take 1 (:properties (first j))))
16:30aaelonynil
16:31aaelonyany ideas?
16:32aaelonytest=> (class (take 1 (:properties (first j))))
16:32aaelonyclojure.lang.LazySeq
16:32amalloyaaelony: https://gist.github.com is one idea
16:32aaelonyamalloy: thanks will check it out
16:33aaelonyamalloy: not sure what you mean. I see an empty page at your link.
16:33amalloyaaelony: yes. you can paste code there instead of long chunks of code here, where it's hard to read
16:33aaelonyah, i see. sorry about that
16:34amalloyaaelony: anyway, (take 1 x) will return a list, not an item from the list
16:34amalloy(:name (first x)) would work
16:34aaelony(:name (first x)) does not work
16:35aaelonyhttps://gist.github.com/1046871
16:36pcavs_aaelony: try (:name (first (:properties (first j))))
16:36aaelonypcavs: that works!
16:37pcavs_aaelony: amalloy was correct, I just rewrote it to be more like your example
16:37aaelonyI'm sure it is something that I am doing wrong due to poor understanding on my part
16:38aaelonythanks, for the help. Now I need to loop, for, or map this such that I extract certain keys from this structure. :name is the first of those.
16:39rpglover64I'm new to clojure (hello from Haskell-land) and I'm trying to understand why my program is behaving in a way that I find very unintuitive.
16:39rpglover64http://hpaste.org/48331
16:39rpglover64which is a straightforward translation of http://hpaste.org/47339
16:40amalloyrpglover64: clojure's self-recursive data structures don't really work as well as haskell's in some cases
16:41rpglover64(take 10 primes) gets me (2 3 5 7 9 11 13 15 17 19)
16:41rpglover64and 15 isn't a prime
16:41gfrlognor is 9
16:41rpglover64yeah
16:42amalloyrpglover64: in this case, the problem is that (range) produces a chunked sequence
16:42amalloyif you replace (drop 3 (range)) with (iterate inc 3), it will work
16:43rpglover64thank you
16:43amalloychunked meaning that it realizes a bunch of (32?) elements all at once, and that means there are 32 integers in a row all relying on the old definition of primes before they get inducted into the hall of primes
16:43amalloy(you could also write (iterate #(+ 2 %) 3) for the ultimate in performance *chuckle*
16:44gfrlogamalloy: (iterate dinc 3)?
16:44rpglover64at that point, i'm just going to start writing a wheel sieve
16:44amalloyrpglover64: fwiw clojure already has a wheel sieve. i assume you're doing this for your own edification, but just so you know
16:45rpglover64amalloy: OOH where?!
16:45amalloyhttp://clojure.github.com/clojure-contrib/lazy-seqs-api.html
16:46gfrlogof course if you're not interested in writing your own code, there's always BigInteger#isProbablePrime
16:47rpglover64gfodor: true
16:53gfrlogamalloy: did you say yesterday than an ISeq always has a first element?
16:54amalloygfrlog: was i wrong?
16:54gfrlogamalloy: () is an ISeq, isn't it?
16:54aaelonywhat is the correct way to specify that api (http://clojure.github.com/clojure-contrib/lazy-seqs-api.html) in the project.clj ?
16:55amalloy&(supers (class (map inc nil)))
16:55sexpbot⟹ #{clojure.lang.ISeq java.util.List java.io.Serializable clojure.lang.Obj java.util.Collection clojure.lang.IPersistentCollection clojure.lang.IMeta clojure.lang.IObj java.lang.Object clojure.lang.Seqable clojure.lang.Sequential java.lang.Iterable}
16:55amalloygfrlog: okay, i was wrong
16:55gfrlogamalloy: okay just checking
16:56amalloy&(supers (class (seq (map inc [1]))))
16:56sexpbot⟹ #{clojure.lang.ISeq java.util.List java.io.Serializable clojure.lang.IChunkedSeq clojure.lang.Obj java.util.Collection clojure.lang.IPersistentCollection clojure.lang.IMeta clojure.lang.ASeq clojure.lang.IObj java.lang.Object clojure.lang.Seqable clojure.lang.Sequential java.lang.Iterable}
17:00gfrlogamalloy: I'm not sure why I thought of that just now
17:01amalloypresumably i was helping so many people you were worried it might go to my head, and i needed to be brought down to earth
17:02gfrlog"helping so many people" made me think of Mother Theresa for some reason
17:04amalloyevery one of them a precious snowflake, so dear to my heart
17:04aaelonyi certainly appreciate the help
17:06aaelonyI've got a collection. For each number of times in the collection, I need to perform a few tasks. Not all tasks relate to the collection but some do. How do I construct a loop around this ?
17:07gfrlogaaelony: what does "for each number of times in the collection" mean?
17:08symboleIs it possible to destructure a map, and require certain keys to be present?
17:08gfrlogsymbole: no, I think you have to check that separately
17:08gfrlogsymbole: if you're destructuring function arguments, you can add preconditions
17:08aaelonyI've got a complex json object. When I drill down to the right level in that obect, there are 274 rows. I need to extract some keys from those rows, but also bring in some keys from higher levels in that json as well
17:09amalloyyou could also write a macro to do it, symbole?
17:09gfrlogoh yes macros are good for that
17:09gfrlogaaelony: if you want to select some elements from a collection, filter is good for that
17:10symboleThanks. I'll look into both options.
17:10gfrlogas far as how to combine them with you're other stuff, that kind of depends on the details
17:10aaelonywell, i need all the elements of a subcollection
17:10gfrlogs/you're/your
17:10sexpbot<gfrlog> as far as how to combine them with your other stuff, that kind of depends on the details
17:10aaelonytraditionally it would be:
17:10gfrlogaaelony: I'm confused, you said "I need to extract some", but then you say you need all of them...
17:12aaelonyfor example, at a nesting depth of say 4-deep I need all the rows. for each of those rows, I need to bring in extra things (say they are at level 2-deep) besides the things that are at level 4-deep
17:13gfrlogaaelony: I guess it's hard to specify how to construct a loop without more details
17:13aaelonyin perl, I would loop through the things that are at the 4-deep level, and output the things at the 4-deep level but additionally print things that were static.
17:14aaelonyit is precisely this loop that is unknown to me in clojure
17:14gfrlogaaelony: you're saying for a given level-4 collection there is some constant data that you want to add to each thing?
17:14aaelonyyes, something very close to this situation
17:15gfrlogaaelony: you can use map to change all the elements of a collection in some way
17:15aaelonyit can be viewed as static, because I already have access to it
17:15gfrlog,(map #(assoc % :foo "bar") [{:id 10} {:id 12}])
17:15clojurebot({:foo "bar", :id 10} {:foo "bar", :id 12})
17:16aaelonylet me think about that
17:16amalloygfrlog: ##(for [m [{:id 10} {:id 2}]] (assoc m :foo "bar"))
17:16sexpbot⟹ ({:foo "bar", :id 10} {:foo "bar", :id 2})
17:16gfrlogamalloy: yes
17:16amalloylonger, but easier to layer if you want to iterate over multiply-nested things, which i bet aaelony will
17:17rpglover64so this is going to be a very noob question, partially dependent on my personal setup, but how do I get access to contrib libraries in the repl?
17:17amalloyrpglover64: how do you launch your repl?
17:17aaelonyi think i need more fine grained control than map and assoc but not sure
17:17rpglover64clj-rlwrap.sh
17:17aaelonyi probably need a more traditional loop
17:18gfrlogaaelony: why so?
17:18amalloyrpglover64: you *could* download contrib, put it on your classpath (which i guess clj does), and then (use 'clojure.contrib.lazy-seqs) for example
17:19aaelonyI am trying to follow an example, and that would be closer to the example I am following.
17:19amalloyin the long run you'll be happier installing cake or leiningen and letting it manage your dependencies, instead of clj-rlwrap
17:19rpglover64huh; that didn't work when I tried it <_<
17:19aaelonyperhaps as long as I can emit a vector with static and non-static elements that would work
17:20gfrlogaaelony: an example in another language?
17:21aaelonysomething like for(my $i=0;$i<@collection; $i++) { print join("\t",$x, $y, $z, $coll[$i]), "\n"; }
17:22amalloyrpglover64: imo cake is better for experimentation since it's easier to set up a "global project" with dependencies on things like contrib
17:22gfrlogaaelony: I'm not sure why for/map can't handle that kind of thing
17:23gfrlog(for [el collection] [x y z el])
17:23aaelonywell, map takes a function and I need several functions
17:23aaelonyseveral function calls for each iteration
17:23gfrlogaaelony: you can combine several functions into one function
17:23aaelonygfrlog: that is the part I am unclear on in clojure
17:24gfrlogaaelony: let me back up real quick -- are you trying to return a data structure, or perform side effects like printing things?
17:26gfrlogin clojure you tend to handle the two cases differently
17:27aaelonyWell, the long story of it is that this that I am writing a function that will be used by Cascalog. That function needs to construct a vector of fields. There are fields I have ready access to without a loop and those will be constant fields. I need to add the constant fields to the variable fields that i get from some looping mechanism. The ultimate output needs to be a vector of rows i believe.
17:28gfrlogaaelony: okay, so it sounds like no side effects; so what did you mean by having to make several function calls? What do you do with the return values of the function calls?
17:29aaelonythe big ugly json I have has various nesting levels. Some items come from level-2 nestings, others come from deeper in the structure. I need to have calls that ask for the values of these variously nested values
17:30aaelonyno side effects, just extracting from various keys
17:31gfrlogaaelony: okay. it sounds like you're approaching the problem imperatively. I'm having trouble trying to convert the problem to functional style without a bit more tangibility. Can we try to create a simple example JSON?
17:32gfrloge.g., from what you've said so far I'm thinking of this kind of thing: {:a 10, :b 12, :items ["one" "two" "three"]}
17:33gfrlogbut maybe it has to be more complex? :/
17:33hiredmanwhat is the state of the art for processing streams of xml in clojure?
17:34aaelonygfrlog: https://gist.github.com/1046871
17:34gfrlogaaelony: okay, so we're focusing on the :properties collection?
17:35aaelonygfrlog: yes
17:35aaelonyand I need to extract the 3 keys from the properties collection
17:35gfrlogaaelony: and you want to change the properties collection using the other keys (timestamp, instance, entityId, etc)?
17:36aaelonybut in a way such that the other fields are output as well
17:36aaelony(timestamp, instance, entityId, etc..., name, newValue, oldValue)
17:37aaelonyand have that repeated for each "row" of properties, 274 rows in this case
17:37gfrlogaaelony: okay. Making sense so far. The last detail is the high level stuff -- your json is a list of property-havers, so do we ultimately want a list of lists of properties?
17:38aaelonygfrlog: unclear on your question. essentially want to list out each row of properties, but also prepend the other data
17:38gfrlogokay, let's try this
17:39gfrloghttps://gist.github.com/1046928
17:40derp_is "incr" a keyword? is there an easy way to test if I am accidentally using a keyword for a function/variable name?
17:40gfrlogthat will merge all the keys from the top level (except :properties) with all the keys from the bottom level
17:40gfrlogderp_: type it into the repl?
17:40gfrlog,incr
17:40clojurebotjava.lang.Exception: Unable to resolve symbol: incr in this context
17:42amalloyderp_: there are very few keywords
17:42gfrlog:)
17:42aaelonygfrlog: I think that does it!! That is what I need to study and learn
17:42derp_gfrlog: that is a simple test, thanks
17:42gfrlogaaelony: nice
17:42amalloyi counted last night, as it happens, and there were 20, or a couple fewer
17:42aaelonygfrlog: never used merge nor dissoc before ... cool :)
17:42gfrlogamalloy: :now :there :are :five :more
17:42AWizzArdWhen you scroll down at http://download.oracle.com/javafx/2.0/binding/jfxpub-binding.htm and look at the box, containing example Java code, then you can see “new DoubleBinding() { …”. Then there is this piece of code: { super.bind(a, b, c, d); } <-- what is that?
17:43gfrlogaaelony: glad I could help
17:43AWizzArdno @Override annotation.. but it looks like an “anon constructor”?
17:43amalloyAWizzArd: anonymously extending/implementing a class/interface; that's a method body for some overridden method
17:44AWizzArdCan I do this with a proxy in Clojure? To me it seems they don’t call the super class’ Constructor, but instead another method of the super class.
17:44amalloyderp_, gfrlog: typing it into the repl won't really help. eg, deftype* is a special form, but:
17:44amalloy,deftype*
17:44clojurebotjava.lang.Exception: Unable to resolve symbol: deftype* in this context
17:44amalloyAWizzArd: they implicitly call the no-arg super-constructor
17:45rpglover64Is there an introduction to Clojure for Haskell programmers specifically?
17:45aaelonygfrlog: That is really cool. There is one more wrinkle I need to contend with, sometimes some of the keys will be absent. In the case where a given key is absent, I need to output a "" placeholder for it. Normally, I would think to use (or :key "") for this. How would this be accomplished?
17:45AWizzArdamalloy: Otherwise proxy takes a vector, with args for the super class constructor. But in this piece of code they seem to call the bind() method?
17:45amalloyrpglover64: not as far as i know. if you hang around in here you can ask brehaut next time he's around
17:45amalloyAWizzArd: incorrect parsing on your part
17:46amalloyoh weird
17:46amalloyi see
17:46amalloyi was looking at the wrong snippet
17:46amalloyyeah, that's a...what, local initializer block?
17:47amalloynot a very common feature in java, but easy to do with clojure
17:47AWizzArdI don’t know, I interpreted this block as an anon class’ constructor?
17:47AWizzArdAnyway, how can I do this with proxy? :-)
17:47gfrlogaaelony: I would probably create a helper function called assure-keys
17:47amalloy(doto (proxy [DoubleBinding] [] (computeValue [] ...)) (.bind a b c d))
17:48gfrlog(defn assure-keys [m ks] (reduce #(if (contains? %1 %2) %1 (assoc %1 %2 "")) m ks))
17:48amalloyif bind is a protected function that you can only call from the proxy itself, there's some functionality where proxy will make-public existing protected methods
17:48gfrlogaaelony: then you can call that function after merge, or something like that
17:48AWizzArdamalloy: ah okay, so simply moving this code outside could work here.
17:49gfrlogaaelony: I'm heading out
17:49amalloyAWizzArd: yes, it's effectively the anon class's constructor
17:49amalloyit has some crazy name because it's a crazy feature
17:49aaelonygfrlog: many many thanks
17:49gfrlogmaybe it should be called ensure-keys? I'm forgetting what words mean and which ones actually exist :/
17:49aaelonylol
17:49aaelonythx again
17:49gfrlogyessir
17:51amalloyAWizzArd: i just looked at http://download.oracle.com/javafx/2.0/api/javafx/beans/binding/DoubleBinding.html though, which indicates that they've tried to put some more obstacles in your way
17:51amalloy(1) bind takes varargs, so you have to pass it a java array rather than a bunch of arguments
17:53amalloy(2) there's a protected method you have to call, and that can't be proxied (apparently)
17:53amalloyi think you have to use gen-class to participate in this abominable API
17:53AWizzArdamalloy: ah okay
18:05solussd_chouser: re-reading JOC since it was released and I don't understand how lz-rec-step in section 6.3.2 alleviates the recursive stack overflow issue in rec-step. Is this a mistake?
18:12amalloysolussd_: no. that's just the magic of the lazy-seq macro
18:13solussd_amalloy- it doesn't work in this case
18:14solussd_(lz-rec-step (range 20000)) ;stackoverflow
18:14solussd_the outer seq, of length 1, contains all 20000 integers
18:15amalloysolussd_: that's a stackoverflow in the repl printing it
18:15amalloythe original version has a stackoverflow just trying to create it
18:16amalloythis is why chouser (or fogus) wrapped it with dorun
18:16solussd_ah
18:17solussd_ok then. . now I'm more confused as to how lazy-seq allows the realization to happen non-recursively
18:17solussd_or, without blowing the stack
18:17amalloysolussd_: are you familiar with a trampoline?
18:18solussd_yes. is that what is happening?
18:18amalloyit's very similar
18:18solussd_neat. thanks!
18:18amalloya lazy-seq is basically a pair: [current-element code-for-next-element]
18:19amalloyso the caller's code is effectively used as a trampoline: lazy-seq returns one element immediately, as well as some code the client can call to generate more if he wants
18:19gfrlogamalloy: so it's a cons cell where the second element is a function instead of list?
18:19solussd_gfrlog: only if we have two trampolines. :D
18:20amalloy*nod* and technically the first element is a function too
18:21amalloy&(let [x (lazy-seq (throw (Exception. "oops"))) y (print "built x okay") z (first x)] z)
18:21sexpbotjava.lang.Exception: oops
18:21amalloyhmph
18:21amalloyin a real repl that would work
18:21gfrlog:)
18:22gfrlogREAL repls use vim
18:22solussd_emacs is a real repl. literally. :D
18:57Raynesamalloy: An oops exception?
18:57Raynesamalloy: Where did we get an oops exception?
18:58RaynesOh.
18:58RaynesThree cheers for actually reading the code.
18:58amalloywell done there
19:30seancorfieldremind me, who owns/runs Clojars?
19:31amalloyseancorfield: these days i think technomancy inherited it?
19:31amalloybut someone else is the official owner, and i think he's still around on occasion
19:32amalloydisclaimer: this may be entirely false
19:32seancorfield'k trying to sort out access for congomongo so multiple project members can push JARs
19:49derp_I have been working on the euler problems through one file I just keep adding to and reloading into repl (https://gist.github.com/1047049)
19:50derp_and recently I just tried to reload the code to get an error in my earlier code (which I am quite sure I haven't modified)
19:50sritchiehere's a funky question -- in both cake and lein repl and swank, I find that I have to defn a var twice before a call to meta returns the right stuff
19:51sritchiethe question is, why?
19:51sritchiehttps://gist.github.com/1047051
19:51derp_and the weirdest thing is this: as I reload the code, the line with the error increases
19:52derp_https://gist.github.com/1047053
19:52derp_I just don't get it
19:53derp_also I am using the cake repl, does it have known issues like this?
19:54amalloysritchie: my understanding is that your meta calls should never work. the surprise is not that it takes two tries, but that it works at all
19:54sritchiederp_: this was my idea for the threading macro, btw -- https://gist.github.com/1046754
19:54amalloy(meta #'test-f) should work on the first try - defn attaches the meta to the var, not the function
19:55sritchieah, I see
19:58derp_sritchie: wow, that is an elegant way of rephrasing the problem
19:59amalloysritchie: if you figure out why it was working to begin with, i'd be interested to know
20:00sritchieamalloy: sounds good, looking at the source now
20:05sritchieamalloy: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Symbol.java#L125
20:06sritchiethat's why it responds to the call... not sure why it takes two defns to update
20:06amalloysritchie: for sure symbols *can* have meta
20:06amalloybut defn doesn't attach any to them
20:07sritchiehere, right? https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L305
20:08sritchieyou're more familiar with this than I am -- name here is the symbol, right?
20:08amalloysritchie: yeah, it is. so defn creates a new version of the symbol, and passes it to def
20:09amalloydef takes the meta from the symbol and attaches it all the the var
20:10amalloydef can't really attach the meta to the value you're def'ing, since you might do something like (def ^{:size 10} x 1), and it can't attach meta to 1
20:11sritchiesure that makes sense
20:11amalloyso i still don't really see how any meta ever winds up attached to the *value* test-f, which is a function
20:14sritchieyeah, odd. playing with this, new-sym doesn't inherit the updated metadata on the second call -- https://gist.github.com/1047073
20:15sritchiewith, say, (defn test-func "some doc" [x] x), test-func gets its update after two, while the new-sym var inherits on the :name and :ns entries in the metadata map
20:18amalloyi guess defn does attach meta to the value after all. i didn't realize that
20:19amalloybut it does so by looking up the *current* meta of the var x
20:20sritchieah, so there's the delay. The var gets the basics, these get assigned to the value as well, then the var gets metadata updates
20:20amalloyyeah
20:20sritchieand two cycles of that is sufficient to catch up the value metadata. got it
20:20amalloykinda a weird half-feature, half-bug, imo
20:21sritchieit does explain why (def func (fn [x] x)) (meta func) returns nil, though
20:25amalloyyes, i imagined that's what would happen even with defn, but apparently not
20:31sritchieis there some function in cake or leiningen to get the current dev-resources-path for a project?
20:33amalloysritchie: i imagine it's available from cake.core/*project*
20:47derp_okay I really don't get what's going on, both cake and the lein repl are giving me the same weird moving error
20:48derp_every time I load my file (in either cake or lein) I get: java.lang.IllegalArgumentException: Parameter declaration let should be a vector (euler.clj:1)
20:48tomojdid you come from lisp or scheme
20:48derp_and if I try to load the file again, the erroring line increases (euler.clj:2, euler.clj:3) with every call
20:49tomojpaste euler.clj to pastebin or gist or something
20:49derp_https://gist.github.com/1047049
20:49derp_that's the code
20:50derp_and this is an example of the error (with no editing on the file): https://gist.github.com/1047053
20:50derp_I know neither scheme or cl, only java and a tidbit of python
20:51tomojat the bottom you have "(defn solve-euler6 (let ..."
20:51amalloyderp_: you have an unbalanced paren somewhere, i think, since the code looks fine and fails for me too
20:51tomojsolve-euler6 needs a param array
20:51tomojvector I mean
20:51amalloyah
20:51tomoj(defn solve-euler6 [] (let ..))
20:52derp_tomoj, amalloy thanks
20:52derp_man that's such a weird error, I really didn't know what to think
20:53amalloyderp_: yes, it's not a good error
20:54amalloyit saw (let ...) and assumed that was the param-list, but it wasn't a vector
20:54amalloyrather than assuming you forgot a param list
20:56derp_ah, well thank you for explaining that
20:57derp_also, I don't mean to start a flame-war or anything, but what's up with the epl licensing? I keep thinking about the cool projects I want to work with, but I am sad to learn how poorly the epl and gpl work together
20:58derp_or at least that's my biased/poorly informed opinion after reading a few posts about the matter
20:59gfrlog(epl + gpl) / 2 = fpl
21:16davekongHow do I specify in a ":methods" takes an array of strings as an argument? when I use String[] I can a ClassNotFoundException: []
21:27sritchiegfrlog: tweaked the readme for you: https://github.com/pallet/thread-expr
21:28sritchieit'll get some more love soon
21:41gfrlogsritchie: w000!
21:42amalloydavekong: ##(class (into-array ["test"]))
21:42sexpbot⟹ [Ljava.lang.String;
21:42amalloyyou want to specify that, as a string, iirc: "[LString;"
21:43amalloyor maybe the java.lang part is necessary here? not sure
21:49davekongamalloy: seems I need the whole thing, but not sure it is working because I get another error "java.io.IOException: No such file or directory"
21:49davekongamalloy: is that "[L" talked about somewhere?
21:49amalloy$google java internal array classname
21:49sexpbotFirst out of 20400 results is: ArrayType (Java 2 Platform SE 5.0)
21:49sexpbothttp://download.oracle.com/javase/1,5.0/docs/api/javax/management/openmbean/ArrayType.html
21:50amalloyew wth is that
21:50amalloydavekong: http://tutorials.jenkov.com/java-reflection/arrays.html maybe
21:58daakui remember running across a function that iterated thru multiple sequences in parallel until the smallest one was run thru -- but can't remember the name. anyone know what i'm talking about?
21:58amalloymap
21:58daakuthanks amalloy
21:58amalloy&(map vector [1 2 3] [5 6 7 8])
21:58sexpbot⟹ ([1 5] [2 6] [3 7])
22:22derp_does anyone have any suggestions for how to make this code faster? https://gist.github.com/1047149
22:24gfrlogderp_: welp...
22:24gfrlogyou could take advantage of the laziness of (filter)
22:24gfrlogyou don't need to run through the whole thing to know whether or not it's empty
22:24gfrlogat least not every time
22:24gfrlogso (zero? (count ...)) can be replaced with (empty? ...)
22:24derp_what do you mean?
22:24derp_ah
22:25Scriptorderp_: a lot of euler eventually relies on more mathematical tricks to be faster
22:25gfrlogit's not just to make the code slightly simpler, it really will be better
22:25Scriptormaybe Sieve of Eratosthenes will help? http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
22:25derp_really? huh, just looking at those functions I would have thought them equivalent in speed
22:25gfrlog,(zero? (count (map println (range 5))))
22:25clojurebot0
22:25clojurebot1
22:25clojurebot2
22:25clojurebot3
22:25clojurebot4
22:26gfrlog,(empty? (map println (range 5)))
22:26clojurebot0
22:26clojurebot1
22:26clojurebot2
22:26clojurebot3
22:26clojurebot4
22:26gfrlogcrap dangit those chunks
22:26derp_wow, yeah it's a lot faster now
22:26gfrlog,(empty? (map println [0 1 2 3 4]))
22:26clojurebot0
22:26clojurebot1
22:26clojurebot2
22:26clojurebot3
22:26clojurebot4
22:26gfrlogaugh
22:26Scriptorgfrlog: try a local repl first
22:26gfrlogScriptor: but I'm never wrong!
22:26Scriptorespecially for code that prints multiple lines :)
22:27derp_so I guess empty? is smart and returns no after checking the first item
22:27gfrlogScriptor: and it wasn't supposed to print multiple lines, that was the whole point :P
22:27gfrlogderp_: exactly
22:27gfrlogI was hoping my println example would just print the first item and be done with it
22:27Scriptorgfrlog: but you used println
22:28gfrlogScriptor: yes, I was trying to demonstrate that lazy seqs need not be consumed
22:28gfrlogso I expected it to just print 0 and be done
22:29Scriptorit gets weird when combined with IO, I think
22:29gfrlogwell (range) is chunked. I'm not sure why it didn't work with the vector
22:29gfrlogI guess vectors are chunked too actually
22:30Scriptorthis works too:
22:30gfrlogah with a list it works
22:30tomoj&(chunked-seq? (seq [1 2 3]))
22:30sexpbot⟹ true
22:30Scriptor(empty? (map #(* % %) (range 10000000000)))
22:30gfrlog,(empty? (map println '(1 2 3 4 5)))
22:30clojurebot1
22:30Scriptorgah
22:30Scriptor,(empty? (map #(* % %) (range 10000000000)))
22:30clojurebotjava.lang.ExceptionInInitializerError
22:30gfrlogScriptor: yeah I tried it with 200 and noted it went up to 31
22:30Scriptor,(empty? (map #(* % %) (range 10000000)))
22:30clojurebotfalse
22:31gfrlogderp_: so my last println example is what I was going for :)
22:31gfrlogbut it doesn't matter since you already understood what was going on
22:34technomancyjustinlilly: did you want to announce that vagrant image on the seajure list?
22:34derp_gfrlog: thanks again
22:34technomancyor was there more to tidy up first?
22:34gfrlogderp_: np
23:03daakuis there some syntax that says "put the elements of a seq here" -- something along the lines of ** in python?
23:04daakuor rather * (single star) in python, not double star
23:04amalloy,`(1 2 ~@[5 4])
23:04clojurebot(1 2 5 4)
23:04daakucool
23:05daakuah, i need to use a macro
23:05amalloyno. depends what you want to do
23:05daakui see, let me throw up a pastie with a small example
23:09amalloybut note that i did that without a macro. just the backtick
23:11scgilardiI don't know Python's *. wondering if clojure.core/apply is... applicable here.
23:12islonI'm creating a clojure library with lots of name clashs with clojure.core, what should I do? Change my function names or advert my users that they should use import the functions with fully qualified names namespace/function?
23:13technomancyislon: are your names parallel to the core ones?
23:14islonno, they have completely different meaning
23:14technomancyI'd try to come up with distinct names then
23:15technomancyone or two here and there is not a big deal (things like get), but you don't want people to look for connections where they aren't there
23:16scgilardiif they load your library with (:require [some.really.long.lib.name :as isl]) they can call your functions with calls like isl/concat , isl/reduce , etc. (and I agree with technomancy about different names being desirable)
23:17islonyeah I dont know what to do, i didn't want to change (next :tuesday) to (next-date :tuesday), some name really are meaningfull in my context
23:17islon*some names
23:17amalloyislon: (after :tuesday)
23:17amalloybut i guess that has meaning too
23:17islonyes, next is more friendly
23:20islonand (-> (january) (first :monday)) is intuitive too, i don't want to change first (nor last) to a less intuitive/friendly name
23:24daakuamalloy: sweet, i got it to work using ` ~ and @ -- thanks!
23:28amalloydaaku: scgilardi is right though, this problem is often asked by people who don't realize that what they want is apply
23:29daakuamalloy: i don't think apply would work in this case -- here's what i have working now: https://gist.github.com/ae25ce5f35e74c0357e0
23:30daakui'm a clojure noob, so any suggestions welcome :)
23:31amalloydaaku: ##(let [thing-to-add '(a b c)] (into [:div {:class "test"}] thing-to-add))
23:31sexpbot⟹ [:div {:class "test"} a b c]
23:31technomancyislon: succ for successive tuesday?
23:31daakuamalloy: ah, i see. lemme try it out
23:33daakuamalloy: cool, much simpler
23:33amalloydaaku: but keep the ~@ approach in mind; it's more flexible
23:33amalloyand easy to forget
23:33islontechnomancy: it's an option but it's not better than next, and what about first, last, second, set, sould I change all of them?
23:33islon*should
23:34technomancywhat's "first" mean? counting from 1 anno domini?
23:34daakuamalloy: yep, will do
23:34islonno, the first day of week like (-> (january) (first :friday))
23:35technomancy(-> (january) (fridays) first)
23:35technomancyby which I mean clojure.core/first
23:35technomancyislon: make your functions work in terms of seqs
23:36technomancythen you don't need your own versions
23:37islonhmmm... maybe it's a good idea, I was thinking in terms of date.js (shich is very friendly and intuitive)
23:37technomancywell, js has a crappy sequence library. we can do better. =)
23:37islonbut I should do a more "clojurish" version
23:38islontechnomancy: you're right, thanks =)
23:38amalloy(inc technomancy)
23:38sexpbot⟹ 10
23:39daaku(inc amalloy)
23:39sexpbot⟹ 12