#clojure logs

2008-05-15

08:38cgrandrhickey: I seem to have a working patch handling overloads in genclass as discussed yesterday. Are you interested in it?
08:38rhickeywow! sure, I'll take a look
08:41cgrandcool! I sent it to you.
09:26ozzileeDoes anyone know if there's a reason (read) won't read from a BufferedInputStream? Has it just not been implemented yet?
09:34cgrandInputStreams read bytes not characters that's why you need a Reader and, more precisely, a PushBackReader to handle the lookahead character of the lisp reader.
09:42ozzileeAh. So I should create a PushBackReader for the InputStream, and then use read?
09:44cgrandyes (new java.io.PushBackReader (new java.io.InputStreamReader your-input-stream your-charset))
09:46cgrandor a clojure.lang.LineNumberingPushBackReader
09:49rhickeyanyone written (or want to write) a (readable stream) function, that takes any InputStream/Reader derivee and piles on whatever layers are needed to bring it to read-ability?
09:49ozzileeNo dispatch macro for: j ? http://pastie.caboo.se/197520
09:53ozzileeI'm sure I did something dumb there, can't see it though.
09:54rhickeyozzilee: are you getting that error on compilation? compiles fine here for me
09:55ozzileeNo, when I try to run it.
09:55ozzileeIn the repl. It defines ok, but (run-cmd "ls") fails
09:55rhickeyls doesn't produce sexprs does it?
09:55ozzileeWhat? Nevermind it works suddenly.
09:55ozzileeThat's weird.
09:56ozzileeNo, now it doesn't. Let me paste the error.
09:56rhickeyread is for reading sexprs
09:57ozzileeDuh. I knew that. Sorry. :-)
09:57ozzileeI was thinking of read-line.
09:58ozzileeOr something. Don't mind me, I'll just stumble along overe here...
10:27rhickeycgrand: do you think:
10:27rhickey(def-overload write [[char] int int] ...)
10:27rhickeyis easier than:
10:27rhickey(defn write<char<>-int-int> ...)
10:35rhickeyor (defn write-char<>-int-int ...)
10:36cgrandrhickey: not for primitive types but (def-overload write [CharSequence int int] ...) seems easier to me than (defn write<java:lang:CharSequence-int-int> ...)
10:36rhickeyI don;t think the package prefixes are necessary
10:38rhickeyCan't imagine a case of a method overloaded on multiple classes with same name/different packages in different positions, and if so, would be similar to base case - both route through same fn
10:40cgrandIndeed, the odds are low.
10:40rhickeyI'm willing to say in that case you can't distinguish and must share same handler
10:40cgrandIn the 150MB of Spring we can maybe find such a case :-)
10:41rhickeyI was trying to recall if I encountered this in jFli or Foil, both of which did wrapper generation
10:41rhickeyI don't think so
10:44cgrandI have no strong opinion on the subject apart that I tried to handle the worst case (and it caused me to add this macro and make escaping more complex).
10:44cgrandmaybe between java.sql.Date and java.lang.Date?
10:45cgrandI meant java.util.Date
10:46cgrandbut it's certainly not worth the added complexity
10:46rhickeybut you'd have to have an overload where the signature was the same except for the date type
10:47rhickeyI think ok to say they get the same handler fn
10:48rhickeyright, not worth the complexity for all other situations
10:54rhickeyok, I'll integrate your patch, but without def-overload and with simplified class names
10:59cgrandgreat! Your naming convention (write<CharSequence-int-int>) made me think that there's no join function in boot.clj
11:00rhickeyjoin?
11:00cgrand(defn join
11:00cgrand "Returns a lazy seq of the values of coll separated by sep."
11:00cgrand [coll sep]
11:00cgrand (if-let etc (rest coll)
11:00cgrand (cons (first coll) (lazy-cons sep (join etc sep)))
11:00cgrand coll))
11:00cgrand(must use lisppaste...)
11:03rhickey(drop 1 (interleave (repeat sep) coll))
11:06rhickeyI'm not opposed to having a fn that does that, but prefer to save join for the notion in set/join, i.e. relational join
11:08rhickeyany other name suggestions?
11:09cgrandlet me see in other languages... I think php call it merge but merge is already taken
11:10rhickeyseparate?
11:11ozzileeintersperse
11:11rhickeyintersperse implies a certain randomness
11:13cgrandno php call it implode but it's a bad name for this function (join wasn't that great either)
11:13rhickeyit really is a variant of interleave
11:15ozzileeChicken scheme calls it intersperse, I can't think of anything else I've heard it called. PHP I believe uses join as well.
11:16ozzileeOf course, that's for strings (in PHP).
11:17cgrandit would juste be handy to have it... maybe such functions belong in contrib
11:20cgrandhaskell call it intersperse too
11:43rhickeyinterpose
11:45cgrandintercalate, interject ?
11:46rhickeywhat's wrong with interpose?
11:47cgrandnothing: I'm just brainstorming
11:48rhickeyok
11:49rhickeyarg order would be (interpose sep coll)
11:50cgrandfine
11:54rhickeycgrand: if one of the overloads has no args, the overload name is foo- ?
11:54cgrandyes
11:54rhickeyhmm...
11:55cgrandwould you prefer foo<>?
11:55rhickeyactually, I went with the foo-int-int flavor, now am wondering about this case
11:56rhickeymaybe foo-void
12:01cgrandWhy not. Is the ending dash related to some naming convention (marking something as private?) or is it just not aesthetic?
12:01rhickeyboth
12:22rhickeycgrand: could you double-check the all-sigs and sigs-by-name inits? They don't seem quite right, and the `s make it very difficult to understand. Thanks
12:24cgrandok
12:26cgrandone error in all-sigs
12:48cgrandrhickey: I found two bugs: one when using :methods and the other when a method is found twice through inheritance. Did you see/smell anything else? Do you want I resubmit a patch without the macro, without packages, withouts 's and with -void or angle brackets?
12:52rhickeyI'm almost done, the problems were keys called on a seq and no ~ on (seq p) ?
12:54cgrandno ~ on (seq p) and a missing distinct on concat (it also fix the keys pb)
12:54cgrandfixes...
13:07rhickeyok
13:15rhickeythat use of keys is still not right, it happens to work due to an implementation details, but keys takes a map, not a seq
13:20cgrandah ok, I copied it on you, let's change that to (map #(take 2 (first %)) (mapcat non-private-methods supers))
13:22rhickeygot (map #(take 2 (key %)) (mapcat non-private-methods supers)) already :)
13:22rhickeyare you saying you copied that use of keys from me - where?
13:26cgrandsee var-fields init in the current genclass.clj
13:27rhickeynot there, sigs-by-name is a map
13:28cgrandbut I introduced sigs-by-name -- by current I meant in SVN
13:30rhickeyhah! finding my own bugs while examining your patch - this is useful! :)
13:33ozzileeRE join/intersperse/interpose: Interpose already seems to have a meaning. http://java.sun.com/developer/technicalArticles/JavaLP/Interposing/
13:36rhickeyinterpose means 'put between'
13:37rhickeyseems a precise description
13:39ozzileeWell, I don't see the point of making up new words for things that are already in common usage.
13:40rhickeyinterpose is an existing word
13:40ozzileeRight, meaning... something about overriding a method, I didn't read it that close.
13:40ozzileeIntersperse is an existing word meaning "put this element in between every element of this list"
13:40rhickeyone article uses the word and that's canonic?
13:41rhickeyYou should be using a dictionary and not other programming languages as your guide
13:41ozzileeUh... that would make for a really frustating language, I would think. Coming from other languages.
13:42rhickeyI strongly disagree
13:42ozzileeDictionary of computer science terms maybe, but not an English dictionary.
13:44ozzileeI personally find learning the new names for ideas I already know to be the most annoying part of learning a new language.
13:44rhickeypeople come from all different programming languages, where different names mean the same thing, the same names mean different things, and some names are just plain bad/wrong
13:45ozzileeI don't think that means you should throw away any common names and start fresh, with yet another set of names.
13:46ozzileeI'm not going to argue for car or cdr here, I agree with head and tail, but intersperse seems pretty damn close to good enough, and it's got a chance of transferring from prior knowledge.
13:46ozzileeHell, I'm not going to argue at all, it's not that big of a deal :-)
13:46ozzileeJust raising a point of view.
13:48rhickeyA lot of care has gone into most of the Clojure names - I spent a long time coming up with conj assoc dissoc etc
13:48rhickeyit would have been easy to reuse existing names that might have had wrong implications
13:50ozzileeFair enough, I don't have any problem with any other names.
13:50ozzileeSo far, anyway ;-)
13:50rhickeyAnd I want the English to work - it taps into important semantic centers. When I see -sperse my mind thinks 'scatter'
13:50rhickeywhen i see -pose my mind thinks 'put'
13:51rhickeyMaybe that's just my long-forgotten high school Latin :)
13:52ozzileeHey, it's your language, I can't fault you for anything you've done so far, so whatever you think is probably going to be best.
13:53rhickeyI do welcome input, just trying to explain my reasoning
13:54ozzileeUnderstood.
14:27ozzileerhickey: If I were to put together a list of Clojure equivalents to some other language, what language would be easiest for you to check and tell me what I missed?
14:28rhickeySorry, I don't have time to do that
14:29ozzileeOk, and that's fine. Oh, I don't mean missed, really, more like "doseq isn't really like foreach, that should be foo". I'll probably only do a dozen or so functions for now.
14:30ozzileeAnyway http://lxref.com/ref/Scheme/Clojure if anyway wants to take a look.
14:34rhickeyChouser: (def myseq (map constantly (iterate inc 0)))
14:40rhickeythere should probably be an alias for the sequence (iterate inc 0)
14:41ozzilee(iterate) with no args? My first thought.
14:45rhickeyit would be a seq value, not a function
14:47ozzileenatural?
14:47cgrandbut it would cause all enumerated numbers to stay in memory!?
14:49rhickeyyeah, (naturals), (positives) or something would be better
14:50rhickeyreally infinite ranges...
14:51rhickey(range-> 0)
14:51rhickeybleh
14:51cgrand(enumerate n) ?
15:00Chouserrhickey: heh, thanks.
15:00Chouserrhickey: you could comment in my blog and up my street cred. ;-) ...or I will.
15:08rhickeyChouser: done!
15:09Chousergreak, thanks.
15:10Chousers/greak/great/ *sigh*
15:29leafwI've created a version of the temperature converter that uses try/catch (as example) and has better error handling and reporting, for example with non-numerical input
15:30leafwhttp://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=fiji.git;a=blob;f=plugins/Examples/celsius_to_fahrenheit.clj;h=9eced8857a51f0aefe85f323f1aaa6720821e5e9;hb=59f3df76a329433e0f7adde94e5d7f9806314e5b
15:30leafwhope that helps.
15:32rhickeywant to put it on the wiki?
15:32leafwso there is a wiki
15:32leafwsorry, I'm pretty new to clojure
15:33rhickeyhttp://en.wikibooks.org/wiki/Clojure_Programming
15:33leafwI saw the example at http://clojure.sourceforge.net/features/jvm_hosted.html
15:34rhickeyRight, I'll probably keep that short as it is docs, but the extra error handling you've done might be interesting
15:35leafwwell, it really was just exploring the language. Very basic stuff.
15:37leafwI also wrote a tiny comparison between jython, java and clojure for ImageJ programming: http://pacific.mpi-cbg.de/wiki/index.php/Scripting_comparisons
15:41leafwif there's something terribly naive about the clojure code I wrote there, I'd appreciate some comments.
16:03lisppaste8rhickey pasted "ImageJ example" at http://paste.lisp.org/display/60801
16:04leafwnice
16:04rhickeyleafw: that's a bit leaner, leveraging the current syntax support and some other idioms
16:04leafwthanks
16:04rhickeynote: I did not run that
16:04leafwI will now
16:05leafwthe (if (some #{text} commands) reads very cool
16:06leafwbut why the #{ .. } ?
16:06rhickeyit's a set literal. Sets, like maps, are functions of their keys
16:07rhickeyuser=> (some #{3 5} [1 2 5 6 7])
16:07rhickey5
16:07leafwij.Menus.getCommands() returns a Hashtable though
16:08leafwalso your script fails with: Unable to resolve symbol: Color in this context
16:08leafwso perhaps the Color.red syntax is newer than my clojure.jar
16:09rhickeykeys should work on any java.util.Map
16:10leafwok, let me update my jar
16:14hoeckrhickey: i really like the new (.method Object args) syntax, tried it a while now.
16:14rhickeygreat!
16:15rhickeythat's the Lispy variant
16:15rhickeyI'm still on the fence about (obj.method args)
16:16rhickeyMany people think it is syntax, and try (foo).blah or %.blah etc
16:16hoeckoh, weird
16:17leafwobj.method ... is just java. I wouldn't do it.
16:17rhickeyoops, well, change my example around then :)
16:17hoeckobj.args seems too hosty to me too, never used that
16:18rhickeyI tried to make it as similar to the others as possible, except the early return...
16:19rhickeyYeah, my thinking now is that (obj.method args) goes too far, and saves not much over (. obj method args), with same read order
16:19rhickeyremoving the parens around args was the big win
16:21leafwrhickey : java.lang.ClassCastException: java.util.Hashtable$Entry cannot be cast to clojure.lang.IMapEntry
16:22leafwthat's where your pastebin example fails.
16:32rhickeyleafw: fixed - grab the latest
16:33leafwok
16:33leafwyou mean paste bin or svn ?
16:33leafwsvn I assume
16:33rhickeysvn
16:33leafwok thank you.
16:34rhickeythanks for the report - I'd implemented key and val, get etc for java.util.Maps, but not keys and vals
16:35leafwglad that helped.
16:39leafwnice, script works now.
16:41lisppaste8rhickey annotated #60801 with "lispier" at http://paste.lisp.org/display/60801#1
16:42rhickeythat's what it will be if I take back (obj.method args)
16:44leafwthanks
16:44leafwI like the changes in the (.setForeground prompt \n(if ...
16:45leafwso (.method ...) and (. method ...) is the same? Note the white space.
16:45leafwthen one cannot name variables starting with a dot (not that I'd want to anyway)
16:45rhickeyno, its (.method obj args) or (. obj method args)
16:45ozzilee(.method Object args) or (. Object (method args)) or (. Object field), if I understand correctly.
16:46rhickeyleafw: dot is reserved for me to provide Java interop
16:46leafwok
16:46leafwgot it.
16:47rhickeyozzilee: in the second case the parens around method args are optional
16:48ozzileerhickey: Except in the case of no args, correct?
16:48rhickeyno, that too, Clojure figures it out
16:48ozzileeAh. Must be new. I'm checking out trunk on this machine right now.
16:49rhickeymakes concatenated no arg calls a breeze with .. - (.. obj foo bar baz) insted of (.. obj (foo) (bar) (baz))
16:50ozzileeThat's fantastic. It's easier to play with java libraries in clojure than it is in java. That's saying something.
16:54leafwozzilee : yes!
16:54leafwthat is for me the best argument for using clojure: lots of libraries, nice syntax.
16:56ozzileeIndeed. Especially with add-classpath now, which means I don't have to leave the REPL.
17:04leafwnice
17:10leafwI've just noted now that you forgo the use of the 'new' key, for a dot at the end of the class name. Makes sense. It's like using SomeClass.new SomeSubclass when out of context, in java.
17:12rhickeyI think Clojure could be superior to the JavaFX language for JavaFX framework programming, eventually, and this kind of declarative constructions helps in that
17:30ozzileeDoes clojure have a word for reading a stream to a string? Since read is for sexprs...
17:39ozzileeAlso, is there a shortcut for (complement foo)? (!nil? bar) would be easier than ((complement nil?) bar)..
18:35rhickeycgrand: genclass overloading patch is up
22:55ozzileeIs there a way to have defmulti dispatch on whether or not the arg is an instance of a specified class, including subclasses?
22:56rhickeyno, just equality, not instanceof
22:56ozzileeOk, that's what I figured.