#clojure logs

2011-01-27

01:19no_mindanyone has a working example of JSON being returned from a clojure program ? I am trying this https://github.com/sivajag/Address-Book but no luck
02:07amalloyLauJensen, you around?
03:00LauJensenamalloy: yea
03:00LauJensenJust got in
03:00amalloynm, i decided to bug you in #clojureql instead
03:00LauJensen:)
04:12mrSpecHello! I have problem with (eval (read)) in my program. I have: (defn -main [& args] (while (= 1 1) (print "REPL> ") (eval (read)))) but Instead of "REPL>" I have empty line. When user writes something, "REPL>" is printed and after that the result. What am I doing wrong? Can I force Clojure to print "REPL>" before evaling what user write?
04:14opqdonuttry flushing *out*
04:14zmiladid you tryed (println "") instead of (print )?
04:34mrSpecthanks! (flush) solve this problem :)
04:40solar_seaIs the joy of clojure book ready for reading or it's still a work in progress ? (I'm wondering wether I should get the "meap" subscription for it or wait for a final release)
04:44clgvsolar_sea: I heard that it is already completed and you can buy it from Amazon or Manning
04:56LauJensensolar_sea: http://joyofclojure.com/buy
04:56clgvhow do I tell leiningen about local dependencies? I have a java implementation in a jar file I want to use.
06:43edoloughlinFor a simple cache, a map of maps keyed by id & shared by multiple threads: is it best to use an atom or ref?
06:44companion_cubei'd say a ref, because to keep the cache consistent you would modify the map in a transaction
06:47ejacksonagreed - if more than one thread is writing to the cache, then you need to coordinate it
06:48ejacksonif only one writes, and the others read, then I'd argue an atom is better as it doesn't need to be coordinated.
06:49edoloughlinIf all I'm doing it adding (and periodically removing/cleaning) entries to a map, then can't an atom provide a sufficient level of locking? There's only one variable involved...
06:50companion_cubeif two threads read the atom, add something to the cache, and put the new value in the atom, one of the changes will be lost
06:51edoloughlinWhat if the atom _is_ the cache? (def cache (atom {}))
06:51clgvthere is a memoize implementation that uses only atoms: http://kotka.de/blog/2010/03/memoize_done_right.html
06:51clgvmaybe that might help you
06:53ejacksonit depends what you are storing in the cache. if every call needs to be recorded then i think you need a ref
06:53companion_cubeoh, right, there is a kind of compare-and-swap in atoms
06:53companion_cubeso you can spot concurrent updates
06:53edoloughlinclgv: Looks interesting. This is my first venture into concurrency in Clojure. I'm trying not to to the noob thing of throwing everything at it.
06:54raekatoms are fins as long as you don't need to coordinate the change with some other change
06:54ejacksoncompanion_cube: i did not know that. seems that in that case you would want a ref though, to take care of the concurrency collisions, no ?
06:54clgvedoloughlin: I learned a lot reading that post. I think the decisions are well explained there.
06:54edoloughlinWill read. Thanks.
06:54ejacksonraek is exactly right. coordination is the differentiator.
06:55ejacksonand you need to coordinate if >1 thread can alter data, and depend on another's value. such as an incrementer, say. at least i think so :)
06:55raekin memoize, the atom never leaves the function, so you know it will never have to be coordinated with someone else's changes
06:56ejacksonif you (swap! atom-on-int inc) from two threads together, you will be one count short.
06:56clgvbut multiple threads can use the function and the cache shall be share like explained in the post
06:56raekno, atoms are thread safe
06:56ejacksonbollocks :)
06:57ejacksonoops, as in not you're talking bollocks, but bollocks i'm wrong again.
06:57raekbut if you want to change multiple atoms or one atom in multiple steps, then you can't do it atomically
06:57raekthat's what refs add
06:57clojurebotTitim gan éirí ort.
06:58ejacksonah yes... that's it.
06:59raekmy rule of thumb is: if you are not sure someone else might want to use your atom/ref in a multi-step or multi-ref change, use refs
07:00companion_cubei think you can do it with atoms, but refs (with STM) are much simpler to keep state consistent
07:44qojaI'm trying to reify a java.io.FilenameFilter with: (reify FilenameFilter (accept [_ name] (.endsWith name ".sql"))) and I get Can't define method not in interfaces: accept--what am I doing wrong?
07:46clgvqoja: I am not 100% sure, but shouldnt you use proxy instead of reify since reify is only intended for protocols?
07:46qojaaren't protocols interfaces actually ?
07:48clgvwell, they are clojure constructs compiled to java interfaces and you are trying to implement a java interface. so there is a semantic difference here.
07:49companion_cubeit's a bit of static typing, right ?
07:49clgvif you got the method-signature right and reify doesnt work I would definitely try proxy instead
07:49clgvI used it for TreeCellRender...
07:52companion_cubethe blog entry on memoization is really interesting
07:56qojaoh what a silly mistake. forgot this-variable as first parameter!
07:57raekfor interfaces, both proxy and reify can be used
07:57clgvraek: ah, good to know
07:57raekbut reify is designed to be clojure-ish
07:58raekso you can't do subclassing with it, for instance
08:02ejacksonand i believe is much faster
08:03raekit is.
08:03raekproxy also allows you to update the methods at run time
08:03raek(which I haven't used myself...)
08:19ejacksonraek: i've played that trick through deftype. Its fantastic from the repl.
08:48zippy314Hey, guys, I know this isn't strictly a clojure question, but since I'm hanging out here and using it for colure dev... It's an emacs customization question. I've used technomancy's starter emacs repo, and it calls for removing my .emacs file and using .emacs.d. Where in that directory should I be putting my own cusomizations?
08:50arbschtzippy314: ~/.emacs.d/init.el is a reasonable choice. it is documented in greater detail at http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html
08:52zippy314tx!
08:55fliebelHrm, I wonder if Logos, and logic programming in general could solve blue eyes. I guess it can, if you define the problem correctly.
08:55ejacksona hesitate to ask..... what is blue eyes ?
08:55fliebelhttp://xkcd.com/blue_eyes.html
08:56fliebelI have set it as my home page until I solve it :)
08:57zippy314fliebel: nice1
08:58zippy314(s/1/!/) correction: fliebel: nice!
08:58ejacksoneep
08:59fliebelI have made a few assertions, but solved nothing yet...
09:00fliebelzippy314: If you'd have typed that regex without the cruft, sexpbot would have xxx it for you ;)
09:00fliebels/xxx/replaced
09:00sexpbot<fliebel> zippy314: If you'd have typed that regex without the cruft, sexpbot would have replaced it for you ;)
09:01zippy314text
09:01zippy314(s/x/s/) correction: test
09:01zippy314hmm what cruft?
09:01zippy314I just typed "s/x/s/"
09:01ejacksons/ee/EEEEEEEEEEEEEE/
09:01sexpbot<ejackson> EEEEEEEEEEEEEEp
09:02zippy314Could it be my client?
09:02ejacksonno you typed "correction:....." after the regex
09:03fliebelprobably.
09:03zippy314nope, I didn't I think my irc client must be doing that or something...
09:03ejacksonhaha, its like a macro. your client got it before sexpbot did :)
09:03fliebel$sed -zippy314 s/'t/'t,/
09:03sexpbot<zippy314> nope, I didn't, I think my irc client must be doing that or something...
09:04zippy314I'm using Colloquy (OS x)
09:04fliebel$sed -zippy314 s/x/X/
09:04sexpbot<zippy314> I'm using Colloquy (OS X)
09:04zippy314:-)
09:04fliebelOkay, I'll to annoying people...
09:05fliebels/to/stop/
09:05sexpbot<fliebel> Okay, I'll stop annoying people...
09:05zippy314is anybody else here using technomancy's emacs starter kit?
09:07raekI do.
09:08zippy314raek: where do you add your own emacs customizations?
09:11clgvfliebel: seems to be a proof by induction ;)
09:12incandenzazippy314: I use ~/.emacs.d/username.el
09:12fliebelclgv: uh?
09:13clgvfliebel: the blue eyes puzzle ;)
09:13fliebelclgv: the proof by induction ;)
09:13zippy314Looks like ~/.emacs.d/custom.el is also autoloaded for this purpose...
09:14incandenzathat is actually used for M-x customize
09:14incandenzayou probably shouldn't put stuff in there
09:14zippy314BTW if any body else is on a Mac and is annoyed by the default scrolling behavior of Carbon emacs, here's something that fixes it: http://www.emacswiki.org/emacs/SmoothScrolling
09:14neilcjzippy314: i throw any code in custom.el and it works, donno if that's ok :P
09:15clgvfliebel: you dont know the term, or what?
09:15fliebelclgv: I'm reading wikipedia now ;)
09:15zippy314incandenza: hmm, what's M-x customize for?
09:15clgvfliebel: ok^^
09:15raekzippy314: ~/.emacs.d/raek.el and ~/.emacs.d/raek/<oher files>.el
09:15incandenzazippy314: it's a way of setting configuration variables with a menu system
09:17raek"First, the user-specific-config file is the file named after your user with the extension ".el". In addition, if a directory named after your user exists, it will be added to the load-path, and any elisp files in it will be loaded."
09:17raekfrom https://github.com/technomancy/emacs-starter-kit
09:17incandenza^ yeah, follow that :)
09:17neilcjyeah, just moved stuff I'd added from custom.el to neilcj.el and everything worked: do that, zippy
09:42markskilbeckAnybody know of a trick in emacs to mimic aquamacs's ability to click a previously entered expression in the REPL to have it evaluated again?
09:44neilcjmiddle clicking an expression inserts it after the REPL prompt, if that helps
09:54raekhitting <ret> after a previous expression copies it to the bottom, iirc
09:54raekM-p can be useful too
09:58markskilbeckneilcj, raek: thanks
10:14zippy314raek: what do you do with M-p?
10:16semperos_go up one entry in REPL history in Emacs
10:17zippy314oh sweet! I need the slime repl cheat sheet.
10:18zippy314looks like there is one: http://www.pchristensen.com/slimecommands.pdf
10:25raekthe slime commands listed here are really useful: https://github.com/technomancy/swank-clojure
10:31hoggarthdo you have an easy way to convert a string to a list of characters?
10:33ejackson,(map identity "Hello, world!")
10:33clojurebot(\H \e \l \l \o \, \space \w \o \r ...)
10:33hoggarthnice
10:33Chousuke,(seq "hello world")
10:33clojurebot(\h \e \l \l \o \space \w \o \r \l ...)
10:33Chousukeuse that :P
10:33ejacksonnicer !
10:34Chousukeactually, since most seq-expecting things call seq on their argument anyway, you can often just pass in plain strings
10:34hoggarthi'll keep that in mind
10:35Chousuke,(first "foo") for example
10:35clojurebot\f
10:35hoggarththanks guys
10:51KruppeIs there any way of finding out what slots are in a class (short of using inspect or reading the source)?
10:52ejacksonKruppe: I usually use show from repl-utils
10:53Kruppeejackson: I'll take a look at it, thanks :)
10:53ejacksonalthough you should be careful with my advice, I haven't been correct yet today ;)
10:53Kruppeejackson: these things happen
11:20LuytMy solution for Euler #1, http://clojure.pastebin.com/rw9zgSyt , I guess I could use some range that counts to 1000 and filter it on multiplep(3) OR multiplep(5). Would that be more elegant?
11:24chouserI like what you've got.
11:25chouserhm, essentially identical, though I started my ranges as 0
11:25chouserat 0
11:27LuytSomehow expanding two lists, concatenating them, then making the numbers in it unique using 'set', seems like a detour to me.
11:28LuytI'd rather have one seq which counts from 0 to 1000, selects only the multiples of 3 and 5 from them, and sums those.
11:29incandenzaLuyt: you could do it like this: (reduce + (filter #(or (= 0 (mod % 3)) (= 0 (mod % 5))) (range 3 1000)))
11:29LuytAha, that looks more like it
11:31chouserLuyt: well, that means calling mod at least once on every number under 1000
11:32incandenzayes, it is slower, I noticed
11:32chouserwhat you've got now only touches numbers that will be included in the set
11:32LuytIndeed ;-)
11:33chouserand remember both ranges and concat are lazy, so it's not really expanding two lists before building the set
11:33LuytOh? I didn't know that.
11:35chouserthe set is what forces the realization of the lazy seqs in that expression, so really only one chunk of input numbers exists at any one time while the set is being built up
11:37symuynHey, is reverse on a lazy seq linear or constant?
11:38chouserlinear. reverse itself isn't lazy and realizes the whole input seq
11:38chouseras it of course must
11:38LuytHmmm when I run it on a range of 3000000 Incandenza's seems to be a lot quicker. How could you easily measure it?
11:39incandenzaI just used 'time'
11:39semperos_$doc time
11:39semperos_guess that only works for source...
11:39LuytAh, I'll try.
11:39symuynchouser: Is it the same for reversing vectors?
11:39Luyt,(doc time)
11:39clojurebot"([expr]); Evaluates expr and prints the time it took. Returns the value of expr."
11:40chouserbe careful doing micro benchmarks -- the JVM is complex and will give widely varying times, especially the first several times you run a particular chunk of code
11:40chousersymuyn: yes, but don't use reverse on a vector, use rseq
11:40symuynOh dear
11:40symuynThanks
11:41LuytIncandenza's code is quicker, at least on my machine. 588 msec vs. 3700 msec.
11:42incandenzaprobably the mod is cheaper than the set membership test, in the long run
11:42LuytYeah, because with smaller sets my code is slightly quicker
11:43incandenzaand I guess the set itself can't be lazy
11:43LuytWell, that's an interesting side effect ;-) On to problem 2...
11:47chouserset can't be lazy, but two sorted lazy seqs could be merged lazily, and adjacent dups could be removed lazily
12:16chouserLuyt: I added a solution to problem 1 at the bottom of http://clojure-euler.wikispaces.com/Problem+001 if you're interested.
12:18LuytInteresting to see all these solutions
12:18Luyt1000 ways to skin a cat
12:20LuytI see many people used the reduce, set, concat thing.
12:21chouserLuyt: they all either used a set, distinct (which uses a set internally), or subtracted the duplicate sum afterward
12:22chouserthat's what I thought it might be interesting to have the merge solution there -- it's the only one that skips the dups instead of subtracting them, but without building a full set
12:23LuytRight now I noticed by homebrewn fibonacci routine is dog slow, and my jaw drops when looking at http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci ;-)
12:23chouserI'm not saying it's better, just different. Ends up being a lot of code for such a simple problem. :-P
12:25symuynIf I want to make an empty collection as a base case for a sequence-returning function, should I use the empty list or the empty vector?
12:26chousersymuyn: well, are you building a vector, a list, or a lazy-seq?
12:27symuynA lazy seq
12:27chouseryou don't want nil for the base case/
12:27chouser?
12:27pdkok dumb q
12:28symuynchouser: Oh, of course. Silly me
12:28pdkwhat out of the box function would i use to append an item to a seq
12:28pdki see there's cons to prepend but i figured i could append in one step too
12:29chouserpdk: lazily without forcing it? a single item, or will it end up being many?
12:29pdkone item at a time
12:29pdkit can be lazy
12:30pdklet me guess it involves wrapping the item in () then doing lazy-cat :p
12:30chouserwell, concat then, but if you're doing it a lot that's rather inefficient
12:30pdkwhat would you suggest to optimize it or change the strategy
12:30mattmitchellcould someone recommend a lib for dealing with command line args?
12:31chouserpdk: use a vector instead of a lazy seq -- you can efficiently add to the right
12:32chouserpdk: or use lazy-seq directly
12:35pdkyeah i was thinking a vector though i didnt find anything right away to append to them
12:35semperos_conj
12:35chouserconj appends to vectors. very very fast
12:35pdkcould always use lazy-concat in place of concat too
12:35pdkhm here i was using conj on sets
12:35pdker lazy-cat
12:36semperos_conj is the cons of vectors
12:36semperos_and vectors efficiently add items to the right
12:36semperos_while lists to the left (head)
12:36chouserconj works on everything: sets, maps, vectors, lazy seqs, cons, ...
12:39LuytIs there a pastebin/codepad somewhere which will execute clojure code?
12:39pkinneyis it ok to paste a one-liner piece of code here?
12:39tonylpkinney, one-liners are fine
12:39pkinneytonyl: thanks
12:40pkinney(map #(bit-xor (int (get %1 %2)) (int (get %1 (- 1 %2)))) lock (iterate inc 0))
12:40semperos_put & at the beginning
12:40tonylLuyt maybe try-clojure but don't think it would return a paste url
12:40Luyt,(map #(bit-xor (int (get %1 %2)) (int (get %1 (- 1 %2)))) lock (iterate inc 0))
12:40clojurebotjava.lang.Exception: Unable to resolve symbol: lock in this context
12:40pkinneylock is a string
12:40Luyttonyl: I'll check.
12:41LuytArgh... "The service is not available. Please try again later." http://tryclj.licenser.net/
12:41tonyltry this http://www.try-clojure.org/
12:41pkinney,(map #(bit-xor (int (get %1 %2)) (int (get %1 (- 1 %2)))) "testing" (iterate inc 0))
12:41clojurebotjava.lang.NullPointerException
12:42pkinneyI think its throwing the error because the int is getting a nil on the last iteration
12:42tonylthere is no last iteration
12:42tonylis a lazy sequence
12:42pkinney(sorry the 1st)
12:42Luyttonyl: Thanks, that site is alive, however it won't accept opening parentheses. Could be a Konqueror issue ;-)
12:42tonyl&(take 100 (iterate inc 0))
12:42sexpbot⟹ (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99)
12:43Luytquick! What't the sum of that? (Gauss)
12:43tonylthe map function to apply to the items only takes 1 argument though
12:44tonylLuyt: crap forgot that, 5015?
12:44LuytN=100, N/2 * 100 - N
12:44tonyl&(get 0 1)
12:44sexpbot⟹ nil
12:44chouser&(get 0 1 :lunchtime)
12:44pkinneytonyl: I thought if u gave the map more args they run in parallel
12:44sexpbot⟹ :lunchtime
12:45LuytGauss solved that in a few seconds when he was a little boy (his schoolmaster gave him the silly assignment of adding the numbers 1 through 100 just to keep him busy)
12:45tonylpkinney: if you give it more then 1 collection ##(map vector (range 0 10) (range 11 20))
12:45sexpbot⟹ ([0 11] [1 12] [2 13] [3 14] [4 15] [5 16] [6 17] [7 18] [8 19])
12:48pkinneyyeah
12:48tonylLuyt: found this in my delicious http://ideone.com/ I knew I saw a service like that somewhere
12:48tonylpkinney: my bad, I forgot about the string there
12:48pkinneyI thought I could use the other coll (from iterate) as an index
12:49Luyttonyl: Looks very good, thanks.
12:49tonylit seems that the error might be in 1 of those gets
12:49tonyl&(map vector "testing" (range))
12:49sexpbot⟹ ([\t 0] [\e 1] [\s 2] [\t 3] [\i 4] [\n 5] [\g 6])
12:50pkinneyoh, does range work that way too, lol
12:50pkinneythats cool
12:51tonylyeah i use it for shortcut
12:51tomoj&(map-indexed vector "testing")
12:51sexpbot⟹ ([0 \t] [1 \e] [2 \s] [3 \t] [4 \i] [5 \n] [6 \g])
12:51amalloydo you really want (- 1 %2)? in infix that's 1 - %2
12:51pkinneyyeah
12:52tonyl(dec %2)
12:52sexpbot⟹ -1
12:52tonyl&(dec %2)
12:52sexpbotjava.lang.Exception: Unable to resolve symbol: %2 in this context
12:52amalloylol
12:52tonyllol
12:52pkinneyits xoring the letter together
12:52amalloytonyl: you activated the karma plugin
12:52tonylyeah
12:52tonylwonder who is %2
12:52amalloytonyl: nobody
12:52tonyl&(map (fn [[x y]] [(int (get x y)) (int (get x (dec y))]) "testing" (range))
12:52sexpbotjava.lang.Exception: Unmatched delimiter: ]
12:52amalloybut just in case he signs on
12:53pkinneyeg. t ^ e = 3... 3 ^ s... etc (3 is made-up)
12:54amalloypkinney: and you have negative numbers as keys in the maps?
12:54pkinneyoh, i'm wrong sorry... t ^ e, e ^ s...
12:54tonyl&(map (fn [[x y]] [(int (get x y)) (int (get x (dec y)))]) "testing" (range))
12:54sexpbotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: sandbox17750$eval19737$fn
12:55pkinneyamalloy: what do you mean?
12:55amalloy&(- 1 5)
12:55sexpbot⟹ -4
12:56amalloymy point is that (- 1 x) will be negative for any x larger than 1
12:56LuytWell, my solution for Euler #2. It contains some suckage...
12:56amalloyand you're using the result of as a key in your maps
12:56Luythttp://ideone.com/iCCOS
12:56pkinneyaaah
12:56tonyl&(int (get \t 0)
12:56sexpbotjava.lang.Exception: EOF while reading
12:56tonyl&(int (get \t 0))
12:56sexpbotjava.lang.NullPointerException
12:57tonyl&(int (get \t 1))
12:57sexpbotjava.lang.NullPointerException
12:57tonylpkinney: that might be your problem
12:57pkinneyyeah, thats it
12:58pkinney(need to find a way outa that
12:58amalloypkinney: ##(dec 5)
12:58sexpbot⟹ 4
12:59pkinneyIt'll strill try and get the -1 index though
13:00tonyli am guessing because of (dec 0)
13:00pkinney,(map #(bit-xor (int (get %1 %2)) (int (get %1 (dec %2)))) "testing" (iterate inc 0))
13:00clojurebotjava.lang.NullPointerException
13:00pkinneyyup
13:00LuytI think these Project Euler problems focus too much on math and not on real world problems
13:01pkinneyis there a quick way to get it to give a 0 if the index doesn't exist
13:01tonylthat is why is called Euler :P
13:01qojais there some short macro, to merge metadata (and not replece, like with-meta does) ?
13:01LuytI mean, to write a web app you don;t have to solve the sum of the first 10001 primes who are amicable
13:01amalloyLuyt: so don't solve them
13:01tonylqoja metadata is map and there is a merge fn for maps
13:02amalloypkinney: ##(get {} -1 0)
13:02sexpbot⟹ 0
13:02Luytamalloy: Excellent idea!
13:02tonylLuyt: it even says you can do them in paper
13:02qojatonyl: but what with (with-meta (fn .... ) (merge ??? { :my 'metadata }))
13:02tonylthe not-found arg I always forget it too
13:02qojai could of course write a fun for that, but isn't there one standard already?
13:03Luyttonyl: My dad studied math and he solved some problems by just analysing them... while I pull out my fav language and go bruteforce it ;-)
13:03pkinneythanks
13:03tonylLuyt: I wish I could do that like your dad, but I like bruteforcing every now and then
13:04tonylqoja: as far as I know there isn't
13:04raekqoja: vary-meta
13:04raek,(doc meta)
13:04Luyttonyl: Yup. But not in all cases bruteforcing is even remotely possible.
13:04clojurebot"([obj]); Returns the metadata of obj, returns nil if there is no metadata."
13:04raek,(doc vary-meta)
13:04clojurebot"([obj f & args]); Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadata."
13:04qojatonyl: ok thanks, i thought it maybe is present int contrib. it seems to be a common scenario
13:05tonylyeah and raek's suggestion might help
13:05qojaraek: that's what i need
13:05qojathx
13:06amalloy&(vary-meta #'first (comp merge meta) #'comment)
13:06sexpbotjava.lang.IllegalArgumentException: Wrong number of args (2) passed to: core$meta
13:06amalloyoh duh
13:07amalloy&(vary-meta #'first merge (meta #'comment))
13:07sexpbotjava.lang.ClassCastException: clojure.lang.Var cannot be cast to clojure.lang.IObj
13:07tonylwhat's up with var's private meta? what is it used for?
13:09raekit stops people from making functions that use those vars outside the namespace they live in
13:10tonylok thanks raek
13:11raek,clojure.core/array
13:11clojurebotjava.lang.IllegalStateException: var: clojure.core/array is not public
13:11raek...or from even using it from the outside of the namespace
13:11raek,@#'clojure.core/array ; with exceptions... :-)
13:11clojurebot#<core$array clojure.core$array@1479a6b>
13:12symuyn&(seq? nil)
13:12sexpbot⟹ false
13:13pdk,(Integer/parseInt "3")
13:13clojurebot3
13:13pdk,(Integer/parseInt 3)
13:13clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
13:26mattmitchellhow can i check if a variable exists?
13:28mattmitchelli guess i mean, how can i check if a var exists?
13:28raek,(doc resolve)
13:28clojurebot"([sym]); same as (ns-resolve *ns* symbol)"
13:28kumarshantanumattmitchell: the compiler checks that for you :-p
13:28raekmaybe this
13:28mattmitchellinteresting
13:29raekyou very rarely need to use it though...
13:29mattmitchellmakes me think i might be handling this bit of code incorrectly then :)
13:38bendlaskey folks!
13:38bendlas/s/key/hey/
13:39bendlasfun clojure quirk of the day
13:39bendlas,(loop [x 5]
13:39bendlas (when (pos? x)
13:39bendlas (try
13:39clojurebotEOF while reading
13:39bendlas (recur (dec x))
13:39bendlas (finally (print x)))))
13:39bendlas,(loop [x 5] (when (pos? x) (try (recur (dec x)) (finally (print x)))))
13:39clojurebotbendlas: No entiendo
13:40chouserthe bots don't like you using try/catch
13:40bendlasOIC
13:41chouserthey could be used to prevent killing of runaway exprs and such.
13:41bendlasguessed that
13:41bendlasanyways, the expression compiles, but the finally is silently discarded
13:41bendlasdue to the recur
13:42hiredmanbendlas: thats a bug, the latest clojure won't compile the expression
13:42raek,((fn f [x] (when (pos? x) (try (f (dec x)) (finally (print x))))) 5)
13:42clojurebotraek: Huh?
13:42hiredmanrecur is not allowed across try/binding
13:42raekright. the catch form.
13:43bendlashiredman: so it's on the radar already, good
13:45hiredmanbendlas: recuring across a dynamic context like try or binding is a buggy way of thinking, the compiler was just loose in allowing you to shoot your foot off
13:49bendlasactually, I need a variation of (binding ) that works on #'var s, with each binding expression in a try
13:49bendlasbut using recur there smelled fishy right away, so i checked first
13:49bendlasluckily
13:51hiredmansounds icky
13:52bendlasit does
13:53bendlasand of course there is a simpler way, which i've just realized
13:55pkinneyis there an easy way to add an item to the beginning of a coll? like a reversed conj?
13:55bendlas(cons item collection)
13:55chouserpkinney: conj on a list adds items to the left
13:55hiredmanconj add items in the most effecient way
13:55hiredman,(conj [1] 2)
13:55clojurebot[1 2]
13:55chouser,(conj '(b c d) a)
13:55clojurebotjava.lang.Exception: Unable to resolve symbol: a in this context
13:55chouser,(conj '(b c d) 'a)
13:55hiredman,(conj '(1) 2)
13:55clojurebot(a b c d)
13:55chousersigh
13:55clojurebot(2 1)
13:55chousersorry
13:56pkinneychouser: ah rite, thanks :)
13:58pkinney(how didn't I notice that? heh)
14:12pkinneygaaah, I'm still stuck in the mold (of OOP)
14:14amalloypkinney: OOP backwards is POO. keep that in mind
14:15pkinneyhehe
14:15pkinneyI just think the overall design of my functions are wrong
14:17pkinneyhttps://gist.github.com/799022
14:17amalloycould be. everything's a learning experience
14:17pkinneymy ugly function
14:17pkinneyI'm abusing let
14:18amalloypkinney: fwiw (list* s) should be the same as just plain s, unless you want to coerce some other sequence to be specifically a list
14:19pkinneyOh
14:19amalloyand there's nothing wrong with using let to label intermediate results, although you might want to pick names that mean something :P
14:20pkinneyheh, yeah a to d isn't good for variable names
14:20amalloyif you just want to reduce the nesting factor of your intermediate results, you can use -> or ->> instead
14:21pkinneyI've seen other code snippets about using -> and ->>, thought they were interesting, but haven't got my head round them enough to using them
14:21amalloy(->> (count lock) (reduce some-fn) (conj (map other-fn other-data)) (map nibble-swap) (map char) (apply str))
14:21pkinneydoes it just push the result onto the next...
14:21pkinneyaah
14:22amalloy&(macroexpand-all '(->> (range) (filter even?) (drop 100) (take 100) (reduce +)))
14:22sexpbot⟹ (reduce + (take 100 (drop 100 (filter even? (range)))))
14:22pkinneycould take out the let altogether then?
14:22zippy314I'm trying to remove an item from a ref to a vector. I can't figure out why this doesn't work: ##(def x (ref [1 2 3 4])) (dosync (alter x remove [#{2}]))
14:22sexpbotjava.lang.SecurityException: You tripped the alarm! def is bad!
14:22zippy314oops
14:23amalloyzippy314: #{2}, not [#{2}]
14:23chouserzippy314: x bevomes the first arg to remove, which is probably not what you want
14:23amalloyoh, or chouser is so right
14:24pkinneyamalloy: thanks, thats gave me some food for thought
14:24amalloypkinney: welcome, and enjoy it. i'm off
14:24pkinneyme too ^_^ thanks again
14:25zippy314amalloy: that doesn't work either: ##(let [x (ref [1 2 3 4])] (dosync (alter x remove #{2})) @x)
14:25sexpbot⟹ ()
14:27zippy314so, I'm trying to figure out what's the proper way to remove an item from a ref to a vector?
14:28amalloy_zippy314: chouse [as usual] has the right answer
14:28amalloy_(alter x #(remove #{2} %))
14:29chouserzippy314: removing items from a vector is suspect in the first place. you're sure you don't want a set instead?
14:29tonylthe way alter is calling is like (remove @x #{2})
14:29shortlordis directly using an (immutable) var in a function without passing the var as an argument considered to be impure?
14:29tonylyes, but you can still do it
14:29zippy314Well, the thing is I care about the order.
14:29hiredman:(
14:29zippy314is there and ordered set?
14:29chouserthere's a sorted set
14:29hiredman(alter x (partial remove #{2}))
14:31zippy314yah baby! that's what I really want, sorted-set. Cool.
14:31jweiss_can someone point me to a typical dir structure for a project with java and clojure source? (/src/java, /src/clj)? (java/src, clojure/src)? etc
14:31chousernote that remove will return a lazy seq, not a vector, and because it's lazy has the potential to stack calls when later realized
14:32zippy314but how do you define the sort algorithm?
14:32shortlordtonyl: but using other functions directly would not be considered impure, right?
14:32chouserzippy314: see sorted-set-by, but be aware that if your fn says two things are equal, only one will be stored in the set
14:32jweiss_clojure itself uses src/clj and src/jvm, oddly
14:33chouserjweiss_: the maven standard is something like src/main/clojure and src/main/java
14:33tonylshortlord: what do you mean directly
14:33technomancyjweiss_: consider why you feel that Java code needs to be in a separate dir
14:33chouser...and there's the non-maven voice. :-)
14:34jweiss_technomancy: i suppose that was a false assumption that it DOES have to be separate?
14:34chouserjweiss_: it'll depend on your tools.
14:34shortlordtonyl: well, where's the difference between using vars or functions in another function without passing them as arguments? using built-in functions like map is not considered to make a function impure, so why is using an immutable var?
14:34technomancyjweiss_: maybe you have a good reason, but I don't think most people do
14:34technomancyworth some thought =)
14:34jweiss_i'm using leiningen to build, so i assume if the creator of lein says its ok then lein won't complain either
14:34jweiss_:)
14:35jweiss_i suppose that if it doesn't work out, separating the two types of files won't be hard.
14:38tonylthe functions you pass to map won't change anything, it would just create a new value and map would save those values in a seq
14:38tonylvars are global objects
14:38technomancyjweiss: for the record I haven't actually tried that; I have noticed that it hasn't been a problem to keep JS files in src.
14:38tonylI think I might be missing something here
14:39chouserdoes lein know how to compile .java files?
14:39technomancychouser: yeah, added in the latest version
14:39jweiss_technomancy: as long as lein will still know to compile java, and put the class files in the jar, along with the clj files, i'll be happy
14:39shortlordtonyl: no, I mean using 'map' inside one of your functions without passing the map function as an argument. (quite theoretical, I know). Just using clojure's core functions is conceptually not different to using your own functions without passing them as arguments
14:40shortlordtonyl: and since vars could be functions or anything else but are in any case immutable, I don't see why just using them in a function without passing them as an argument makes the function impure
14:41tonylshortlord: oh that is a good question about the purity or functional langs. in the strictest of meanings that is impure
14:43tonylshortlord: but as you say you would need some impurity to use the language functionalities. I would say AFAIK in clojure you can use global functions inside your functions, but when it comes to other values in vars, depend less on those.
14:43tonylbut that is my opinion
14:43shortlordI ask about that quite theoretical thing, because I still have problems determining how pure any particular function in my code should be. For small problems it's quite easy to stay very pure, but in a larger project all the functions seem to require more an more arguments to stay pure
14:45tonylgood question, but if you want to stay really pure then you can only use the special forms that clojure comes with, which I think are about 12.
14:46tonylthat would be a tedious language to use, instead of using of the available library functions like the seq, maps, vectors, etc ... functions
14:47shortlordtonyl: I am not very interested in staying pure for the sake of staying pure, but I have the feeling that I'm often still doing things too imperatively. Whenever I try to actively write pure code, it's very hard to determine when to pass which things as arguments and when to use something directly
14:48shortlordis there any good resource on software development using functional programming that is largely language agnostic and goes beyond explaining the functional concepts in terms of isolated 5 - 50 lines examples?
14:49tonylshortlord: I battle with that thinking sometimes. but I haven't stumble upon a source like that. I have just started reading the SCIP book and it seems quite good in functional concepts, although it uses scheme to illustrate
14:50tonylI have just started with functional programming with clojure
14:50technomancyscheme is as close to language-neutral as you can get
14:51tonyltechnomancy: yeah, I can understand about 80% of what the code means. maybe because I have some clojure exposure
14:51shortlordI've already heard quite a few good things about SICP, I guess I should really put it on my to-read list
14:52shortlordthx for the suggestion :)
14:53edwshortlord: And watch the H-P lectures from the '80s by Sussman & Abelson.
14:53benreesmanwhat is the idiomatic way in clojure to assoc a key that's nested in a map, perhaps several levels in?
14:53semperosassoc-in, I think
14:54semperos,(doc assoc-in)
14:54clojurebot"([m [k & ks] v]); Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-map...
14:54shortlordbenreesman: if you simply want to assoc it, use assoc-in, otherwise update-in can operate on it using a function
14:54benreesmanthank you!
14:57benreesmanis there a way to have it add the keys if not present as maps?
14:58semperospart of the docs for assoc-in
14:58semperos"If any levels do not exist, hash-maps will be created"
14:59semperosthat what you meant?
15:01benreesmandefinitely
15:02benreesmanbrilliant, works like a charm
15:16sritchiehey all -- I'm looking to work with a java function that takes a byte array as a parameter and fills it with data. this sort of goes against the clojure way, as data structures are supposed to be immutable -- also, when I pass in the symbol for my array (defined with (def array (byte-array (* 1200 1200)))), it doesn't change
15:17sritchiewhat's the most idiomatic way to deal with a java method like this?
15:19tonyli don't think that java fn would know how to change the value of a binding to the var that is holding the array
15:20brehauttonyl: by the byte array itself is a mutable block of memory
15:20tonylmmm... I haven't done anything like this, but maybe somebody here hve
15:20brehauts/by/but/
15:20sexpbot<brehaut> tonyl: but the butte array itself is a mutable block of memory
15:20sritchiegot it, so it's modifying the array, but can't switch the binding over
15:21brehautsexpbot, that wasnt a general regexp. why did you apply it twice?
15:21brehautsritchie: no
15:21tonylthankr brehaut, I clearly need more knowledge about this then :)
15:22sritchiethe other option is a method that returns a DirectByteBuffer
15:22brehautas i understand it, all array types are mutable, and largely exist for interop (and speed)
15:22tonylI can see that in the code now
15:23brehauti think something else is going wrong to cause sritchie's array to not be modified
15:24brehautsritchie: also idiomatically, i think you would try to isolate the code that worries about mutation as much as reasonably possible.
15:24brehautie keep it internal to one function
15:25amalloy_brehaut: sexpbot does a global replace. he's not perl, awk, or sed, he's just looking for s/foo/bar (optional trailing slash)
15:25sritchiebrehaut: I'm reading MODIS tiles from nasa, enclosed in these dataset objects -- reading this byte array is the last step before I can free myself from mutable arrays
15:26brehautsritchie: thats fine then. java interop is 'first class' code in clojure
15:26brehautamalloy: apparently so :P
15:27tonylsritchie: you can use java structures in clojure functions too
15:28sritchiewell, looks like my first step is figuring out why that byte array isn't being modified
15:29tonylmaybe the java function is not actually changing it?
15:30brehautsritchie: does you java function have some api docs (or better source) on the internet?
15:30brehautand can you paste your snippit somewhere?
15:30sritchieyeah, here's the doc -- http://gdal.org/java/org/gdal/gdal/Band.html#ReadRaster_Direct(int, int, int, int)
15:30sritchiebrehaut: pardon, here it is -- http://gdal.org/java/org/gdal/gdal/Band.html
15:32sritchiehttps://gist.github.com/799187
15:32sritchiethat's how I was calling it
15:33sritchieI'm going to go verify that the Band has good data in it
15:33brehautsritchie: thats a good idea.
15:33tonylthat method needs a ByteBuffer object
15:34brehauttonyl: its heavily overloaded
15:34sritchietonyl: yeah, check the example at the very top, it just needs a byte array
15:34tonylyeah I scrolled further more
15:34tonyli see the method signature now
15:35tonylmaybe type hinting would help resolve which method is being choose to operate
15:36sritchietonyl: looks like the method is returning CE_None, which shows that all went well -- I'm going to try this with a different dataset, and see what happens
15:36tonylok
15:36sritchiebut the fact that the method can modify a byte[] created with byte-array is great
15:36sritchiethat simplifies this application quite a bit
15:37brehautsritchie: are any exceptions being raised about finding methods?
15:38brehautim presuming not, otherwise you probably would have mentioned them before now?
15:38sritchiebrehaut: no, the application finds the method, and returns 0, which is CE_None (meaning no failure), but the byte array returned the same value from the REPL
15:39sritchieI assumed that it hadn't been modified, since (take 100 gdal-bytes) resulted in 0s, but based on these answers and the CE_None, I'm worried that I chose an empty band
15:42brehautsritchie: use (some (complement zero?) gdal-bytes)
15:42brehautit will return true if there is a non zero value and nil otherwise
15:43brehautinstead of take 100
15:44sritchieyeah, I do get true
15:44brehaut100 bytes out of 1400000 is not a very reliable sample
15:44amalloyor (not-every? zero? bytes)
15:44brehautamalloy cleans up my mess again :P
15:44amalloyi think that exists. maybe not. ##(doc not-every?)
15:44sexpbot⟹ "([pred coll]); Returns false if (pred x) is logical true for every x in coll, else true."
15:44amalloywhew
15:45brehautamalloy: and it works right too
15:45tonyllol not-every is just (comp not every?) oh i love it, so simple
15:46sritchiehey, great, this --
15:46sritchie (some #(if (or (zero? %) (neg? %)) nil %) my-bytes)
15:46sritchiereturns 30
15:46tonylso there are values
15:46sritchieyup, looks like all's well
15:46tonyl:) I learned from this one too
15:47sritchieso! the lessons of today are -- byte arrays are mutable, and don't use (take 100 array) to investigate a 1200 x 1200 array
15:47brehauttonyl: i learnt from tutoring at university that helping other people is always the best way to learn
15:48tonylbrehaut: so true
15:48brehautsritchie: you next lesson is to take that test case, and write a deftest for it
15:49sritchiebrehaut: sounds like a plan, that's a great idea
15:49brehautwhich reminds me that i want to look into midje more
15:49sritchiethank you guys for the help, the clojure community's been fantastic
15:57brehautit is definately time for a pot of tea
15:57amalloybrehaut: make some for sritchie too
15:58amalloysritchie: btw that #(if ...) thing you did earlier is a complicated version of when-not
16:00brehauti would pay money for a good A3 cheatsheat/quickref poster
16:00amalloy&(when-not (zero? 0) 10)
16:00sexpbot⟹ nil
16:01sritchieamalloy: does when-not return the value that it stops at?
16:01amalloyno, when-not is just a tweaked version of if, not of some
16:01sritchiegotcha
16:01amalloyyou might also look at (first (filter #(when-not ...)))
16:01brehautsritchie: there is a large family of if and when functions
16:02amalloyor i guess (first (filter pos? coll))
16:02amalloynow that i've actually read your or expression :P
16:03sritchiehey, I like that better
16:03amalloyif you didn't, i'd suggest getting your head examined :)
16:05sritchieespecially since my test was sort of meaningless, just meant to reassure me that this damned data exists, I can (take 10 (filter pos? coll)) to my heart's content
16:06amalloy&(->> (range) (filter even?) (filter odd?) first)
16:07amalloymy favoritest infinite loop
16:07sexpbotExecution Timed Out!
16:07brehauthuh. so it is
16:07amalloyfind me the first odd even number, plz
16:08sritchievery nice
16:09tonylwouldn't that be just 0
16:12brehaut,[(odd? 0) (even? 0)]
16:12clojurebot[false true]
16:13amalloyone that's a little sneakier is (->> (range) (map (partial * 2)) (filter odd?))
16:16sritchieOne quick question -- for that particular method we discussed, is it preferable to convert the java array into a vector, after the mutation?
16:16tonylI guess I meant mathematically speaking
16:17tonylsritchie: to use it in clojure world?
16:17sritchieyeah, with incanter -- I need to cut the array up and form 2d time series arrays
16:17brehauttonyl: ok. how about this. Oddness is defined in terms of evenness. Evenness is defined as devisible by 2 with no remainder
16:17brehautoddness is the complement of evenness
16:18tonylso 0 can't be use as a value if it is the pivot used to test evenness
16:19raeksritchie: the functions in clojure's sequence library will call seq on the argument, so to use arrays with map, filter, reduce, et.c. you donät have to do anything
16:19tonylbut we need practicality in programming so that would suffice :P
16:19raek*don't
16:19brehauttonyl: i dont understand?
16:19sritchieraek: but is it preferable to convert to vector to get immutability?
16:20brehautsritchie: someone has to go out of their way to mutate the array
16:20brehautusing (frinstance) aset
16:20brehautor passing it to some java
16:20sritchiebrehaut: got it, and since I'm writing the code, (vector ... ) would just be an extra operation
16:20brehautyes, although you'd use vec
16:21tonylI mean we are using 0 in the implementation of even? to test if 0 is even or not
16:22raekif you can't know whether the other code in your progam (or the libraries it uses) will respect your wish for it to remain constant, then I guess you need to create a immutable version of it
16:22brehauttonyl: in what sense? (defn even? [n] (= 0 (mod n 2))) would be my first guess at the imp
16:23raekif it never escapes your function in array form, there's no need to worry
16:23sritchieraek: got it, makes sense
16:23raekyou could just call seq on it to hide the fact that the data is in a vector
16:23tonylbrehaut: but you are trying to find the evenness of 0 by testing an operation (mod) against 0
16:24brehautthats fine
16:24brehautsurely
16:24tonylyeah it is
16:25tonylI am just saying that I was thought in math classes that 0 can be even or odd and positive or negative
16:25brehautim not sure i understand how that invalidates the 0 as a part of the series of even numbers though
16:26hiredmanhttp://en.wikipedia.org/wiki/Parity_of_zero
16:26hiredmantonyl: that is not true
16:27brehauthiredman: huh, scales make the meaning even particular intuitive
16:28tonylhiredman brehaut: thanks for the info. I am going to have to send a very angry letter to my math professors now
16:29brehautthat would be a funny letter :P
16:29hiredmanplease do, be sure to also complain if you were taught that multiplication is repeated addition
16:30tonyla quote from the wiki page 'For them the question exemplifies "common knowledge ... that any well-educated adult should have"'
16:31tonyli guess i am not an adult yet then
16:31tonylhiredman: yeah they did that too
16:31pdk,(Math/pow 2 50)
16:31clojurebot1.125899906842624E15
16:31pdkgreat
16:31hiredmanhttp://scienceblogs.com/goodmath/2008/07/teaching_multiplication_is_it.php
16:32brehautobligatory xkcd http://xkcd.com/123/
16:33hiredmanthat is a good one, I'd not seen it before
16:34brehautit was footnoted in the most recent one
16:34brehauti had forgotten about it
16:34brehaut(being bad at both physics and bond films)
16:40pdk,(Math/pow 2 25)
16:40clojurebot3.3554432E7
16:58sritchiehey guys, is it preferable to typehint on java interop as a matter of course (for a third party API, say), or is it best to do it only on performance bottlenecks, as the clojure documentation suggests?
17:03tonylperformance bottlenecks except for swing, swing doesn't like reflection
17:03RaynesSwing doesn't like humanity.
17:07joly,(doc gcd)
17:08clojurebotGabh mo leithscéal?
17:08ossarehis there a tool that does the reverse of hiccup? i.e. reads some html and gives me a bunch of vectors?
17:08brehautossareh: enlive
17:08ossarehbrehaut: of course!
17:09bendlasonly it gives you {:tag :html :attrs {} :body []}
17:09raekenlive<->hiccup https://gist.github.com/633049 :-)
17:10brehautraek: nice :)
17:10raekthere are other wrapping libs than Enlive that use Tagsoup for parsing
17:11raeksome of them output data in hiccup style
17:11ossarehThat is awesome
17:12ossarehSo, while we're on this - my app has the need to create html - which I was hoping to later on postwalk to replace certain things in the tree - i.e. if it see <r:user:name> it knows to replace it with (:name user). Is there such a thing already?
17:13raekenlive can match and replace elements
17:13ossarehawesome
17:13raekit is often used as a html templating engine
17:13raekthat's the thing it does besides the parsing
17:14bendlasindeed and it's the winningest html templating engine i know of, btw
17:14konrI've got a package "foo" with a global *bar* and many different function sets operating on it so that there are namespaces foo.fun1, foo.fun2 etc. Where should I put *bar*? In a new namespace like foo.variables? Or I can :use foo.core on foo.fun1 etc and vice versa?
17:14raekexample for a guestbook: https://github.com/raek/lcug-guestbook/blob/master/src/se/raek/lcug/guestbook/view.clj
17:15ossarehhuh - I've been using hiccup for the past 2 or so months. Is enlive significantly better suited to this type of thing? (i.e. is it worth the time to convert)
17:15raekrunning server: (beware of retro 90's html, your eyes might hurt a bit) http://services.raek.se/guestbook/
17:16ossarehIt is very likely that much more of my application will have the html created in something like TinyMCE and data just "slotted in".
17:16raekAFAIC, hiccup only does clojure data to html conversion
17:16tonylkonr: I am guessing you are refering to namespace foo not package "foo"
17:16konrtonyl: yes, indeed
17:16tonylkonr: usually if it is a global var it goes in the core
17:16tonyllike foo.core/*bar*
17:17tonylor just the base like foo/*bar*
17:17raekkonr: namespaces cannot have cyclic dependencies
17:17ossarehraek: in that example deftemplate is reading that html, throwing it into a var and then what are the forms after that? Perhaps replacing the content of those entries with the output of the form?
17:18raekyes, those forms describe what html elements to match and what to do with them
17:18raekyou use CSS-style selectors
17:19ossarehright
17:19ossarehI do like that. A lot in fact.
17:19ossarehdeftemplate seems to be reading from the filesystem - that could come from anywhere I hope?
17:19raekthe right hand side is a function that takes the subtree and returns a (potentially) altered one
17:20bendlasossareh: enlive is especially worth it, when you have html from other sources. generating new html based on existing html is the thing enlive does.
17:20raekyes, it's just one of the convenience macros, iirc
17:20raekLauJensen has written about enlive in his blog
17:20LauJensenmany times :)
17:21ossarehraek, bendlas: awesome - thanks. I'm going to spend some quality time with it.
17:22pdk,(apply +)
17:22clojurebotjava.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$apply
17:22pdkhmm
17:22brehaut,(apply + [])
17:22clojurebot0
17:23brehautapply needs a fn and a seq minimum
17:24pdki was looking for an equivalent to funcall but hey
17:24pdkguess wrapping the function i generate in extra parens will work
17:24brehaut,(+)
17:24clojurebot0
17:24pdk,(Math/pow 2 13)
17:24clojurebot8192.0
17:24raekyes, the first thing in the list just has to evaluate to something that implements IFn. no funcall is needed.
17:25bendlas,(.invoke + 1 2)
17:25raeklike in Scheme
17:25clojurebot3
17:25bendlas,(.invoke +)
17:25clojurebot0
17:26raek,(* (+ (*) (*)) (+ (*) (*) (*)) (+ (*) (*) (*) (*) (*) (*) (*)))
17:26clojurebot42
17:27brehauthaha awesome
17:27bendlaswow
17:27bendlasjust wow
17:27brehautreal simple
17:27brehautthe identity of multiplication is 1
17:28ossarehLauJensen: so bestinclass is built with the manly sounding CMS you eluded to close to new year?
17:28brehautif you think of * as reducing its arguments, you'd have (reduce binary_mult 1 seq)
17:29brehautso you can use (*) as weird-hand for 1, and the rest is basic math
17:34brehauthuh
17:35brehautthe implementation of + is actually really close to that, jsut with some explicity arities and an inline
17:35brehauts/+/*/
17:36tonylbut + with zero args returns 0
17:36bendlasyeah, rich knows his algebra
17:37brehauttonyl: yes, 0 is the identity for addition
17:37tonylyup
17:38mattmitchellhow can i test a files existence in clojure?
17:39bendlassee java.io.File
17:40bendlaswith convenience fns from clojure.java.io
17:40mattmitchellbendlas: excellent thanks!
17:43bendlasclojurebot: do you do javadoc?
17:43clojurebotPardon?
17:43bendlas,(javadoc java.io.File)
17:43clojurebotjava.lang.Exception: Unable to resolve symbol: javadoc in this context
17:43bendlasclojurebot: google java.io.File
17:43clojurebotFirst, out of 535000 results is:
17:43clojurebotFile (Java 2 Platform SE v1.4.2)
17:43clojurebothttp://download.oracle.com/javase/1.4.2/docs/api/java/io/File.html
17:50zanes_dnolen: Why?
17:50Raynesmattmitchell: (.exists (java.io.File. "/home/matt/somefile"))
17:51mattmitchellRaynes: That's exactly what I'm looking for thanks!
17:51raek(also consider using clojure.java.io/file for joining path segments in a platform independent way)
17:54dnolenzanes: seems like a fantastic way to annotate code w/o cluttering it up with comments while under heavy development. also seems like a great way to annotate other people's code while you're figuring it out.
17:54raekinteresting
17:55raekespecially the second usage
17:55mattmitchellI have a condition setup, where if the test is true, I'd like to print a message and then call (System/exit 0)
17:55mattmitchellbut the (System/exit 0) part is never executed.
17:55mattmitchellonly the printing of the message
17:56semperosyou capturing the actions in a do block?
17:56tonyl(when true (println "message) (System/exit 0))
17:56tonyl&(when true (println "message) (System/exit 0))
17:56sexpbotjava.lang.Exception: EOF while reading string
17:56mattmitchellno
17:56tonyl&(when true (println "message") (System/exit 0))
17:56sexpbotjava.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
17:56semperosif you're using an if expression, the second form is the 'else' statement
17:57semperosi.e. the second form after the condition
17:57mattmitchellsemperos: ok i see
17:57tonyl&(if true (do (prn "message") (System/exit 0)))
17:57sexpbotjava.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
17:57semperosyep
17:57mattmitchelltonyl semperos thanks!
17:58brehautmattmitchell: do look at the flow control section of http://clojuredocs.org/quickref/Clojure%20Core
17:58brehautthere are a lot of short hand forms that will make your life easier
18:05mattmitchellbrehaut: awesome thanks
18:06mattmitchellbrehaut: very helpful indeed
18:06pdk,(Math/pow 2 20)
18:06clojurebot1048576.0
18:11jweiss_i know this is only tangentially related to clojure, but somebody here probably knows the answer: when i run 'lein deps', the deps that are SNAPSHOT versions do not get updated from the remote repository, it just copies the existing snapshot from the local repo. is there a way to change this behavior?
18:13dakronejweiss_: lein will check once a day for an update to snapshots
18:13jweiss_dakrone: is there a way to get it to check every time?
18:13technomancyif you need more than that you should probably use checkout dependencies
18:14dakronejweiss_: you can remove it from your ~/.m2 dir
18:14technomancyjweiss_: I attempted to implement that, but the Maven API call to force it to check every time seemed to be a no-op.
18:14technomancycould be I was doing something wrong, but checkout deps are generally a better solution for most cases
18:14jweiss_hm. maybe i can run mvn -U ?
18:14technomancythat works too
18:14jweiss_i suppose rm -rf will work just as well
18:15jweiss_ok thanks
18:23ossarehso, with enlive, when I deftemplate name file - what are the lookup semantics for where that file is? I'm getting an NPE with all sorts of different path attempts
18:25brehautossareh: your classpath i believe
18:26brehautoh, maybe source path
18:28ossarehbrehaut: cool - looks like you're right (just stepping through the enlive code now) clojure.lang.RT/baseLoader
18:28brehautossareh: ok cool, i'm making pigs out of the sausage of my own sites implementation
18:29brehautin lein i have :source-path defined as "src", and inside src i have templates/….html and my deftemplates are qualified with respect to src
18:31ossarehaha - when you package up with lein war is everything kept sane?
18:31brehauthaha no i use ductape and string :P
18:31brehautim sure most sane people will chastise me for my deployment strategy
18:32ossarehbrehaut: I think we're in the same camp - so not chastening from me =)
18:32brehauti git pull on the live site, lein uberjar, kill the old process, java -server -jar ... & disown
18:32ossarehheh - pretty much similar except I scp the uberjar from my local machine
18:33brehautah right. i have all my media resources served by nginx on a subdomain
18:33brehautandi just point it at the git repo
18:33technomancyas long as it's not production code...
18:33brehauttechnomancy: what do you mean by production ?
18:33technomancylive users; your job on the line, etc
18:33brehautoh right
18:33brehautnope
18:34technomancyok, carry on =)
18:34brehautif it was my job to run my blog, i'd have a lot more time to get the deployment sorted, and i'd earn a lot less :P
18:35ossarehtechnomancy: if I specify resources-path is that imported into a jar / uberjar ?
18:35technomancyossareh: yeah. you don't have to specify it; if you have a resources/ directory, then it will be included in the jar
18:35ossarehoh, OK.
18:35ossarehthanks :)
18:36technomancysure
18:37brehautossareh: theres a bunch of different lein plugins for different automated deployment tools/strategies these days.
18:37brehautrealistically i should put aside half a day to learn one
18:38ossarehbrehaut: blog about it :)
18:38brehauthaha
18:38brehautno doubt
18:39__name__brehaut: would you mind giving me the url to your blog?
18:39brehauthttp://brehaut.net/
18:39__name__does not load for me
18:39brehautcomments about the colors can be redirected to /dev/null/
18:40brehaut;)
18:40__name__brehaut: i do not get any meaningful page with chromium
18:40__name__echo "my eyes!" > /dev/null
18:41brehauthmm. it looks fine in both safari and webkit for me
18:41brehautand http://www.downforeveryoneorjustme.com/brehaut.net says its up
18:41__name__brehaut: i do get /something/.
18:42ossareh;)
18:42brehautossareh: OMG monads WTF is reasonable
18:42ossarehtechnomancy & brehaut - thanks - I now have my deftemplates working =)
18:43brehautno worries
19:04joshua__I'm using duck-streams write-lines method to write a file on a Linux OS which is than read by a C++ program on a Window's OS.
19:05joshua__The program doesn't run as expected. When you open up the file in Notepad there is an invisible char directly before line breaks.
19:05joshua__I get that this is some sort of new lines are different based on operating system thing, but how do I fix this?
19:06brehautthe basic newline differences would go the other way
19:06brehautunix uses \n and windows uses \n\r (i think that way round)
19:07brehautstart with opening the file in a hex editor or something
19:07joshua__So what is my actual problem?
19:07brehautyou need to look at the files byte contents, rather than a text editors interpretation
19:07brehauttext file encoding is a broad and subtle field for erros
19:08joshua__brehaut, how do I view the byte contents?
19:08brehauthex editor or something
19:09brehautjoshua__: http://ubuntuforums.org/showpost.php?p=277111&amp;postcount=2 for linux
19:09joshua__thanks
19:09brehauta good hex editor wil lshow you line number, bytes as hex pairs, then the ascii output
19:10brehauthttp://stackoverflow.com/questions/10426/what-is-a-good-windows-hex-editor-viewer for windows
19:11brehautalso, check the very first two bytes in the file
19:12brehautthats where a byte order mark appears if it has been included (common for UCS and some UTF encodings)
19:12brehauthttp://en.wikipedia.org/wiki/Byte_order_mark
19:20joshua__brehaut, thanks for pointing me in the right direction. If I dig into hex to fix a bug I'm allowed to call myself Mel, right?
19:21brehautonly if you rewrite your duckstream to take into account of drum timings to control program flow.
19:21brehautusing a hex editor to fix a bug is just unlucky
19:40ossarehOK. enlive rocks.
19:41brehauttotally eh
19:42brehautone really nice property is that you can work on the design by just editing the template without any other webserver or anything in between.
21:00pdk(doc bindings)
21:00clojurebotExcuse me?
21:00pdk(doc binding)
21:00clojurebot"([bindings & body]); binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before. The new bindings are made in parallel (unlike let); all init-exprs are evaluated before the vars are bound to their new values."
21:10pdk,(let [myfn (fn [[arg]] arg)] (myfn))
21:10clojurebotjava.lang.IllegalArgumentException: Wrong number of args (0) passed to: sandbox$eval930$myfn
21:10pdk,(let [myfn (fn [& [arg]] arg)] (myfn))
21:10clojurebotnil
21:13tonyl&((fn [& [x y & more]] [x y more]) 1 2 3 4 5 6)
21:13sexpbot⟹ [1 2 (3 4 5 6)]
21:16brehaut$source destructure
21:16sexpbotdestructure is http://is.gd/ub7pAw
21:17brehautwell, thats a bunch longer than i was expecting
21:18tonylit's magically longer
21:20hiredmanmaniacally
21:21brehautpretty sure a lot of tea was involved
21:23tonylaaah, i need to extend my nested closure tolerance
21:26brehauttonyl: have you played about with it? it helps to know what its doing
21:27pdki am officially concurrent programming wizard
21:27brehautoffically?
21:27pdkapparently trying to optimize an AI tree search algo by making it spawn a new thread for each branch in the tree unchecked is not wise
21:27pdkMUCH TO MY CHAGRIN
21:28brehauttonyl: its rewriting a destructuring bind into a bunch of calls to nth etc
21:29brehaut,(destructure ['a 1])
21:29clojurebot[a 1]
21:29tonylbrehaut: I figure it creates new symbols based on the destructuring norms that are passed
21:29brehaut,(destructure ['[a b] [1 2]])
21:29clojurebot[vec__948 [1 2] a (clojure.core/nth vec__948 0 nil) b (clojure.core/nth vec__948 1 nil)]
21:30tonylyup
21:30hiredmanthat is the tamest sort of destructuring
21:30brehautthe output is surprisingly simple compared to the work that goes into producing it
21:31hiredman,(destructure ['{{[x y z] :b} :a} {:a {:b [1 2 3}}])
21:31clojurebotUnmatched delimiter: }
21:31hiredman,(destructure ['{{[x y z] :b} :a} {:a {:b [1 2 3]}}])
21:31clojurebot[map__951 {:a {:b [1 2 3]}} map__951 (if (clojure.core/seq? map__951) (clojure.core/apply clojure.core/hash-map map__951) map__951) map__952 (clojure.core/get map__951 :a) map__952 (if (clojure.core/...
21:31pdk} truly is the best in the land clojurebot
21:33hiredman[{:keys [bytes} {:keys [x y z] :as args} :foo :as everything}] ;;ran into something like this in production code today
21:33danlarkina travesty
21:34brehautoh my
21:34hiredmandanlarkin: right, well joe and I took some steps
21:34tonyl[bytes doesn't look like a valid symbol
21:34danlarkingood, abominations like that should not stand
21:35hiredmanthe [bytes} should be [bytes]
21:36hiredmanthen he complained about something like (let [a … b …] (.delete a) b)
21:36tonylhaha
21:36tonylsounds like somebody had code amnesia
21:37hiredmanso I suggested (let [a …] ((fn [b] (.delete a) b) …)) so he yelled at me for a bit
21:37danlarkinoh god
21:37hiredmanyeah, just like that
21:38tonylwow, did you show him his own code?
21:38hiredmanoh the destructuring thing was code I had written too
21:42brehautthe frightening thing about those snippets is that they are pretty decent in the context of the wider industry
21:43hiredmanwhat is the difference between (let [a 1] a) and ((fn [a] a) 1) ?
21:43no_mindwhat is the difference between defn and defn- ?
21:44hiredmanlet can bind primitives to names and fn creates a recur point
21:44danlarkinno_mind: defn is ok to use and defn- is wrong
21:44brehautno_mind: defn creates a ns private var
21:44no_minddanlarkin: amny clojure libs are using defn-
21:44brehautno_mind: many projects are using C++; doesnt make it right
21:44danlarkinif they jumped off a bridge would you too?
21:45danlarkinBAM! Mothered
21:45hiredmandanlarkin is something of a luddite, he complains if I use letfn
21:45no_mindwell i want to know what is defn- and why not to use it ?
21:45brehauthiredman: its not his fault, he came from python
21:45hiredmanno_mind: have you read the doc string?
21:45no_mindno
21:45tonyl&(doc defn-)
21:45sexpbot⟹ "Macro ([name & decls]); same as defn, yielding non-public def"
21:45brehautno_mind: you dont want to use because someone will come along later and curse you that the fn they need is private and now tey need to copy and waste
21:46hiredmanit is infact very easy to get access to a private var
21:46brehauthiredman: oh real? that would be handy
22:04technomancyprivate is more about reducing the surface area of your API than actually hiding anything
22:04brehautinteresting
22:04technomancywhy should foo.mylib.<TAB> complete to a bunch of internal junk you don't ever need to call?
22:04brehautsure that makes sense
22:05brehauttime for the stupid question: emacs clojure mode supports that?
22:05technomancyno, you need swank
22:05brehautah
22:06brehautpass on that for a while then
22:07technomancysuit yrself
22:08brehautyup :) while it would be handy i am still pretty bad at emacs
22:12Raynestechnomancy: Have you ever done any gnus stuff?
22:17zippy314Hi, I'm wanting to regex replace on strings and a google search yields re-gsub in clojure-contrib.str-utils. and also re-replace in clojure.contrib.strings What's the difference and which should I use?
22:17hiredmanyou should check the .replaceAll method on String and see if it doesn't do what you want
22:18zippy314I also what lower-casing and capitalization. Should I just use java methods?
22:18hiredmanyes
22:20zippy314,(.replaceAll "fish bonk" #"\w")
22:20clojurebotjava.lang.IllegalArgumentException: No matching method found: replaceAll for class java.lang.String
22:21zippy314?
22:21hiredmanzippy314: when I said check I meant "read the javadoc"
22:21zippy314it's there.
22:21hiredmanread the javadoc
22:21zippy314http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#replaceAll(java.lang.String,%20java.lang.String)
22:21zippy314oh (blush)
22:21zippy314,(.replaceAll "fish bonk" #"\w" _)
22:21clojurebotjava.lang.Exception: Unable to resolve symbol: _ in this context
22:22zippy314,(.replaceAll "fish bonk" #"\w" "_")
22:22clojurebotjava.lang.ClassCastException: java.util.regex.Pattern cannot be cast to java.lang.String
22:22hiredmanyou still haven't read the doc
22:22hiredmaninfact you haven't even read the link you just posted
22:22zippy314yah. sorry.
22:24zippy314ok. but please explain why I should be using this instead of the contrib libs.
22:24brehautzippy314: its right there in the javadoc
22:25hiredmanbecause dependence on contrib, given the dubious quality of lots of contrib is bad
22:25zippy314(.replaceAll "fish bonk" "\\W" "_")
22:25zippy314,(.replaceAll "fish bonk" "\\W" "_")
22:25clojurebot"fish_bonk"
22:26zippy314Hmmm. I'm not so keen about regexs encoded as strings. It's a pain to have to escape the escapes and so on..
22:27brehauthiredman: in this instance, the fns in question have moved from contrib to clojure itself havent they?
22:27jimbostrudelyou could store them in a file and read them in
22:27brehauthttp://clojure.github.com/clojure/clojure.string-api.html
22:28hiredmanbrehaut: *shrug*
22:44zippy314brehaut: from that url it says to use: (:require '[clojure.string :as str]) But when I do that, I get "java.lang.Exception: lib names inside prefix lists must not contain periods" any idea what gives?
22:45brehautis that part of your ns definition?
22:45tonyl(:require doesn't need the apostrophe
22:46brehautzippy314: ie do you have (ns my.ns (:require …))
22:46technomancyRaynes: it's been a while since I had a really tuned gnus
22:46Raynestechnomancy: It was fairly easy getting it to fetch my mail. The problem is that there are no mail groups. INBOX doesn't exist.
22:47RaynesIt's bizarre.
22:47Raynes<3 thunderbird
22:47scottjyou mean you can't subscribe to inbox?
22:49Raynesscottj: Yes. It claims that it doesn't exist.
22:50scottjbut you can see the maildir/whatever file(s)?
22:51RaynesThe only thing it's actually showing me is the default help group.
22:51zippy314brehaut: yes I was. The trick was what tonyl said.
22:51brehautzippy314: ok cool.
22:51zippy314tx
22:52scottjRaynes: have you consulted the manual?
22:52RaynesYes, and at least 4 different step-by-step tutorials. It doesn't look like anybody else has ever encountered this problem.
22:52RaynesIt isn't a huge deal. I'll ask in #emacs eventually.
22:53scottjwhat select method are you using?
22:53scottjanyway, email clients that only show one message at a time are lame.
22:54Raynesnnml