2008-05-15
| 08:38 | cgrand | rhickey: I seem to have a working patch handling overloads in genclass as discussed yesterday. Are you interested in it? |
| 08:38 | rhickey | wow! sure, I'll take a look |
| 08:41 | cgrand | cool! I sent it to you. |
| 09:26 | ozzilee | Does anyone know if there's a reason (read) won't read from a BufferedInputStream? Has it just not been implemented yet? |
| 09: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. |
| 09:42 | ozzilee | Ah. So I should create a PushBackReader for the InputStream, and then use read? |
| 09:44 | cgrand | yes (new java.io.PushBackReader (new java.io.InputStreamReader your-input-stream your-charset)) |
| 09:46 | cgrand | or a clojure.lang.LineNumberingPushBackReader |
| 09: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? |
| 09:49 | ozzilee | No dispatch macro for: j ? http://pastie.caboo.se/197520 |
| 09:53 | ozzilee | I'm sure I did something dumb there, can't see it though. |
| 09:54 | rhickey | ozzilee: are you getting that error on compilation? compiles fine here for me |
| 09:55 | ozzilee | No, when I try to run it. |
| 09:55 | ozzilee | In the repl. It defines ok, but (run-cmd "ls") fails |
| 09:55 | rhickey | ls doesn't produce sexprs does it? |
| 09:55 | ozzilee | What? Nevermind it works suddenly. |
| 09:55 | ozzilee | That's weird. |
| 09:56 | ozzilee | No, now it doesn't. Let me paste the error. |
| 09:56 | rhickey | read is for reading sexprs |
| 09:57 | ozzilee | Duh. I knew that. Sorry. :-) |
| 09:57 | ozzilee | I was thinking of read-line. |
| 09:58 | ozzilee | Or something. Don't mind me, I'll just stumble along overe here... |
| 10:27 | rhickey | cgrand: do you think: |
| 10:27 | rhickey | (def-overload write [[char] int int] ...) |
| 10:27 | rhickey | is easier than: |
| 10:27 | rhickey | (defn write<char<>-int-int> ...) |
| 10:35 | rhickey | 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 | rhickey | 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: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 | rhickey | 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 | cgrand | maybe between java.sql.Date and java.lang.Date? |
| 10:45 | cgrand | I meant java.util.Date |
| 10:46 | cgrand | 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 | rhickey | I think ok to say they get the same handler fn |
| 10:48 | rhickey | right, not worth the complexity for all other situations |
| 10:54 | rhickey | 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 | cgrand | "Returns a lazy seq of the values of coll separated by sep." |
| 11:00 | cgrand | [coll sep] |
| 11:00 | cgrand | (if-let etc (rest coll) |
| 11:00 | cgrand | (cons (first coll) (lazy-cons sep (join etc sep))) |
| 11:00 | cgrand | coll)) |
| 11:00 | cgrand | (must use lisppaste...) |
| 11:03 | rhickey | (drop 1 (interleave (repeat sep) coll)) |
| 11:06 | rhickey | 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 | rhickey | 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 | ozzilee | 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 | cgrand | 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 | rhickey | 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 | rhickey | 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 | rhickey | 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 | cgrand | one error in all-sigs |
| 12:48 | cgrand | 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 | cgrand | fixes... |
| 13:07 | rhickey | ok |
| 13:15 | rhickey | 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 | rhickey | 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 | rhickey | 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 | ozzilee | 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 | rhickey | 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 | ozzilee | 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 | ozzilee | 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 | ozzilee | Hell, I'm not going to argue at all, it's not that big of a deal :-) |
| 13:46 | ozzilee | 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 | rhickey | 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 | ozzilee | 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 | rhickey | when i see -pose my mind thinks 'put' |
| 13:51 | rhickey | 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 | ozzilee | 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 | ozzilee | 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 | rhickey | 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 | rhickey | really infinite ranges... |
| 14:51 | rhickey | (range-> 0) |
| 14:51 | rhickey | bleh |
| 14:51 | cgrand | (enumerate n) ? |
| 15:00 | Chouser | rhickey: heh, thanks. |
| 15:00 | Chouser | 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 | Chouser | 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 | leafw | 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 | leafw | hope that helps. |
| 15:32 | rhickey | want to put it on the wiki? |
| 15:32 | leafw | so there is a wiki |
| 15:32 | leafw | 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 | leafw | 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 | leafw | 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 | leafw | the (if (some #{text} commands) reads very cool |
| 16:06 | leafw | but why the #{ .. } ? |
| 16:06 | rhickey | it's a set literal. Sets, like maps, are functions of their keys |
| 16:07 | rhickey | user=> (some #{3 5} [1 2 5 6 7]) |
| 16:07 | rhickey | 5 |
| 16:07 | leafw | ij.Menus.getCommands() returns a Hashtable though |
| 16:08 | leafw | also your script fails with: Unable to resolve symbol: Color in this context |
| 16:08 | leafw | 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 | rhickey | that's the Lispy variant |
| 16:15 | rhickey | I'm still on the fence about (obj.method args) |
| 16:16 | rhickey | 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 | rhickey | 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 | rhickey | 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 | leafw | that's where your pastebin example fails. |
| 16:32 | rhickey | leafw: fixed - grab the latest |
| 16:33 | leafw | ok |
| 16:33 | leafw | you mean paste bin or svn ? |
| 16:33 | leafw | 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 | leafw | 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 | leafw | I like the changes in the (.setForeground prompt \n(if ... |
| 16:45 | leafw | so (.method ...) and (. method ...) is the same? Note the white space. |
| 16:45 | leafw | 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 | leafw | 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 | leafw | 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 | leafw | 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 | ozzilee | 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. |