#clojure logs

2009-03-03

00:27arohneris there any way to say "this" when defining a function with multiple arities?
00:28arohnerI would really like to say (defn foo ([a b] (bar a b)) ([a] (this a nil))
00:31cp2you can just say foo
00:31hiredman^-
00:32cp2,(defn bar [a b] (prn a)) (defn foo ([a b] (bar a b)) ([a] (foo a nil))) (foo "a" "b")
00:32clojurebotDENIED
00:32cp2eh
00:32cp2you get the idea
00:32cp2lol
00:32durka42or use a Y combinator ;)
00:34cmvkkno defn?
00:34cmvkk,(defn foo [] 1)
00:34clojurebotDENIED
00:34hiredmanno def, defn uses def, so no defn
00:35cmvkkah.
00:37cp2what does defn- use
00:39hiredmanrun macroexpand on it
00:39cp2bah
00:40cp2dont have anything clojure related on this fresh install
00:40hiredman~def defn-
00:40cp2should fix that :)
00:40cp2what
00:40cp2it went to re-find
00:40cp2oh
00:40hiredmangah
00:40cp2nevermind
00:40cp2well, yeah
00:40cp2revisions are off
00:40cp2but it was close
00:41cp2i see
00:41cp2still uses defn
00:41hiredmanthey shouldn't be
00:41hiredmanthat is really annoying
00:42hiredmanah
00:42hiredmanthe url is broken
00:43hiredman~def defn-
00:48arohner,(macroexpand '(defn- foo [x] (* x x)))
00:48clojurebotDENIED
00:48arohneranyways, the point is that I don't want to write foo again
00:48arohnerI want it to refer to the same function with a different arity
00:49hiredmanuh
00:49hiredmanI am pretty sure we solved that
00:50hiredman(defn foo ([a b] (bar a b)) ([a] (foo a nil))
00:50durka42you can do something like this: (def f (fn g ([a b] nil) ([a] (g nil nil))))
00:51durka42if you really don't want to mention the fn's real name
00:51hiredmanthis is an idiom used all over core.clj
00:51hiredman~def max
00:51hiredmanfor example
00:52cmvkkwhy was my first thought "they should just use apply there instead of reduce since max can take any number of arguments"
00:52cmvkkno cmvkk, that is not how it works
00:53cmvkkthat is not how it works at all
00:53hiredmanhaha
00:53hiredmanthat would truely be magic
00:53arohnerhiredman: how does your example solve that?
00:54durka42arohner: what are you trying to do? why can't you use the function's name?
00:54arohnerdurka42: I shouldn't have to repeat myself
00:55arohnerdurka42: your example works, but I think there should be an easier way
00:55hiredmanarohner: you want (foo a) to call (foo a nil) yes? that is what your example indicated
00:55hiredmanthat is what my example does
00:56arohnerthat's what my original code did. the point was that I didn't want to repeat the name foo
00:56arohnerit's just a DRY issue
00:57hiredmanthat is just silly
00:57arohnerhow?
00:57durka42a macro could solve it
00:57cmvkkit would be nice if recur worked that way i guess but it makes sense that it doesn't
00:57hiredmanbecause at some level you must repeate your self, or split the function into two
00:58arohnerhiredman: this makes sense to me: (defn foo ([a b] (bar a b)) ([a] (this a nil)))
00:59arohneror to make it simpler: (defn foo ([a b] (bar a b)) ([a] (recur a nil)))
00:59cmvkki do that now in some code i'm writing, with a macro that wraps over an fn
00:59cmvkkit just calls the fn 'prev' every time
00:59hiredman(def foo (fn this ([a b] (bar a b)) ([a] (this a nil)))
00:59arohnercmvkk: I assume recur doesn't work because the two different arities are two different functionss as far as java is concerned
00:59cmvkkyep, that seems to be the case.
01:01cmvkkdefinitely a case of (defmacro defnt [name & body] `(def ~name (fn ~'this ~@body))) though
01:05durka42(let [recurr foo] (defn foo ([a b] nil) ([a] (recurr nil nil))))
01:06cmvkki don't think that would work.
01:06durka42nevermind, that doesn't work
01:06durka42it works if foo is already defined...
01:06durka42doing it at the repl deceived me
01:08cmvkkhmm, i wonder if tricky rebinding would allow me to do mutual recursion without having to use atoms.
01:08hiredman...
01:08hiredmanwhy not use trampoline?
01:09cmvkkhmm...trampoline is only for tail recursion though right?
01:09hiredmantrue
01:09cmvkkthis would be mutual the-wrong-kind-of-recursion.
01:09cmvkkthat i want to do, i mean.
01:10hiredmanew
01:10durka42whee
01:10durka42(letfn [(bar ([a b] nil) ([a] (recurr nil nil))) (recurr [& args] (apply bar args))] (def bar bar))
01:10cmvkkheh
01:10cp2ok, now i know where people get the stereotypes for lisp having excessive parens
01:11cp2one liners like that :)
01:11cp2even then thats not too bad
01:11durka42that would be so much better if it were indented
01:11cp2yeah
01:11cmvkkchat rooms are decidedly bad environments for complex data structures.
01:12lisppaste8durka42 pasted "more palatable?" at http://paste.lisp.org/display/76403
01:13hiredman,(pl inc $ inc $ inc $ 0)
01:13clojurebot3
01:14cmvkkare you including libraries besides the normal one?
01:14cmvkk,(doc pl)
01:14clojurebot"([& forms]); replaces a $ b with (a b) walking right to left replaces a � b with (comp a b) left to right ?a with (uncurry a) left to right ?a with (flip a) left to right"
01:14hiredmanyes
01:15cmvkkthose symbols are all garbled in my chat, by the way
01:15hiredmanunicode
01:15cmvkki assume that's because i'm using a stupid chat client
01:15cmvkkhmm, does clojure do okay with unicode?
01:16hiredmanjava is all unicoded up
01:16hiredmanso so is clojure
01:16cmvkki'm gonna start writing all my code in hangul...that way i don't have to worry about name collisions
01:16hiredmanare you korean?
01:17durka42,(let [? "snowman"] (.replace ? "w" "?"))
01:17clojurebot"sno?man"
01:17cmvkkno, i just took the language in college.
01:17hiredmanmy parents are english teachers over there
01:18cmvkkoh oh
01:18cmvkki want to do that, actually.
01:18hiredman:(
01:18cmvkkheh, it's bad?
01:18hiredmanfor me
01:18cmvkkwhat for?
01:18hiredmanmany people do it so it cannot be that bad
01:19cmvkkwell that's hopefully the case
01:20hiredmanmy personality and the korean cultural obsession with foriegners don't jive
01:21hiredmangotta watch out cause in the last four months the won has really tanked against the dollar
01:22cmvkkyeah that's true, well every currency is tanking
01:22cmvkki'm not looking to make it rich, being employed at all would be nice
01:22cmvkkfresh out of college with a degree in linguistics and no work experience, i'm not exactly going to find a programming job here in america or something
01:22cmvkkso i might as well finish learning a foreign language and work at the same time.
01:23hiredmanI am sure there are plenty of korean software companies looking for people who speak english
01:24cmvkkhmm..m
01:27hiredmanclojurebot: English?
01:27clojurebotEnglish is the official language of the universe
01:27hiredman~translate to ko English is the official language of the universe
01:27clojurebot??? ??? ?? ?????
01:31durka42~translate from ko ??? ??? ?? ?????
01:31clojurebotEnglish is the official language of the universe is
01:31slashus2is
01:44replacahiredman: what does pl stand for?
01:45hiredmanreplaca: pointless
01:45replacahiredman: ahh, ok. not pf?
01:46hiredman:|
01:46replaca:)
01:47replacait's in contrib?
01:47hiredmanhah
01:47hiredmanno
01:47replacayour own thing?
01:47hiredmanyeah
01:47hiredman~pl
01:47clojurebotexamples is http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples
01:47hiredmanhmmm
01:48hiredmanthat was not what I was expecting
01:48hiredman~transform
01:48clojurebottransform is http://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj
01:48hiredmanthere
01:48replacacool. looks neat.
01:49replacawow, now that's clojure! I can learn from that.
01:54hiredmanugh
01:54hiredmandon't look at that
01:55durka42all right
01:55durka42i'll go to bed instead
01:56cmvkkheh heh
01:56cmvkkdefinitions for a bunch of combinators, and then out of nowhere, (def ? :heart)
01:57hiredmanheh
01:58durka42,?
01:58clojurebotjava.lang.Exception: Unable to resolve symbol: ? in this context
01:58hiredmanI was using jline for a repl at the time and it had problems with unicode
01:58replacaThe sad thing about ? is that it is unused.
01:59cp2i ? you
01:59replaca:-(
01:59cmvkkand we can't define it here because def is disabled.
01:59hiredmanI have "&heart;" setup in irssi to change to ?
02:30brennancis there something like comp that goes from left to right instead of right to left?
02:32hiredman,(flip comp)
02:32clojurebot#<sandbox$flip__7102$fn__7104 sandbox$flip__7102$fn__7104@1712a80>
02:33brennancthanks, how do I find where flip is?
02:33hiredmanheh
02:33hiredmanflip is not part of clojure
02:34hiredmansorry, it is something I wrote
02:34hiredman~transform
02:34clojurebottransform is http://github.com/hiredman/odds-and-ends/blob/8a84e6ddbad9d71f714ba16c3e1239633228a7eb/functional.clj
02:34hiredmansource is there
02:34hiredman"->" is sort of like that
02:34hiredman,(-> 0 inc inc inc)
02:34clojurebot3
02:36brennancmy thinking is when you have a long string of function compositions it's much easier to work with it in a post-fix notation like forth or factor
02:36hiredman,((flip comp) inc println) 1)
02:36clojurebot#<core$comp__3945$fn__3947 clojure.core$comp__3945$fn__3947@1c390b8>
02:36hiredmanhmmm
02:36hiredman,(((flip comp) inc println) 1)
02:36clojurebot2
02:37hiredmanbrennanc: definately take a look at "->"
02:37brennancwill do, thanks
02:39hiredmanI think comp actual works ok for those situations too
02:39brennancit saves you from the parentheses but it's still more natural to work left to right
02:40hiredmanhttp://github.com/hiredman/clojurebot/blob/6452d7353b60a33bcb0adc04d9fab25cdd0b98c4/hiredman/clojurebot/tweet.clj#L12
02:40hiredmanstuff bubbles up through the function
02:42brennanc(-> "abc" .toUpperCase ,, (.replace ,, "B" "-"))
02:42brennancwhat are the 2 commas?
02:42hiredmandunno
02:42cmvkkjust placeholders.
02:42hiredmancommas are whitespace
02:43hiredmanthey mean nothing to the compiler
02:43brennancweird, wonder why they are there
02:43cmvkkthey're placeholders
02:43hiredmanto help understand what "->" is doing I guess
02:43cmvkkto mark where the object would be in that function call
02:43brennancahh
02:44hiredman:(
02:44cmvkki don't think it's very useful to do that though
02:44cmvkkto each their own i guess
02:45hiredmanI was using "," to seperate stuff out when I first started using (cond ...)
02:45brennancthe "functional programming" in the "programming clojure" book is tough. Not sure if that is just because I'm not used to lisp or if it will get easier with time.
02:46cmvkki try not to ever use commas. i figure if i get used to them, i'll just end up being more confused when i see someone else's code that doesn't use them.
02:48hiredman,(pl (?map (replicate 3 range $ 3) call � (?map inc)))
02:48clojurebot((1 2 3) (1 2 3) (1 2 3))
02:49brennancwhat's with the funky symbols?
02:49brennancanyone else seeing that?
02:49hiredmanthe unicode?
02:49cmvkkyes they mean something apparently
02:49hiredmanthe arrows, the cicle with the line and the interpunc
02:50brennancthey part of the token or are they tokens in and of themselves?
02:50hiredmanthe only mean something inside the pl macro
02:51cmvkkthere's uh...not any point to that stuff other than obfuscation is there?
02:51hiredman?map is a symbol
02:51brennancI'm not even going to bother asking until I'm much further along into my clojrue education. :)
02:51cmvkkor maybe that example just seems pointless to me.
02:51hiredmanpl stands for pointless
02:51hiredman,(macroexpand-1 '(pl (?map a b)))
02:52clojurebot(do ((flip map) a b))
02:52brennancreminds me of "APL, in which you can write a program to simulate shuffling a deck of cards and then dealing them out to several players in four characters, none of which appear on a standard keyboard."
02:52hiredman? is an apl symbol
02:52hiredmanno idea what it does in apl
02:53hiredman,(macroexpand-1 '(pl (?map b)))
02:53clojurebot(do ((uncurry map) b))
02:57brennanc(-> "abc" .toUpperCase reverse str)
02:57brennanchow do I get the escape characters out of the string?
02:57brennanc... and the parentheses
02:57hiredman,(-> "abc" .toUpperCase reverse (#(apply str %)))
02:57clojurebot"CBA"
02:58hiredman:(
02:58hiredman, ,(-> "abc" .toUpperCase reverse)
02:58clojurebot(\C \B \A)
02:58hiredman(str '(\C \B \A))
02:58hiredman,(str '(\C \B \A))
02:58clojurebot"(\\C \\B \\A)"
03:22cmvkk,*ns*
03:22clojurebot#<Namespace sandbox>
04:37hiredmanhttp://weblogs.asp.net/podwysocki/archive/2009/02/23/adding-parallel-extensions-to-f.aspx
04:53djpowellare any of the people looking at cells online?
04:55djpowellhttp://blog.sigfpe.com has some interesting stuff about using comonads implement spreadsheet like stuff functionally
04:55djpowell - not recently, in the archives
06:09Ben`how can I cast a lazy list to java.util.List?
06:10Ben`I'm trying to use Collections/binarySearch but I get "java.lang.ClassCastException: clojure.lang.LazyCons cannot be cast to java.util.List"
06:10Chousukethat means it's not a list, but a lazy seq
06:11Chousukebut does a binary search make sense for a list? :/ wouldn't it be really slow.
06:11Chousukeanyway, you can force the seq into a real collection: (into [] yourseq)
06:12Ben`oh, thanks
06:34AWizzArdChousuke: btw, why (into [] foo) and not (vec foo)?
06:34AWizzArdis this lazy vs eager?
06:35ChousukeAWizzArd: nah, both are strict.
06:35ChousukeI think they do the same thing
06:35Chousuke(into [] foo) just reads better IMO and I thought of it first :)
07:03timothypratleyI want to make a state machine whereby I have a number of functions which return a new state and cause me to transition to another function. These functions would only return on transition events - how would I go about blocking for an event in java/clojure?
07:04timothypratleyanalogous to showing a swing dialog and waiting for the result.
07:08leafwtimothypratley: make a future and grab its output -- and within the future, show your dialog. This will halt execution at that grabbing of the future output.
07:11leafwyou could do this trivially using pmap and a list that contains a single element, the function to exec and wait on.
07:16leafwtimothypratley: even easier, see (doc future)
07:18timothypratleyHmmm not sure how to apply that... I was thinking that the state machine would be essentially a group of functions which spin until a change of state event whence they would return the new state to transition to. But I was hoping to do a blocking wait instead of a loop spin. Maybe I'm thinking about it all wrong.
07:24timothypratleyfutures don't really block for an event as such - they just create a thread that will eventually have a value
07:40cgrandtimothypratley: a BlockingQueue?
07:42timothypratleyah of course
07:42timothypratleythanks!
08:30cgrandChouser: ok for merging javadoc into repl-utils
08:32Chousercgrand: ok, great.
08:32Chouserdo you read all the IRC logs?
08:33cgrandI mirror and grep them :-)
08:34clojurebotsvn rev 1321; fix cast in read-line [issue 82], patch from Chouser/Trolard
08:45cgrandChouser: I move javadoc.clj to repl_utils/javadoc.clj and load it from repl-utils.clj. Ok?
09:17Chousercgrand: oh, sure, that's a good idea. I hadn't thought of keeping the files separate.
09:21cgrandChouser: dcommited!
09:21Chouserheh
09:46Chousercgrand: I'm in no particular rush, but just so you know: I'm not seeing your change.
09:50Chouseryou know about 'git stash'. not sure if that fixes your situation or not
09:50ChouserI'm no git wiz
09:51Lau_of_DKWhats the situation ?
09:52cgrandLau_of_DK: it's ok, everything is fine with git
09:54Lau_of_DKGood, I'll calm back down :)
09:54cgrandChouser: yup git stash does the trick (the error message is helpful enough and says to use git stash btw), it's a recurrent problem due to a pb with line separators
09:56Chouserhm, interesting. are you on Windows?
09:57cgrandyes
09:57Chouserbut you don't use vim?
09:57leafwcgrand: I thought git win devs had solved the line char problem in latest git release.
09:58cgrandChouser: it depends, a mix of eclipse and gvim
09:58Chouserok.
09:59cgrandmsysgit disabled git svn, so I resort to cygwin's git for git svn and I think that's cygwin automagic EOL conversion that messes everything
09:59Chousergvim usually does pretty well at using the right line endings on a per-file basis, but I have noticed the sources in clojure and contrib both seem to have a mix.
10:00Hookehello
10:00Lau_of_DKHey Hooke :)
10:01Hookehi Lau_of_DK :)
10:02Hookehow r u
10:04HookeI'm wondering what may be the best IDE for clojure. I've seen a little of enclojure, clojure-mode for emacs and also an eclipse plugin
10:04Lau_of_DKEmacs
10:04Lau_of_DKWithout a doubt
10:04Lau_of_DKIm good thanks :)
10:04clojurebotsvn rev 1322; bytecode-based constants, [issue 78], patch from rwvtveer
10:04Lau_of_DKGet Emacs going with Clojure-mode and SLIME, you're set for life
10:10Hookehmm, thanks for the tip
10:10HookeI've been reading about clojure IDEs here: http://www.ociweb.com/mark/clojure/article.html
10:11Hookewhat's the difference between using clojure-mode and swank-clojure? It's a bit confusing, no? :)
10:15Lau_of_DKHooke: its very confusing, look up Bill Clements blog, he's got a very excellent blogpost explaining Emacs, Swank and SLIME in relation to one another
10:16Hookeoh, I see. thank :)
10:19Lau_of_DKnp
10:19Hookeits here, right? http://bc.tech.coop/blog/081209.html
10:19Lau_of_DKThats the one
10:21Hookelots of reading to do :)
10:21Lau_of_DKGood stuff though
10:21Hookeyeah, looks good
10:22Lau_of_DKOn the same blog you'll find a really easy guide on how to install/setup emacs, but if you want to try something else, try technomancy's clojure-mode on github, it has an installer which is supposed to do all the work for you, Ive only heard good stuff about it
10:23Hookeah, I installed the clojure-mode and saw the clojure-installer command, but didnt dare to use it :D
10:23Lau_of_DKIt looks safe, it does a few git-clones, and then gives you an example of a configuration, I cant see how I should break anything
10:24Lau_of_DKand techomancy is solid in elisp
10:25RaynesOh cool. By saying "Someone should fix issue 82" yesterday, I actually /got/ it fixed.
10:26Hookeokay :)
10:26HookeRaynes: you should claim some credit, then
10:26RaynesTotally Hooke :p
10:31Hookeah, the clojure-mode I'd tried is not technomancy's. technomancy's is a fork of it
10:38duck1123should we be switching to technomancy's now?
10:38duck1123I'm still using the other one
10:39Lau_of_DKIm going with Technomancys, have been for a while
10:39Lau_of_DK(doc average)
10:39clojurebotGabh mo leithsc�al?
10:39Lau_of_DKDo we have some average calc stuff yet, or is it still (/ (count seq) (apply + seq)) ?
10:40ayrnieu(defn average [seq] (/ (count seq) (apply + seq)))
10:40ayrnieualthough you should use 'coll' instead of 'seq'.
10:40Lau_of_DKYou didnt answer my question, you just pasted my own code... O_o
10:41ayrnieuI pasted your own code.
10:41tashafalol
10:41ayrnieuIt turns out that you can define procedures in this language.
10:41Lau_of_DKYarly ?!
10:42RaynesNevar.
10:42tashafa(doc index)
10:42clojurebotTitim gan �ir� ort.
10:43tashafa(doc index-of)
10:43clojurebotexcusez-moi
10:43tashafai think 'index-of' should also be part of core
10:43Lau_of_DKI gotta jet
10:43ayrnieutashafa - what would it do?
10:44Raynes(doc nth)
10:44clojurebotReturns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-found is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences.; arglists ([coll index] [coll index not-found])
10:44RaynesWhat's wrong with that?
10:44Chouserindexes into collections are used much less frequently in idiomatic Clojure than in, say, javascript.
10:44tashafa(index-of 5 [1 2 4 5 0 3]) -> 3
10:44Raynes,(nth [1 2 3 4 5] 5)
10:44clojurebotjava.lang.ArrayIndexOutOfBoundsException: 5
10:44tashafasorry.. (index-of [1 2 4 5 0 3] 5) -> 3
10:45Raynes,(nth [1 2 3 4 5] 4)
10:45clojurebot5
10:45Raynes^
10:45Chousertashafa: that would require a linear search of the vector -- not someting you want to do if you can avoid it.
10:45tashafatrue...i figured as much
10:45Chouserwhat would use do with the index once you got it?
10:46tashafai think i had this discussion here a while ago
10:46Chouser:-)
10:46Raynesfind-doc is the most useful thing evar.
10:47tashafaChouser: hmmm... thinking
10:49tashafaChouser: Every test case i can think of (for the use of index-of), I can now figure out a more elegant way to do it.
10:50Chousergreat!
10:50Chouserthe main functions that use an index on a vector are nth and assoc
10:51tashafahmm.. what about the starting point of a word in a string
10:51Chouserif you found the index by a linear search for the value, using nth on it is pointless -- clearly you already know the object you're looking for.
10:51Chousertashafa: String has a method for that, I believe.
10:52tashafaah got me
10:52Chouser,(.indexOf "Hello" "l")
10:52clojurebot2
10:52tashafai always forget clojure is bolted on Java
10:52Chouserso that leaves assoc.
10:52ChouserI suppose you might want to search for a item in a vector and then replace it with a new value using assoc.
10:53ChouserBut unless the order is important, that could be done much more efficiently on a set instead -- get, disj, conj
10:53tashafaChouser: Re: if you found the index by a linear search for the value, using nth on it is pointless -- clearly you already know the object you're looking for.
10:54tashafabut what if i want to noo at what nth the value occurs in a seq
10:54tashafato know*
10:55Chousermy point is that knowing that hardly ever helps you
10:55tashafatrue
10:55ChouserI'm trying to think of what you would use that index value *for*, once you got it.
10:55Chouserusing it to pass to 'nth' is pretty silly.
10:56tashafayeah... but what if that was your whole application... to find the index of where a pariticular value appears in a seq
10:56ChouserI can come up with contrived examples, like the one above -- the order of the items is important, so you want a vector not a set. You want to replace a particular value with another value, or replace a nearby value.
10:56Chouserbut I don't know if a builtin function is needed to support such an odd case.
10:57tashafayeah..
10:57Chouserin fact, if I was going to do a lot of that, I'd probably keep some index map in sync with the vector so that the lookups could be constant time rather than linear.
10:57tashafaforget i brought it up, i lost the discussion the first time around :)
10:57ayrnieutashafa, not everything you want to make use of will be in core. If this particular function were placed in core, it would be in core.clj and not different from what you'd write yourself.
10:58tashafaayrnieu: no doubt, i think core is huge as it is anyways
10:58Chouserhm, might be fun to make an "indexed vector" object, that provides constant time lookup.
10:59ayrnieuas opposed to vectors, which provide constant time lookup?
11:00Chouserconstant time lookup of the index when given the value
11:01ayrnieuwould these map values to lists of indexes?
11:02Chouseryes
11:02rhickey,(.index (nthnext (vec (range 100)) 2))
11:02clojurebot2
11:02RaynesOrly.
11:03rhickeyvector/array/string seqs are indexed
11:04Chouseroh
11:06tashafalol
11:06Chouser,(.indexOf '[a b c d] 'd)
11:06clojurebot3
11:06tashafa(doc nthnext)
11:06clojurebotReturns the nth next of coll, (seq coll) when n is 0.; arglists ([coll n])
11:10tashafajava saves the day
11:10cgrandapart from java interop (and destructuring) do people use indexing that much?
11:13tashafacgrand: there are probably more elegant ways to do want you need to do if you are using index
11:14tashafa..or think you need an index of a val in a vec
11:20tashafabut ofcourse there might be some edge cases
11:20cgrandI can just think of algorithms that require some kind of hashing (eg hashmaps, bloom filters) or those that require the ability to skip elements to be sublinears (eg KMP)
11:32Chousercgrand: your blog posts are like your lisp code: succinct but full of meaning.
11:35cgrandChouser: thanks
11:52scottjSo are all the bugs with fully-lazy worked out in contrib and swank/slime? latest compojure uses fully-lazy and I want to upgrade to that, but I don't want my dev environment/libs to break.
11:52ChouserI think contrib is good to go.
11:53ChouserI hear swank/slime is working too, though I'm not sure if you need an unusual branch or something.
12:13scottjok, thanks
12:43Lau_of_DK({:id 5, :name "Frank"} {:id 6 :name "Brooks"}) - Lets say I want to go through that seq, and when I hit someone named Brooks, I want to attach another key called age, which has value 25 for instance. Whats the most effecient way to do this?
12:45Chousermost efficient would be to keep a map indexed by :name as well.
12:46Lau_of_DKhow?
12:48Chouserif your seq is called 'db', then: (set/index (set db) [:name])
12:48Lau_of_DK(doc set/index)
12:48clojurebotExcuse me?
12:48Chouserdoc clojure.set/index
12:49Chouser,(doc clojure.set/index)
12:49clojurebot"([xrel ks]); Returns a map of the distinct values of ks in the xrel mapped to a set of the maps in xrel with the corresponding values of ks."
12:49Lau_of_DKIs that new?
12:49Chouserno
12:49Chouseror if you just want to work in linear time:
12:49Chouser(for [{nm :name :as rec} db] (if (= nm "Brooks") (assoc rec :age 25) rec))
12:50Lau_of_DKin terms of time, what is the above?
12:50Lau_of_DKthe... set/index
12:50Chouseroh, set/index is linear, but then any lookups on it are constant-time
12:50gnuvince(doc if)
12:50clojurebotGabh mo leithsc�al?
12:51gnuvince,(doc if)
12:51clojurebot"([tst & etc]); "
12:51gnuvinceThat doesn't look right, does it?
12:51gnuvince,(if true)
12:51clojurebotjava.lang.Exception: Too few arguments to if
12:51Chouser(doc if) at a repl says Please see http://clojure.org/special_forms#if
12:51clojurebotIt's greek to me.
12:52gnuvinceChouser: hmm, not in Slime
12:52gnuvinceOh
12:52gnuvincewait
12:52gnuvinceyes it does
12:52gnuvincewth...
12:52Chouserbother. I was hoping to make fun of it again.
12:53gnuvinceAh
12:53gnuvinceIt's C-c C-d d
12:54durka42that is weird, why does (doc if) say it's a special form when it's really a macro
12:56Chouserdurka42: that it's a macro is an implementation detail
12:57Chouserit's only been a macro since the lazy assert thing, and I imagine it will go back to being a special form later.
12:57durka42ah i see
12:59ChouserSimilarly 'let' is discussed as a special form, but is currently implemented as a macro in order to do destructuring.
12:59durka42and loop
12:59Chouserindeed
12:59jbondesonthe * forms are the true special forms.
13:01Chouseryeah, that's a fun one.
13:01jbondesonmodifying the if macro was good times...
13:02jbondesonyou have almost nothing in terms of clojure functionality
13:02Chouserright. no gensym, for example.
13:02durka42also loop calls destructure, which loops...
13:03jbondesonif you modify anything that high up you do lots of calls to the java code
13:03durka42i would imagine
13:03Chouseralso fun is the assert-if-lazy-seq private macro, which does a bunch of work then emits just nil or true as a constant.
13:04jbondeson= uses if so you have to use clojure.lang.Util/equiv ... good things like that
13:04Chouserthis allows the 'if' macro, when compiled, to store only that resulting constant and not have to check the system property ever again and yet still get consistant results.
13:05durka42oh, it's a macro
13:05durka42i was just going to say, doing a System/getProperty on every branch would slow things down pretty quick
13:05jbondesoni wonder how bad it would be to move gensym up higher.. heh
13:05Chouserwell, it's still doing an 'instance?' check on every branch, which is why it's optional.
13:05Chousukedurka42: hopefully there is a base case in destructure where it does not loop :P
13:05jbondesoninitial glaces say: HARD
13:06jbondesonguess the only macros up higher are pretty simple...
13:07Chouserwell, like I said, I assume 'if' will be going back to normal eventually.
13:34Lau_of_DKIs there a function for (in-range? 5 0-10) true function ? Or do I make my own
13:38jbondesonhuh, contains? doesn't work on lists like you'd expect.
13:38jbondeson,(contains? (range 0 10) 5)
13:38clojurebotfalse
13:38kotarak,(some #{5} (range 10)) ; Lau_of_DK
13:38clojurebot5
13:39kotarak,(some #{100} (range 10))
13:39clojurebotnil
13:40jbondeson,(contains? (into #{} (range 10) 5))
13:40clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$into
13:40jbondesonwhops
13:40jbondeson,(contains? (into #{} (range 10)) 5)
13:40clojurebottrue
13:41Lau_of_DKThanks pappa and jbondeson
13:41jbondeson(set ...) would be more concise than (into #{}...)
13:41jbondesonweird that contains doesn't work on generic seq's
13:43kotarak,(#(< 1 % 10) 5)
13:43clojurebottrue
13:43kotarak,(#(< 1 % 10) 100)
13:43clojurebotfalse
13:43jbondesonoohh, from the docs contains? will *NOT* perform a linear search
13:43jbondesoniiinteresting
13:43kotarak@Lau_of_DK sometimes ranges can also be easy. (see above)
13:44Lau_of_DKhmmm :)
13:45Lau_of_DKthat was fancy
13:45pjstadigi think i'm pretty close to getting Clojure to share everything with Terracotta
13:45pjstadigbut i've hit a snag with *in*, *out*, and *err*
13:45WizardofWestmarcpjstadig: having to jump through many hoops?
13:46pjstadigit's been "interesting" mostly because of some dumb mistakes on my part
13:46pjstadig*in*, *out*, and *err* need to be per VM
13:46WizardofWestmarcthose are just input and output streams yes?
13:47WizardofWestmarcif so that technically isn't a big deal as you may WANT the defaults to be different per vm/machine
13:47pjstadigyeah they need to be per VM values
13:48pjstadigbut since they are Vars interned into a namespace...
13:48pjstadigand the namespace table is shared...
13:48pjstadigTerracotta is trying to share the root values of those Vars
13:49pjstadigi've thought of a couple of solutions
13:50pjstadigI think making the root field for *in*, *out*, and *err* transient would make terracotta do what we want
13:50pjstadigbut i don't want to make the root of all Vars transient (which is the only option I have in the TC config)
13:51pjstadigSo I'm thinking I want to introduce a new class TransientVar which has a transient root
13:51pjstadigFirst problem is that Var is final, but I can get around that using TC's class replacement
13:52pjstadigsecond problem is that i'd have to make a bunch of changes to the compiler to support TransientVar, which seems like a path filled with pain
13:53WizardofWestmarcI'd say talk to Rich and see if he has any ideas
13:53WizardofWestmarcsince he seems rather interested in getting a strong interconnection between Terracotta and clojure
13:54durka42clojurebot: bat signal
13:54clojurebot/summon rhickey
13:54WizardofWestmarchaha
13:55WizardofWestmarcoh certainly, I know I will at some point
13:55WizardofWestmarcjust not for a while ;)
13:55durka42terracotta does sound really cool
13:56pjstadigi'm *that* close (makes really small distance with fingers)
13:56durka42how can you test things without *in* *out* or *err*?
13:56rhickeypjstadig: if you defn in one VM does TC move the def to others?
13:57rhickeyi.e. the fn objects?
13:57pjstadigI can see compiled functions in the object cache if that's what you mean
13:57rhickeyand they work?
13:58pjstadigwell i think so
13:58rhickeyamazing
13:58pjstadigi've stepped through with JSwat and I see it pulling out the objects
13:58pjstadigi just can't get the REPL because of *in*, *out*, and *err*
14:00pjstadigone of the tests I want to do is set a root binding and see it propagated to other VMs
14:00rhickeyright, that's what I'm asking about, specifically a fn
14:00Rayneshttp://stackoverflow.com/questions/563356/which-lisp-should-i-learn read the comments on Greg Hewgill's post.
14:01rhickeyfor the *in* etc for now oyu can hack Clojure source to make roots nil, then rely on repl binding
14:01pjstadigok
14:01pjstadiglet me try
14:12pjstadigd'oh
14:12pjstadigNPE in main
14:16durka42if the repl is going to bind them anyway, what does it matter if the root bindings are shared?
14:16pjstadigyeah i had thought about leaving the root binding nil, but in browsing through the code i thought that wouldn't work
14:17pjstadigso of course I went straight for the more difficult solution
14:50forkingYourIOare hashmaps BSTs? or hashtables?
14:52jbondesonforkingYourIO: it's a trie
14:56pjstadiguh
14:56pjstadigREPL
14:56pjstadigwhat should I type?
14:58rhickey(defn foo [] 42)
15:01pjstadigjava.lang.IllegalArgumentException: No matching method found: unread for class java.io.BufferedInputStream
15:01pjstadig*in* needs to be a PushbackReader i guess
15:01pjstadighehe
15:02pjstadignow I got an error that user$foo_3158 is uninstrumented so i guess it compiled the function
15:02rhickeyThat's what I was wondering about - would TC instrument dynamic classes
15:04pjstadigupdating my instrumented-classes config
15:06pjstadiguser=> (defn foo [] 42)
15:06pjstadig#'user/foo
15:06pjstadiguser=> (foo)
15:06pjstadig42
15:06pjstadiguser=>
15:09cemerickit's like watching the moon landing or something
15:09kotarakcemerick: I had several of these moments with Clojure already. :)
15:09pjstadigthe first thing i tried to type was "What hath God wrought?"
15:10rhickeypjstadig: can you tell if foo is available on another JVM?
15:10pjstadighehe
15:10pjstadigthere's a slight problem...
15:10pjstadigwhen I try to reconnect from to TC I get an error
15:10cemerickI've been very intrigued by terracotta since I learned that it's persistent last week.
15:25fandarhickey: there is a problem with latest Clojure SVN version
15:26fandarhickey: try running in clojure-contrib: ant test_clojure
15:26fandait generates failures and errors
15:26fandathere is some confusion between "nil" and "()" by the reader/compiler it seems
15:26fandaalso:
15:27fandauser=> (pop '(1 2 3))
15:27fandajava.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack (NO_SOURCE_FILE:0)
15:27fandauser=> (peek '(1 2 3))
15:27fandajava.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack (NO_SOURCE_FILE:0)
15:27fanda-------
15:27fandamany tests pass when ran in REPL, but fail when loaded it seems
15:28Lau_of_DK,(format "25 percent is written as %d%" 25)
15:28clojurebotjava.util.UnknownFormatConversionException: Conversion = '%'
15:28Lau_of_DKAm I misunderstanding the javadoc or is format broken % ?
15:29kotarakLau_of_DK: just guessing: %% ?
15:29jbondesonnuke the second %
15:29Lau_of_DKargh :)
15:29Lau_of_DKpappa, youre right
15:29jbondesonthat too
15:29jbondesonheh
15:29jbondesongood ole escaping
15:35forkingYourIOjbondeson: trie? treap?
15:36jbondesonforkingYourIO: http://lampwww.epfl.ch/papers/idealhashtrees.pdf
15:37jbondesonthat's the paper detailing the underlying data type of the PersistentHashMap
15:44pjstadigso, connecting a second JVM i get a ClassNotFoundException
15:44pjstadigcould not find class clojure.core$ns__1868
15:47Lau_of_DKAny docs out there on how to work with GET values in Compojure in a semi intelligent way? :)
15:58Lau_of_DKpin?
15:58Lau_of_DKg
15:59WizardofWestmarcyou're coming through
15:59WizardofWestmarcjust no one's talking
15:59Lau_of_DKThanks Marc
16:02rsynnottdid they shorten the nicknames?
16:03WizardofWestmarcthe max on freenode is one less then my normal handle :P
16:03cmvkkdo you ever try write a program to solve a problem, and as you work out the implementation the program becomes so crazy that you have to step back and think
16:03WizardofWestmarccmvkk: all the time
16:03cmvkk"this is so complicated, i MUST be approaching this solution all wrong"
16:03Lau_of_DKYea, happend just a few minutes ago :)
16:03cmvkkbut then you can't think of an easier way?
16:03WizardofWestmarcand most of the time I'm right and I end up completely redoing the design
16:04WizardofWestmarcsometimes
16:04WizardofWestmarcI usually give it a day or three first to percolate
16:04WizardofWestmarcso I can have one of those shower Eureka! moments
16:04jbondesonat that point i hit google and find some dissertaion written in 1954 or something, but nothing else helpful ;)
16:04cmvkkheh
16:05kotarakcmvkk: I think, this is the usual process of software development.
16:05jbondesonjust frame your question as a clojure question and Chouser will invariable solve it for you...
16:05jbondeson-e+y
16:05WizardofWestmarcjbondeson: hahahaha
16:05WizardofWestmarcso true!
16:10pjstadigrhickey: what can be done about classes?
16:11pjstadigmy first thought was to make the map field of DynamicClassLoader into a static CHM that can be stored in Terracotta, but the compiler doesn't seem to be giving the classes to the DynamicClassLoader after compilation
16:11pjstadigplus i don't really know much about this stuff
16:12pjstadigi also thought maybe that i could just let clojure recompile the source files when connecting to TC so that it has the classes for each JVM
16:13pjstadigeven if I did, the class names would probably be different, plus you wouldn't be able to share anything except core objects
16:32jwinterLofDK: I think you can need to specify symbols or wildcards in the path that the route is matching against, then use those symbols or the route map
16:34Lau_of_DKOk guys, simple stuff now, in compojure, if the user navigates to 127.0.0.1/?name="frank"&age=22 I want those arguments passed to a function, what do I do, (GET "/*" (myfunc route)) doesnt seem to fly
16:36danlarkinLau_of_DK: Madison handles that quite well, I like to think :)
16:37Lau_of_DKDemo?
16:37Lau_of_DKbtw, (GET "/:action" (main (route :action)))
16:37Lau_of_DKthat flies
16:37jwinterso what's wrong?
16:38Lau_of_DKjwinter: that getting to that conclusion takes more than 10 secs due to missing docs
16:38jwintermeh, it's a new project. Look at the tests for documentation for now.
16:38danlarkinLau_of_DK: in Madison your view function would take two extra parameters, name and age
16:39Lau_of_DKWhat do you do when theres an arbitrary number of args?
16:40jwinterThere's a * wild card, you could parse that
16:41danlarkinwell for an URL that will always take a name and age you'd probably build it like /dan/24/ -- but for an URL with truly dynamic parameters (those that you can't predict) then you can just pull them out of the request hash-map, which is the first argument passed to all view functions
16:41Lau_of_DKk
16:42Lau_of_DKdanlarkin: Are you an Emacs guy ?
16:42danlarkinyep
16:42Lau_of_DKSo - Youve got some interactive repl development going already ?
16:42danlarkinindeed
16:42danlarkindo you mean with madison specifically?
16:42Lau_of_DKYea
16:42Lau_of_DKMadison Square Clabango
16:43jwintercompojure's also got a get-params fn that takes a servlet request
16:44jwinterreturns a map
16:45danlarkinthe django-inspired builtin runserver has autoreload functionality, so saving a file and then refreshing the webpage will use the new version
16:45jwinterdanlarkin: url?
16:45Lau_of_DKcool
16:45danlarkinjwinter: /Users/dan/Code/madison/ :)
16:46danlarkinit'll be up on github soon
16:46Lau_of_DKhaha
16:49danlarkinReal Soon Now(TM(TM)
16:49replacadanlarkin: that autoreload feature is the best thing a web dev framework can have!
16:49danlarkinreplaca: I agree
16:49replacadanlarkin: I'm looking forwad to playing with it
16:49danlarkinit was one of the first things I built, because trying to build the framework without it was too annoying
16:50replaca:-)
16:51replacabuilding developer friendly programs consists of two things: eating your own dog food and being really irritable ablout things that aren't the way you like 'em
17:17Lau_of_DKJust need a quick pointer - Im in compojure, and Ive computed some data and I want to return a chart - is there a good clean easy-to-use lib available for that?
17:18hiredmangoogle charts?
17:19Lau_of_DKIts not something you can use locally on your own server is it?
17:34clojurebotsvn rev 1323; restore list constants as PersistentLists
19:10danlarkinsweet, I've got a nice test-runner framework for madison
19:11danlarkinwalks a file-seq, turns each File into a Namespace, requires it and runs run-tests on it
19:12danlarkinand deals with its own classpath issues, so I don't have to add the tests directory to my classpath
20:06meredyddWhen did "#=" arrive?
20:06meredyddAnd is there now any way to use the reader to process untrusted data?
20:08durka42no, but rhickey said it is necessary and planned
20:08meredyddokay.
20:08hiredmanyou could look at clojurebot's sandbox
20:08meredyddclojurebot allows execution of code anyway
20:08meredydd(although the sandbox is very clever)
20:09hiredmanyeah, but in a limited way
20:09hiredmanwhich until we get a safe reader might be enough
20:09Chouser#=() has been around since early november.
20:11gnuvince_What's #-()?
20:11gnuvince_#=()
20:11hiredmandoes stuff at read time
20:11durka42,#=(prn "hi")
20:11clojurebotDENIED
20:13durka42Clojure=> (do (prn "run") #=(prn "read"))
20:13durka42"read"
20:13durka42"run"
20:13durka42nil
20:13gnuvince_OK
20:13gnuvince_It's not mentioned in the reader documentation on the website.
20:14ayrnieu<Holcxjo> BTW: Why is #= not mentioned ond http://clojure.org/reader#toc2 ? <Holcxjo> Deliberate or oversight? <rhickey> Holcxjo: Deliberate
20:15durka42yeah... why is it a secret
20:16hiredmanbecause it is likely to be abused
20:16ayrnieu*shrug* you've probably seen how people defend the status-quo. If it isn't known, people won't complain when it gets changed.
20:16hiredmanspeak of the devil
20:16gnuvince_the radix syntax is not mentioned either
20:16gnuvince_Another trade secret?
20:16durka42radix?
20:16durka42as in 0x16?
20:17gnuvince_,2r10100101
20:17clojurebot165
20:17gnuvince_,36rzzzz
20:17clojurebot1679615
20:17hiredmanHuh
20:17hiredmanthat is most interesting
20:17gnuvince_you give a base followed by r followed by digits for that base
20:17gnuvince_so you can input numbers in base 2 through 36
20:17replacaor the unicode character syntax (at least not last time I looked)
20:18replaca,\u01df
20:18clojurebot\?
20:19durka42at the repl that gives me \� and in gorilla \?
20:20replacaThose are rendering issues - but I'm no unicode expert
20:20durka42unicode says clojurebot is right and vim and my shell are wrong
20:20ayrnieuwith an emacs irc client, you can M-x describe-char with the point over the pretenders.
20:23durka42in vim apparently it is ga
20:24durka42hum, it is a gorilla bug - vim can display the character fine
20:25hiredmangorilla ist still using ruby right?
20:25durka42no
20:25durka42he's using nails
20:25hiredmanoh
20:25hiredmanwhat about jline?
20:26durka42um i don't know
20:27durka42iTerm can't handle \u01df
20:28hiredmanmight not be unicode by default
20:28forkingYourIOare all nodes on the same level always the same color on a red black tree?
21:34slashus2I don't understand what is going on in Issue 85.
21:37kid_meierhas anybody encountered an issue with slime/swank-clojure where upon connecting to the swank server the *slime-repl* buffer is not opened ?
21:42lisppaste8Rayne@acidrayne.net pasted "If you read this you will die in 7 days" at http://paste.lisp.org/display/76441
21:49cmvkkyeah that happens to me sometimes kid_meier
21:49cmvkkbut only sometimes
21:50kid_meierany clue how to fix it? it is happening for me consistently on Mac OS X
21:50kid_meieri have some suspicion it is emacs/slime/swank compat issue but not a guru to find out what it is.
21:50cmvkknope, i don't know anything about all that slime stuff. since it only happens to me sometimes, i've just been ignoring it.
21:50cmvkkat least you know now that it's cross-platform?
21:51kid_meierya... i seem to recall this happening awhile ago before on Linux.. updating to all of the development snapshots of the packages worked.
21:51kid_meierbut doesn't seem to be so easy to get all of those updated packages on Mac..
21:52kid_meiereh well, i'll keep playing with it.
21:52cmvkki don't suppose there's a way to open a new *slime-repl* buffer manually or something
21:54kid_meiernot that I can figure out.
22:02kid_meierwas able to get it working by rolling back to more conservative version of slime w/ emacs 22.1.1
22:21jhawk28What is the difference between let and binding?
22:22cmvkklet creates local 'variables'
22:23cmvkkbinding creates thread-specific bindings for Vars (which you can then change with 'set!')
22:24cmvkkso use let to create locals, and use Var when you want mutable globals, basically.
22:24cmvkkbinding, not Var
22:25jhawk28thanks
22:26jhawk28I think I understand
22:26cmvkkyou should probably go read about it on the site, i can't think of a good way to describe it succintly without it being confusing.
22:26jhawk28was trying to find it in the prag book
22:27durka42binding can only create thread-local bindings for existing vars
22:27jhawk28http://clojure.org/api#binding
22:27durka42(binding [does-not-exist 3]) => CompilerException
22:28arohnerbinding changes the value of a var inside the scope of the binding call
22:29arohner,(do (def x 1) (println "x is " x) (binding [x 2] (println x) (println "x is " x)) (println "x is " x))
22:29clojurebotDENIED
22:30cmvkkit's dynamically scoped. i don't know why, but lexical vs. dynamic scoping took me a while to grok when i was first learning CL.
22:31arohnercmvkk: no, it's lexically scoped
22:31arohnerlexically scoped means you can look at only that section of code and know what the value is
22:31cmvkkoh, really?
22:31arohnerdynamically scoped means it's necessary to know what code outside of your snippet is doing to understand the value
22:31ayrnieu,(binding [repeat (fn [x] [x])] (repeat 1))
22:31clojurebot[1]
22:32cmvkkfor some reason i assumed binding was analogous to setting special variables in CL
22:32arohnerso if you pretend my example above works,
22:32arohnerset the root value of x to 1
22:33ayrnieucmvkk - CL's let accomplishes has the role of clojure's let and binding.
22:33cmvkkno no, this is definitely dynamic scope.
22:33ayrnieuyes, it is.
22:33cmvkktry this: (def *x* 2), (defn foo [] (println *x*)), (foo), (binding [*x* 3] (foo))
22:34cmvkkVars bound with binding are dynamically scoped.
22:35arohnercmvkk: ok, I read the wikipedia article. you're right
22:35ayrnieuit's a common distinction. The scheme name for binding is fluit-let; Perl has 'my' lexical variables vs. 'local' dynamic variables.
22:36cmvkkyep.
22:36cmvkki forgot you could do it in perl too. I never used 'local' when i was using perl.
22:38ayrnieuit's useful in cases like: my $file_contents = do { local $/ = undef; <$fh> };
22:38ayrnieu(binding [*compile-files*] (load-file "hello.clj"))
22:38ayrnieu(binding [*compile-files* true] (load-file "hello.clj"))
23:22cooldude127i'm pissed off at myself. i JUST discovered clojure.contrib.math after rewriting a fair amount myself
23:23slashus2On issue 85, I am trying to figure out if having something like (defn testing testing2 ([x] x) ([x y] y)) is useful.
23:24rlbHmm, I should check and see where the debian clojure package stands...
23:28slashus2Any input?
23:30Chouserproviding arglist docs?
23:32slashus2Chouser: It seems to screw up the arglist metadeta?
23:39durka42~source clojure.core/sigs
23:39Chouseroh, I see. the only legal interpretations for 'testing2' is a docstring or attrmap, and a symbol's not a legal value for either
23:40durka42defn sees that testing2 is not a string, so it doesn't chop it off before calling sigs
23:40durka42sigs sees that testing2 is not a seq, so it assumes it is the one and only arglist