#clojure log - May 15 2008

The Joy of Clojure
Main Clojure site
Google Group
List of all logged dates

8:38 cgrand: rhickey: I seem to have a working patch handling overloads in genclass as discussed yesterday. Are you interested in it?

8:38 rhickey: wow! sure, I'll take a look

8:41 cgrand: cool! I sent it to you.

9:26 ozzilee: Does anyone know if there's a reason (read) won't read from a BufferedInputStream? Has it just not been implemented yet?

9:34 cgrand: InputStreams 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.

9:42 ozzilee: Ah. So I should create a PushBackReader for the InputStream, and then use read?

9:44 cgrand: yes (new java.io.PushBackReader (new java.io.InputStreamReader your-input-stream your-charset))

9:46 or a clojure.lang.LineNumberingPushBackReader

9:49 rhickey: anyone 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?

9:49 ozzilee: No dispatch macro for: j ? http://pastie.caboo.se/197520

9:53 I'm sure I did something dumb there, can't see it though.

9:54 rhickey: ozzilee: are you getting that error on compilation? compiles fine here for me

9:55 ozzilee: No, when I try to run it.

9:55 In the repl. It defines ok, but (run-cmd "ls") fails

9:55 rhickey: ls doesn't produce sexprs does it?

9:55 ozzilee: What? Nevermind it works suddenly.

9:55 That's weird.

9:56 No, now it doesn't. Let me paste the error.

9:56 rhickey: read is for reading sexprs

9:57 ozzilee: Duh. I knew that. Sorry. :-)

9:57 I was thinking of read-line.

9:58 Or something. Don't mind me, I'll just stumble along overe here...

10:27 rhickey: cgrand: do you think:

10:27 (def-overload write [[char] int int] ...)

10:27 is easier than:

10:27 (defn write<char<>-int-int> ...)

10:35 or (defn write-char<>-int-int ...)

10:36 cgrand: rhickey: not for primitive types but (def-overload write [CharSequence int int] ...) seems easier to me than (defn write<java:lang:CharSequence-int-int> ...)

10:36 rhickey: I don;t think the package prefixes are necessary

10:38 Can'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:39 * rhickey is complexity-averse

10:40 cgrand: Indeed, the odds are low.

10:40 rhickey: I'm willing to say in that case you can't distinguish and must share same handler

10:40 cgrand: In the 150MB of Spring we can maybe find such a case :-)

10:41 rhickey: I was trying to recall if I encountered this in jFli or Foil, both of which did wrapper generation

10:41 I don't think so

10:44 cgrand: I 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:44 maybe between java.sql.Date and java.lang.Date?

10:45 I meant java.util.Date

10:46 but it's certainly not worth the added complexity

10:46 rhickey: but you'd have to have an overload where the signature was the same except for the date type

10:47 I think ok to say they get the same handler fn

10:48 right, not worth the complexity for all other situations

10:54 ok, I'll integrate your patch, but without def-overload and with simplified class names

10:59 cgrand: great! Your naming convention (write<CharSequence-int-int>) made me think that there's no join function in boot.clj

11:00 rhickey: join?

11:00 cgrand: (defn join

11:00 "Returns a lazy seq of the values of coll separated by sep."

11:00 [coll sep]

11:00 (if-let etc (rest coll)

11:00 (cons (first coll) (lazy-cons sep (join etc sep)))

11:00 coll))

11:00 (must use lisppaste...)

11:03 rhickey: (drop 1 (interleave (repeat sep) coll))

11:06 I'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:08 any other name suggestions?

11:09 cgrand: let me see in other languages... I think php call it merge but merge is already taken

11:10 rhickey: separate?

11:11 ozzilee: intersperse

11:11 rhickey: intersperse implies a certain randomness

11:13 cgrand: no php call it implode but it's a bad name for this function (join wasn't that great either)

11:13 rhickey: it really is a variant of interleave

11:15 ozzilee: Chicken scheme calls it intersperse, I can't think of anything else I've heard it called. PHP I believe uses join as well.

11:16 Of course, that's for strings (in PHP).

11:17 cgrand: it would juste be handy to have it... maybe such functions belong in contrib

11:20 haskell call it intersperse too

11:43 rhickey: interpose

11:45 cgrand: intercalate, interject ?

11:46 rhickey: what's wrong with interpose?

11:47 cgrand: nothing: I'm just brainstorming

11:48 rhickey: ok

11:49 arg order would be (interpose sep coll)

11:50 cgrand: fine

11:54 rhickey: cgrand: if one of the overloads has no args, the overload name is foo- ?

11:54 cgrand: yes

11:54 rhickey: hmm...

11:55 cgrand: would you prefer foo<>?

11:55 rhickey: actually, I went with the foo-int-int flavor, now am wondering about this case

11:56 maybe foo-void

12:01 cgrand: Why not. Is the ending dash related to some naming convention (marking something as private?) or is it just not aesthetic?

12:01 rhickey: both

12:22 cgrand: 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:24 cgrand: ok

12:26 one error in all-sigs

12:48 rhickey: 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:52 rhickey: I'm almost done, the problems were keys called on a seq and no ~ on (seq p) ?

12:54 cgrand: no ~ on (seq p) and a missing distinct on concat (it also fix the keys pb)

12:54 fixes...

13:07 rhickey: ok

13:15 that 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:20 cgrand: ah ok, I copied it on you, let's change that to (map #(take 2 (first %)) (mapcat non-private-methods supers))

13:22 rhickey: got (map #(take 2 (key %)) (mapcat non-private-methods supers)) already :)

13:22 are you saying you copied that use of keys from me - where?

13:26 cgrand: see var-fields init in the current genclass.clj

13:27 rhickey: not there, sigs-by-name is a map

13:28 cgrand: but I introduced sigs-by-name -- by current I meant in SVN

13:30 rhickey: hah! finding my own bugs while examining your patch - this is useful! :)

13:33 ozzilee: RE join/intersperse/interpose: Interpose already seems to have a meaning. http://java.sun.com/developer/technicalArticles/JavaLP/Interposing/

13:36 rhickey: interpose means 'put between'

13:37 seems a precise description

13:39 ozzilee: Well, I don't see the point of making up new words for things that are already in common usage.

13:40 rhickey: interpose is an existing word

13:40 ozzilee: Right, meaning... something about overriding a method, I didn't read it that close.

13:40 Intersperse is an existing word meaning "put this element in between every element of this list"

13:40 rhickey: one article uses the word and that's canonic?

13:41 You should be using a dictionary and not other programming languages as your guide

13:41 ozzilee: Uh... that would make for a really frustating language, I would think. Coming from other languages.

13:42 rhickey: I strongly disagree

13:42 ozzilee: Dictionary of computer science terms maybe, but not an English dictionary.

13:44 I personally find learning the new names for ideas I already know to be the most annoying part of learning a new language.

13:44 rhickey: people 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:45 ozzilee: I don't think that means you should throw away any common names and start fresh, with yet another set of names.

13:46 I'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:46 Hell, I'm not going to argue at all, it's not that big of a deal :-)

13:46 Just raising a point of view.

13:48 rhickey: A lot of care has gone into most of the Clojure names - I spent a long time coming up with conj assoc dissoc etc

13:48 it would have been easy to reuse existing names that might have had wrong implications

13:50 ozzilee: Fair enough, I don't have any problem with any other names.

13:50 So far, anyway ;-)

13:50 rhickey: And I want the English to work - it taps into important semantic centers. When I see -sperse my mind thinks 'scatter'

13:50 when i see -pose my mind thinks 'put'

13:51 Maybe that's just my long-forgotten high school Latin :)

13:52 ozzilee: Hey, 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:53 rhickey: I do welcome input, just trying to explain my reasoning

13:54 ozzilee: Understood.

14:27 rhickey: 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:28 rhickey: Sorry, I don't have time to do that

14:29 ozzilee: Ok, 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:30 Anyway http://lxref.com/ref/Scheme/Clojure if anyway wants to take a look.

14:34 rhickey: Chouser: (def myseq (map constantly (iterate inc 0)))

14:40 there should probably be an alias for the sequence (iterate inc 0)

14:41 ozzilee: (iterate) with no args? My first thought.

14:45 rhickey: it would be a seq value, not a function

14:47 ozzilee: natural?

14:47 cgrand: but it would cause all enumerated numbers to stay in memory!?

14:49 rhickey: yeah, (naturals), (positives) or something would be better

14:50 really infinite ranges...

14:51 (range-> 0)

14:51 bleh

14:51 cgrand: (enumerate n) ?

15:00 Chouser: rhickey: heh, thanks.

15:00 rhickey: you could comment in my blog and up my street cred. ;-) ...or I will.

15:08 rhickey: Chouser: done!

15:09 Chouser: greak, thanks.

15:10 s/greak/great/ *sigh*

15:29 leafw: I'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:30 http://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:30 hope that helps.

15:32 rhickey: want to put it on the wiki?

15:32 leafw: so there is a wiki

15:32 sorry, I'm pretty new to clojure

15:33 rhickey: http://en.wikibooks.org/wiki/Clojure_Programming

15:33 leafw: I saw the example at http://clojure.sourceforge.net/features/jvm_hosted.html

15:34 rhickey: Right, I'll probably keep that short as it is docs, but the extra error handling you've done might be interesting

15:35 leafw: well, it really was just exploring the language. Very basic stuff.

15:37 I also wrote a tiny comparison between jython, java and clojure for ImageJ programming: http://pacific.mpi-cbg.de/wiki/index.php/Scripting_comparisons

15:41 if there's something terribly naive about the clojure code I wrote there, I'd appreciate some comments.

16:03 lisppaste8: rhickey pasted "ImageJ example" at http://paste.lisp.org/display/60801

16:04 leafw: nice

16:04 rhickey: leafw: that's a bit leaner, leveraging the current syntax support and some other idioms

16:04 leafw: thanks

16:04 rhickey: note: I did not run that

16:04 leafw: I will now

16:05 the (if (some #{text} commands) reads very cool

16:06 but why the #{ .. } ?

16:06 * drewr comes back after a couple weeks and it's a whole new language

16:06 rhickey: it's a set literal. Sets, like maps, are functions of their keys

16:07 user=> (some #{3 5} [1 2 5 6 7])

16:07 5

16:07 leafw: ij.Menus.getCommands() returns a Hashtable though

16:08 also your script fails with: Unable to resolve symbol: Color in this context

16:08 so perhaps the Color.red syntax is newer than my clojure.jar

16:09 rhickey: keys should work on any java.util.Map

16:10 leafw: ok, let me update my jar

16:14 hoeck: rhickey: i really like the new (.method Object args) syntax, tried it a while now.

16:14 rhickey: great!

16:15 that's the Lispy variant

16:15 I'm still on the fence about (obj.method args)

16:16 Many people think it is syntax, and try (foo).blah or %.blah etc

16:16 hoeck: oh, weird

16:17 leafw: obj.method ... is just java. I wouldn't do it.

16:17 rhickey: oops, well, change my example around then :)

16:17 hoeck: obj.args seems too hosty to me too, never used that

16:18 rhickey: I tried to make it as similar to the others as possible, except the early return...

16:19 Yeah, my thinking now is that (obj.method args) goes too far, and saves not much over (. obj method args), with same read order

16:19 removing the parens around args was the big win

16:21 leafw: rhickey : java.lang.ClassCastException: java.util.Hashtable$Entry cannot be cast to clojure.lang.IMapEntry

16:22 that's where your pastebin example fails.

16:32 rhickey: leafw: fixed - grab the latest

16:33 leafw: ok

16:33 you mean paste bin or svn ?

16:33 svn I assume

16:33 rhickey: svn

16:33 leafw: ok thank you.

16:34 rhickey: thanks for the report - I'd implemented key and val, get etc for java.util.Maps, but not keys and vals

16:35 leafw: glad that helped.

16:39 nice, script works now.

16:41 lisppaste8: rhickey annotated #60801 with "lispier" at http://paste.lisp.org/display/60801#1

16:42 rhickey: that's what it will be if I take back (obj.method args)

16:44 leafw: thanks

16:44 I like the changes in the (.setForeground prompt \n(if ...

16:44 * ozzilee has changed his mind, and now prefers (.method object args) too.

16:45 leafw: so (.method ...) and (. method ...) is the same? Note the white space.

16:45 then one cannot name variables starting with a dot (not that I'd want to anyway)

16:45 rhickey: no, its (.method obj args) or (. obj method args)

16:45 ozzilee: (.method Object args) or (. Object (method args)) or (. Object field), if I understand correctly.

16:46 rhickey: leafw: dot is reserved for me to provide Java interop

16:46 leafw: ok

16:46 got it.

16:47 rhickey: ozzilee: in the second case the parens around method args are optional

16:48 ozzilee: rhickey: Except in the case of no args, correct?

16:48 rhickey: no, that too, Clojure figures it out

16:48 ozzilee: Ah. Must be new. I'm checking out trunk on this machine right now.

16:49 rhickey: makes concatenated no arg calls a breeze with .. - (.. obj foo bar baz) insted of (.. obj (foo) (bar) (baz))

16:50 ozzilee: That's fantastic. It's easier to play with java libraries in clojure than it is in java. That's saying something.

16:54 leafw: ozzilee : yes!

16:54 that is for me the best argument for using clojure: lots of libraries, nice syntax.

16:56 ozzilee: Indeed. Especially with add-classpath now, which means I don't have to leave the REPL.

17:04 leafw: nice

17:10 I'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:12 rhickey: I think Clojure could be superior to the JavaFX language for JavaFX framework programming, eventually, and this kind of declarative constructions helps in that

17:30 ozzilee: Does clojure have a word for reading a stream to a string? Since read is for sexprs...

17:39 Also, is there a shortcut for (complement foo)? (!nil? bar) would be easier than ((complement nil?) bar)..

18:35 rhickey: cgrand: genclass overloading patch is up

22:55 ozzilee: Is there a way to have defmulti dispatch on whether or not the arg is an instance of a specified class, including subclasses?

22:56 rhickey: no, just equality, not instanceof

22:56 ozzilee: Ok, that's what I figured.

Logging service provided by n01se.net