#clojure logs

2009-06-29

00:22fulletsCan someone give me a clue as to how I would create two (proxy [AbstractAction] ...) forms that refer to each other?
00:23fulletsi.e., something like http://clojure.pastebin.com/d1be1fd79 that will actually work
00:29replacafullets: I can think of a bunch of cheats that use specials or refs, but I'm having a hard time coming up with anything straightforward that feels right
00:30replacafullets: But that may just be too much time in the sun this weekend
00:58JAS415is there a proxy and gen-class for common lisp dummies available anywhere?
02:08fffejin Clojure Contrib it says I can rebind the tracer function - embarassingly I don't know how to do that without wrapping my entires set of code in a (binding) construct
02:08fffejis there an easier way?
02:08hoeckfffej: you can use alter-var-root to change the root binding of a var
02:09fffejthanks!
02:10fffejso something like (alter-var-root tracer (constantly (constantly nil)))?
02:13hoeckfffej: yes, then your var-value will be (constantly nil)
02:14fffejthanks again!
02:15hoeckyou may want to try set! too: http://clojure.org/vars#set
02:15hoeckyou're welcome :)
02:15fffejI'd be looking at unalias in the namespaces - that didn't seem to help
02:24fffejhoeck: I got there in the end: (alter-var-root (var clojure.contrib.trace/tracer) (constantly (constantly nil))) seems to disable tracing, thanks for your help
02:30hoeckah, yes, that disables the tracer function
02:31hoeckthe clojure head has got :pre and :post conditions to functions; maybe those are suitable for inserting traces too
02:33fffejand any other AOP type applications too I guess
02:55Lau_of_DKMorning gents
03:31cgrandhi all
04:01AWizzArdHi cgrand
04:05cgrandAWizzArd: good morning
08:10AWizzArdHello dear regexperts. I would like to know how a regexp would look (if it exists) and what function I need to call that splits a text for me into several strings, depending on some "groups". For example I have the groups: whitespace, numbers, special-chars and non-whitespace. Into the first group I want to put all chars that I want to treat as whitespace. I would like to call (regexp-foo regexp "Greetings to/t /t/nall Clojure fans12345in the world.") ==
08:12Chouserthat got cut off at ==
08:14AWizzArd(regexp-foo regexp "Greetings to/t /t/nall Clojure fans12345in the world.") ==> ["Greetings", " ", "to", "/t /t/n", "all", " ", "Clojure", " ", "fans", "12345", "in", " ", "the", " ", "world", "."]
08:14AWizzArdthe ==> was your "=="
08:15Chouser(re-partition #"[\s\d]+" "Greetings to\t \t\nall Clojure fans12345in the world.")
08:15AWizzArdSo, one whitespace group would contain space, \t, \r, \n but also for example the whitespace char that appears when one in Windows holds down the Alt key and types 255 on the number pad.
08:15Chouserre-partition is in clojure.contrib.str-utils
08:16Chouseroh, you want . classified as whitespace
08:16Chouser#"[\s\d.]+"
08:17AWizzArdChouser: re-partition looks like what I want, or at least nearly as what I want. In your regexp [\s\d.] you list three of my groups: \s and \d and the .
08:18AWizzArdIt is just that I would like to have some few more chars in \s. Can I do something like [[\s xß]\d[.-+*/']] ?
08:19ChouserI think you don't want the inner [], but yes that should work
08:19Chouser[-\s xß\d.-+*/']
08:19Chouser[-\s xß\d.+*/']
08:20Chouseror is it that you want each of those groups split differently
08:20Chouser"123 456" ==> ["123" " " "456"] ?
08:20Chousercemerick: good morning!
08:20AWizzArdyes, if I have "hello x ßguys" I would like to get ["hello", " x ß", "guys"]
08:20cemerickChouser: same to you :-)
08:21cemerickfor a second, I thought someone had set up a greeting bot in #clojure ;-)
08:21ChouserAWizzArd: hm, yes that's a bit trickier.
08:21Chousercemerick: :-)
08:22AWizzArdwhat is re-groups for?
08:22AWizzArdDoes that allow me to define several chars that I want to treat as one group, and get all strings consisting out of those?
08:23AWizzArdAnd is there also such a splitting mechanism that keeps the positions (start, end) of the found groups?
08:23ChouserAWizzArd: no, it's just to help interact with the java regex api. You use it on a regex match object after the match has happened.
08:23Chouserkinda internal.
08:24ChouserThere's an open question on what to do with things like that on non-JVM Clojures that implement regex's with a different api.
08:25ChouserAWizzArd: very interesting puzzle. You want (.split "\b" string) but with your own definition of word-boundary.
08:27cemerickyeah, I saw no one replied to D. Miller's post about making the re-* cross-platform.
08:27achimAWizzArd: how about re-seq?
08:28achimhere's an example for 3 char classes: (re-seq #"[abc]+|[def]+|[jki]+" "adeadedfababacjki")
08:28achim,(re-seq #"[abc]+|[def]+|[jki]+" "adeadedfababacjki")
08:29Chousercemerick: I nearly have a couple times, but with thoughts so vague I keep deciding it's not worth anybody's time.
08:29Chouserachim: ah! I think you nailed it.
08:29cemerickYeah, I don't see myself using clojureCLR much if at all, so I'm keeping my poorly-informed opinions out of that one.
08:30AWizzArdachim: I will try that
08:31AWizzArdone sec
08:32ChouserI don't see how to avoid classifying "non-whitespace" using that method.
08:32Chouserbut maybe that's not a problem.
08:32AWizzArdwell, maybe there is something that matches everything
08:33AWizzArdre-seq looks at least very promising. It is basically doing 95% of what I want. It only does not report the positional info.
08:34Chouseroh, actually, maybe feed achim's regex into re-partition.
08:35Chouser(re-partition #"[abc]+|[jki]+" "adeadedfababacjki") ==> ("" "a" "de" "a" "dedf" "ababac" "" "jki")
08:35ChouserAWizzArd: positional info can be re-created from the match seq
08:36AWizzArdChouser: yes, re-partition would help. I would specify my whitespace, number and special-char group and leave the non-whitespace group unspecified. re-partition would then split as I wish.
08:37AWizzArdYes, the result seq implicitly stores positional information. It looks as if nothing got thrown away.
08:37AWizzArdVery good, thank you Chouser and achim :-)
08:38AWizzArdbtw, any one here knows the regexp for getting the numbers of the next lottery?
08:39achimhmm, i vaguely remember seeing a "reducing" fn somewhere, but don't remeber, where ...
08:39ChouserAWizzArd: I think so -- what's the format of the input?
08:39Chouserachim: clojure.contrib.seq-utils/reductions
08:39achimChouser: thanks!
08:41achim(reductions + 0 (map count (re-partition #"[abc]+|[def]+|[jki]+" "adeadedfababacjki")))
08:41AWizzArd:-)
10:15rhickeyPreferences? (partition n step pad coll) or (partition n step coll pad)
10:18danlei`I like the first one better
10:21Chousukea keyword argument would be nicer IMO, but I also prefer the former of the two.
10:21danlei`keyword would be nice, indeed
10:22rhickeythen step and pad would be keys
10:22Chouserthe coll is important, and it most fns it appears either first or last (interesting when it's one vs. the other)
10:24rhickeyrationale here: http://groups.google.com/group/clojure/msg/a8866d34b601ff43
10:25ChouserI've always been in favor of at least optionally named args in general.
10:25rhickeyoptionally named?
10:25Chouserrhickey: ah, nice link. That would argue for coll last.
10:27rhickeyChouser: yes, that's what I originally argued, now just double checking this doesn't feel more like a 2 seq fn, a la concat, since it really is the partitioning of the concatenation
10:27Chouseryeah, allowing the caller to name some (or all) the args, but also providing a way to not name them in simple cases.
10:28Chouserpython has a solution for this (though it's not quite ideal).
10:28rhickeyChouser: sounds complicated and potentially slow
10:28Chouserif you "def foo(a, b, c)" you can call foo(1, 2, 3), foo(1, c=3), or whatever.
10:29rhickeyearly clojure had CL-style keyword and optional args
10:29Chouseryou know how I feel about slow :-) but could something built on :inline help alleviate that in many cases?
10:29danlei`why did you drop the keyword args?
10:30rhickeydanlei`: becasue they are not needed often enough, nor primitive
10:30Chouseractually, it was thoughts along these lines that prompted me to work on {:keys [...]} destructuring early on.
10:31Chouserrhickey: and by you accepting that patch, I fear you've sealed your fate -- you'll never be rid of me now.
10:31danlei`rhickey: hm, but hand-rolled keyword args are not seldom ... wouldn't something like defnk from c.c. be nice in core?
10:32rhickeyI have nothing against keyword args, there's just no need for primitive syntax in fn for them
10:32Chouserthe fact that java is so much faster when dealing with positional args over keyword args does modulate my opinion.
10:33stuartsierraCan keyword args be handled at compile time?
10:34rhickeyIn a large codebase of CL (where it is very idiomatic), keyword usage was < 10% of functions
10:34rhickeystuartsierra: some cases, sure
10:34rhickey&optional less still
10:35Chouser3 args is about the limit of what strikes me as comfortable without keywords. Putting keywords only on the end somewhat frustrates partial application. I could contradict myself all day...
10:35rhickeyand both are somewhat covered by true variable arity
10:35danlei`hm ... to me something around 10% is not really sparse, but ok
10:35stuartsierracompile-time keyword args would certainly be more efficient than (apply hash-map args)
10:36rhickeydanlei`: I bet you could nuke a ton of them just for :test, :start etc, which aren't really needed when you don't have so much variability in equality semantics and you have things like rseq
10:36rhickey:from-end
10:36rhickeyetc
10:37rhickeyClojure's own code is a testament to the fact that keyword args aren't needed often
10:37rhickeySo in the good fight against complexity, they lost
10:38ChouserI don't suppose 'partition' could be split up in such a way that no one function needs all 4 args?
10:38stuartsierraThat's true for core fns, but they're more heavily used in contrib libs, where you need to configure some external object.
10:38danlei`I see, I'll think about it
10:39rhickeyChouser: I'm thinking now that overloading partition is wrong, as soon as I wrote "partitioning of the concatenation above"
10:39Chouserif partition always acted like it had a nil pad, then you could either filter on subseq length (original behavior) or pad to a given length (new behavior)
10:39rhickeyreally should have a different fn for partition with variable length trailing, rather than key it off of a pad
10:40rhickeyChouser: not changing original behavior
10:41rhickeyjust need a name for (partition+ n step coll) where it can yield partial partitions at end
10:42Chouserrhickey: clojure.contrib.seq-utils/partition-all
10:42rhickeyright, but -all doesn't say much
10:42rhickeyto me
10:43Chouserthere was a discussion...
10:43stuartsierrapartition-remainder
10:45Chousukeor simply partition-with-pad, but it's a bit long
10:46rhickeyChousuke: but it's not with-pad, you don't need pads since you have concat
10:46Chousukehmm.
10:47rhickeypartition*
10:48Chouserhttp://groups.google.com/group/clojure/msg/e34f62e95d9de1c9
10:48ChouserSo I guess I'm to blame for -all
10:49Chouseroriginally proposed as "chunk" -- guess that's out. :-)
10:49stuartsierraMaybe "partition" includes the ending and "strict-partition" doesn't.
10:49Chouser-all was meant to suggest that none of the original seq was left out.
10:50rhickeyyeah, a completely different name, e.g. subseqs, wouldn't help people who first try partition and then want trailing partials
10:51Chousukepartition* might be good enough.
10:51rhickeychould also be considered a variant on take
10:51rhickeyor take-nth
10:52rhickeytake-seqs
10:53rhickey(take n step coll)
10:55rhickeyfor me, non-regular partition sizes isn't really partition
10:56Chousera comment in the docstring would be sufficient to get from partition to something named differently
10:56rhickeyI'm not arguing against the utility of taking subseqs every nth
10:57rhickeywould (take n step coll) be misleading>
10:57rhickey?
10:58stuartsierrawhat does the step mean there?
10:58rhickeythe nice thing about it is that it doesn't promise exactly n, as take doesn't
10:59Chouserseems more surprising to me for take to return something starting past the beginning, than for partiton to return short seqs
10:59rhickeystuartsierra: step is the offset (take n n coll) == (partition-all n coll)
10:59stuartsierrahmm
10:59Chouser(map #(take n %) (nth-nexts step coll)) ?
11:00Chouserexcept with a better name for nth-nexts
11:01rhickey(take-subs n coll) (take-subs n step coll)
11:02Chouseryes
11:04rhickeytake-subs or take-seqs?
11:05stuartsierra"take-groups" ?
11:06rhickeystuartsierra: probably best not to consume another concept for this :)
11:06Chousuketake-subs makes me hungry :P
11:06ChouserI think "subs" because that more clearly indicates they're shortened
11:07rhickeyChouser: good point
11:07rhickey,(doc subs)
11:07Chousukeno clojurebot apparently :/
11:07Chouserclojurebot and hiredman are both MIA
11:07rhickey-------------------------
11:07rhickeyclojure.core/subs
11:07rhickey([s start] [s start end])
11:07rhickey Returns the substring of s beginning at start inclusive, and ending
11:07rhickey at end (defaults to length of string), exclusive.
11:08ChousukeI wonder if it's too abbreviated. I wouldn't mind take-subseqs
11:08Chouserwhy is that even in core?
11:08Chousukesubs definitely is too abbreviated :P
11:09ChouserI guess it lets you avoid hinting the String *shrug*
11:10rhickeySpot the difference:
11:10rhickeyhttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#substring(int,%20int)
11:11rhickeyhttp://msdn.microsoft.com/en-us/library/system.string.substring.aspx
11:11Chouserbleh
11:11stuartsierraone off
11:11Chouserend vs len
11:11rhickeyright
11:11ChouserI think javascript has both. :-)
11:12rhickeyso we don't want .substring calls everywhere
11:12stuartsierraBut I've been bugged that (subs "hi" 0 10) throws an exception.
11:13stuartsierraThis is why I wrote c.c.str-utils2.
11:13ChouserJS substr is like .net, JS substring is like Java
11:13rhickeysubs was added when I was trying to get Norvig's spell corrector out the door
11:14rhickeyvs Python which has something more concise for this
11:17Chouserah, yeah -- array range syntax that works also on strings
11:18rhickeyanyway, is take-subs confusing due to subs, hunger issues aside?
11:20Chouserany chance of renaming "subs" to "substring"?
11:20Chouserbut either way, I'd say "no".
11:21rhickeyChouser: possible, but the comparison vs Python will remain. For people doing a lot of that, typing out substring will seem quite tiresome
11:22ChousukeI think it's better to be a bit more verbose and have take-subseqs
11:22ChouserI'd be fine with take-subseqs
11:24Chouserrhickey: but python can be concise there because it's leveraging the "namespace" of the object, just like any other OOP. Pushing object-specific methods up to the core namespace is a bit like cheating.
11:33albinoand cheating is the right way to do it :)
11:39cemerickThere has to be a fool in every room, so I'll take that on today: why not a reader macro for subsequencing in general? #[seq-or-string 0 10]?
11:40stuartsierraOr first class ranges, like Ruby (#[0 10] seq-or-string)
11:40cemerickI'm not sure I'd ever use it myself, but if some group of users is doing a lot of string-mangling, it might make sense.
11:41cemerickstuartsierra: that's even better
11:42Chouserthat would do substring, subvec, or drop/take as appropriate?
11:43cemerickyeah, that's the thought
11:44cemerickhaving all of these siloed fns for strings, vectors, seqs, etc., doesn't make sense to me
11:44rhickey_IBM's X10 was doing some neat thing with first-class regions, encompassing ranges and multidimensional indexing
11:45Chousukeshouldn't be too difficult. The crappy thing is that IFn seems to be a painful interface to implement :P
11:45Chouserreader support for ranges is independent of a general sub-part fns though
11:45rhickey_ranges for non-indexed data structures are bad
11:45rhickey_so not for take/drop
11:45ChouserChousuke: AFn and RestFn aren't bad though, are they?
11:45Chousukeis AFn enough?
11:46cemerickor, I should say, having all those siloed fns makes a lot of sense, but they shouldn't be the primary interface for 98% of all users. That other 2% might have some really good reason to explicitly choose one of them in a hot loop if something's known to be a particular type.
11:46Chouserselect-keys for maps?
11:46Chousereh. hm.
11:46Chousernm.
11:46ChousukeChouser: hm, but AFn is a class. Range already extends ASeq
11:47Chouserah
11:47Chousukemost of implementing IFn is just cut & paste.
11:47ChouserChousuke: why not write it in clojure, for goodness' sake!?
11:48ChousukeRange is in Java. :/
11:48rhickey_Chousuke: not in chunks branch
11:49Chousukeoh? neat.
11:49rhickey_but something that only did ranges and not multidimensional indexing is a waste, IMO
11:51rhickey_in X10 it's something like #[0:10] for a range and #[0:10 20:100] for a first-class md region
11:56Chousukehm, that will be trickier
12:17achimhow do languages with native range support handle range-minus, e.g. [0, 3] \ [1, 2] ?
12:18stuartsierraHm, Ruby doesn't define minus on ranges.
12:20achimthat's the easy way ;) - i tried implementing some range arithmetics stuff a while ago and ended up with by basic type being a set of vectors (ranges). that's probably not the way to go in terms of code readibility
12:25cheddarwhat's a good way of making a queue? If it's n-elements long, should I just do (let [new-queue (cons new-element (take n-1 queue))])?
12:26cheddarperformance-wise, would that be a reasonable approach?
12:26achimcheddar: (clojure.lang.PersistentQueue/EMPTY) - conj'es from the right, pops and peeks from the left
12:42Chousukehm
12:42Chousukewell, implementing a simple splice was easy, but I'm not convinced it's good enough.
12:43Chousukestepping and such will be the real problem anyway
12:46Lau_of_DKGood evening gentlemen
12:52jackdempseyevenin
12:52jackdempseyanyone have video recommendations for clojure? been through the blip.tv vids a bit, looking for other stuff easy to ingest while workin out
12:53Lau_of_DKtechnomancy had some screencasts going that looked awesome
12:53jackdempseyoh nice
12:55technomancyyups: http://peepcode.com/products/functional-programming-with-clojure
12:55technomancynot free though; sorry
12:56jackdempseyhehe
12:56jackdempseyi love open source, however, the day you produce something amazing and have to say "its not free, sorry"
12:56jackdempseydunno :-)
12:56jackdempseyhappy to fork over the huge sum of $9 for some great content
12:57jackdempseywas actually in the process of buying that when you linked to it
12:57technomancycool. =)
12:57jackdempseydid you used to do some merb stuff as well? i recognize your nick from somewhere
12:57technomancyI used to write a lot of Ruby and have done a number of Elisp tools.
12:57technomancyonly dabbled in merb a small amount
12:58jackdempseyah ok cool
12:58jackdempseymaybe it was sequel, or dm, or who knows :-)
12:58jackdempseynice, cardio here i come
13:09Lau_of_DKtechnomancy: When will your screencast on ClojureQL be up ? And how much should I expect to get from that in terms of royalities ?
13:11technomancyhehe
13:11technomancyLau_of_DK: I'm actually thinking of doing a short intro to paredit
13:12Lau_of_DKOk, thats actually not the same thing :)
13:12technomancysince it's easy to get confused by it, but it's super-helpful once you get the hang of it.
13:12Lau_of_DKI never use it - hitting shift+8 just didnt seem like a big investment
13:14jackdempseyclojureQL?
13:14Lau_of_DKYep
13:15Lau_of_DKIts hot
13:15jackdempseyah
13:15jackdempseyi see
13:15Lau_of_DKhttp://github.com/Lau-of-DK/clojureql/tree/master
13:15jackdempseycool
13:15jackdempseyyeah looking
13:16Lau_of_DKI'll make a post on the group later, but its v0.9 now, coming up on 1.0, so people are very welcome to fire away with bug-reports/feature-requests/love-letters etc. (last one should go to meikel)
18:40ChousukeI finally figured out how c.c.monads
18:56Chousukedanlei: see http://gist.github.com/137862 for a monadic version of ansi2html
18:56Chousukenow I need some sleep.
19:20danleiChousuke: mee too, 1:19am over here ;) thanks for the effort, I'll have a look at it tomorrow (and a little talk I guess ;)
20:26durka42did anyone enter icfp in clojure?
20:29jackdempseydurka42: dont' think so, seen that asked here a couple times
20:29jackdempseyactually one person did say they were doing something for it....but maybe that was you? :-)
20:29durka42did i?
20:29durka42i did, but i don't remember mentioning it
20:29durka42i didn't have time to really do it, but i solved the first challenge
20:30durka42~logs
20:30jackdempseyah cool
20:30jackdempseyyeah i think it was someone else
20:30jackdempseycan't recall their nick tho
20:34Chouserhttp://clojure-log.n01se.net/date/2009-06-27.html#12:02b
20:35blbrown_win2I think I am having classloader issues NoClassDefFoundError, etc. I am trying to invoke a java library from clojure I get an error where Log4J Logger is not found. I believe it has to do with the DynamicClassLoader. Is there more than one DynamicClassLoader can I use the Clojure classloader?
20:37durka42hiredman: where's your protegé? :p
21:53samwisemhey I was just wondering, 'clojure.lang.Script' and 'clojure.lang.Repl' seem deprecated, and the preferred way is to launch everything through 'clojure.main' now?
21:54durka42correct
21:55samwisemthanks
22:24eyerisWhat is the syntax for a function that returns a constant, literal value?
22:25fullets[w](constantly 42) might do what you want
22:25eyerisNice. Thanks.
22:29eyerisWhy is this false? (== ((constantly true)) true)
22:29eyeris,(== ((constantly true)) true)
22:29eyerisIn fact, (== true true) is false
22:30fullets[w]I believe == is for comparing numbers
22:30fullets[w](= ((constantly true)) true) is true
22:31eyerisOkay
22:31eyerisThanks
22:37eyerisI read the documentation for each about 5 times.
22:37eyerisKnowing that my first understanding is wrong, it totally makes sense.
22:38eyerisBut when I read it, the brevity of the definition of == made it seem as if it were just a modification of the definition of =, meaning that it returned a non-nil value, not garunteeing a boolean.