2008-03-13
| 07:14 | hoeck | rhickey: thanks for fixing!!! |
| 07:36 | rhickey | you're welcome |
| 09:16 | MarkJP | what am I doing wrong: (ns-interns 'clojure) |
| 09:17 | rhickey | 'clojure is a symbol, ns- fns take namespaces: (ns-interns (find-ns 'clojure)) |
| 09:18 | rhickey | I hope to change most of these to take a ns 'designator', i.e. either the ns itself or its (symbol) name |
| 09:18 | rhickey | in my spare time... |
| 09:21 | bgeron | (because you could set up a rule on how to make a ns out of a symbol |
| 09:22 | rhickey | ew |
| 09:22 | bgeron | not nice? |
| 09:22 | rhickey | user-defined conversions ruin static typing |
| 09:22 | bgeron | depends on how it's implemented |
| 09:22 | rhickey | because you can;t control when they are used |
| 09:25 | rhickey | not worth it - every feature like that adds more complexity than it reduces |
| 09:26 | rhickey | see Scala |
| 09:30 | Chouser | bgeron: yeah, Scala has a complete set of features for auto-converting from types to other types. |
| 09:31 | rhickey | I meant more generally - see Scala for an example of exponential complexity of interacting features |
| 09:31 | bgeron | ah |
| 09:33 | la_mer | bgeron: we use Scala for a real product (which stuns people sometimes) -- it's definitely got a 45-piece Craftsman set of tools, but one often finds that the set is missing simple screwdrivers, etc. |
| 09:33 | la_mer | when its features map well to your problem, it's *very* nice, though |
| 09:33 | bgeron | but then I also think that CL's &optional shouldn't have been hardcoded |
| 09:33 | bgeron | then maybe its features are too hardcoded :) |
| 09:34 | bgeron | PG's (opt x) syntax looks nice |
| 09:36 | rhickey | (opt x) ? |
| 09:36 | la_mer | this is arc, yes? |
| 09:36 | bgeron | (fn (a b (opt c)) ..) |
| 09:36 | bgeron | no, it was a plan for arc |
| 09:36 | bgeron | well, maybe it is real arc |
| 09:36 | bgeron | but if it's real arc, it's probably hardcoded :( |
| 09:37 | bgeron | down? ;) |
| 09:37 | la_mer | I hadn't thought that far. |
| 09:37 | Chouser | I think arc has optional args without using an "opt" keyword. |
| 09:38 | Chouser | ...And I think I prefer clojure's mechanism for different arities on the same function. |
| 09:39 | bgeron | what's the difference? |
| 09:40 | bgeron | (not meaning to imply "there is no difference") |
| 09:40 | Chouser | The difference in how clojure does it? |
| 09:40 | bgeron | yes |
| 09:41 | Chouser | I think boot.clj's "reduce" function is a good example. |
| 09:41 | Chouser | It takes 2 or 3 args: either [f coll] or [f val coll] |
| 09:41 | bgeron | blegh, arc does optional args with (o arg [default]) |
| 09:41 | rhickey | fyi Clojure used to have full CL &optional &keys and &rest |
| 09:42 | bgeron | casing on different lengths is nice :) |
| 09:42 | rhickey | and each fn was a single entry point, which dealt with that stuff |
| 09:43 | la_mer | rhickey: that was dropped to align more closely with java's function call mechanics, yes? |
| 09:43 | Chouser | So val is optional, but its in the middle. To do that with a single list of formal args (like CL, JavaScript, arc, etc.) you'd have to use something like [f coll-or-val (optional coll)] and then monkey around in the function body to get the correct coll |
| 09:43 | rhickey | now each entry point is distinct - IFn has 20+ overloads |
| 09:44 | rhickey | doing it this way is very much faster - esp when & comes into play |
| 09:44 | Chouser | I've started peeking at the Clojure Java code. I'm so glad rhickey wrote that kind of painful code so I don't have to. ;-) |
| 09:44 | rhickey | compare to other JVM langs which pack args into Object[] |
| 09:44 | rhickey | Clojure uses real stack |
| 09:46 | rhickey | Chouser's example is good too, real overloading is not the same as optional |
| 09:47 | Chouser | I must admit I have to beat down an occasional yearning for type-based overloading. |
| 09:47 | rhickey | multimethods |
| 09:48 | Chouser | oh! |
| 09:48 | Chouser | hm, how did I forget about those. |
| 10:06 | Chouser | aww... why's that? |
| 10:06 | bgeron | pretty pricey |
| 10:06 | Chouser | I bet. |
| 10:07 | bgeron | and I'm supposed to become the treasurer of an association this evening :p |
| 10:07 | bgeron | (because if there would be no new board, the association would get disbanded) |
| 10:08 | bgeron | maybe secretary would have been a better position for me |
| 12:07 | nsinghal | (def aa (fn [] :ns)) |
| 12:07 | nsinghal | (aa) returns :ns |
| 12:07 | nsinghal | (def bb #(:ns)) |
| 12:07 | nsinghal | (bb) throws Arity error |
| 12:09 | rhickey | #(...) => (fn [args] (...)) so #(:ns) => (fn [] (:ns)) |
| 12:09 | nsinghal | (def cc #(:ns %)) |
| 12:10 | rhickey | in the latest version error would be: |
| 12:10 | rhickey | java.lang.IllegalArgumentException: Wrong number of args passed to keyword: :ns |
| 12:11 | nsinghal | thanks that explains it |
| 12:13 | Chouser | rhickey: great update to the error message, by the way. Bound to be helpful. |
| 12:14 | rhickey | :) |
| 12:26 | Chouser | what do you think of: (defn coll? [x] (or (seq? x) (vector? x) (map? x) (set? x))) |
| 12:27 | rhickey | (instance? IPersistentCollection x) |
| 12:29 | Chouser | hm! Well, I can't be sure, but I suspect that when people are asking for something that says if an object is "seq-able" (and you rightly point out that (seq "foo") works and isn't what they want) ... what they may really want is coll? |
| 12:30 | rhickey | sometimes - that fact that it includes maps may not be what they intend - There's also Sequential |
| 12:31 | rhickey | but I can add predicates for all the marker interfaces |
| 12:31 | rhickey | IPersistentCollection, Sequential, Reversible, Associative etc |
| 12:32 | Chouser | you may be right -- it's hard to tell. Most place where I'm doing something like seq? I mainly want to know if I should recurse into it or not. So true for maps and other collections, false for strings, keywords, symbols. |
| 12:32 | Chouser | Are those names currently documented anywhere? |
| 12:32 | Chouser | Docs may be sufficient, and then you don't have to clutter up the clojure namespace with a bunch of new predicates. |
| 12:33 | rhickey | unfortunately I still haven't gotten around to documenting the Java side - which is quite extensive |
| 12:33 | Chouser | ok |
| 12:43 | MarkJP | what is the equivalent of instanceof in clojure |
| 12:44 | Chouser | instance |
| 12:44 | MarkJP | thx |
| 12:44 | Chouser | (instance? Classname obj) |
| 12:44 | Chouser | sorry, I forgot the question mark |
| 12:44 | MarkJP | cool |
| 12:46 | MarkJP | so lets say I proxy class Foo |
| 12:47 | MarkJP | (proxy [Foo] [] (method1 [] ... ) (method2 []...)) |
| 12:48 | MarkJP | the resultant object doesnt seem to pass the (instance? Foo o) test |
| 12:49 | MarkJP | actually sorry, Foo is an interface in this case |
| 12:50 | Chouser | Well, you've just surpassed my knowledge. :-/ sorry. |
| 12:52 | MarkJP | np, I'll wait for Rich, he seems to know Clojure pretty well |
| 12:54 | MarkJP | interesting, it passes the instance? test for another proxy i did |
| 12:54 | MarkJP | I'm doing something wrong |
| 13:00 | rhickey | proxy should pass instance? for all of its supers |
| 13:01 | MarkJP | oh man |
| 13:01 | MarkJP | it works now |
| 13:01 | rhickey | gremlins |
| 13:02 | MarkJP | wow... don't do this: |
| 13:02 | MarkJP | (import '(clojure.lang.RT) '(clojure.lang.Var)) in clojure |
| 13:02 | MarkJP | :p |
| 13:02 | MarkJP | proxy wasnt working |
| 13:03 | MarkJP | I was able to make up methods within proxy without complaint |
| 13:04 | MarkJP | those imports where not intentional, cut and paste from java code |
| 13:06 | Chouser | extensive? really? http://n01se.net/paste/hV0 |
| 13:06 | Chouser | that's a quick pass. probably a little buggy. |
| 13:06 | Chouser | not to mention ugly. |
| 13:06 | MarkJP | cool, how did you generate that? |
| 13:07 | Chouser | heh. well... |
| 13:08 | Chouser | a little perl, a little bash, and graphviz's "dot" command: http://n01se.net/paste/o9V |
| 13:09 | MarkJP | cool |
| 13:09 | Chouser | I think the word you're looking for is "gross", but I'll take "cool". ;-) |
| 13:11 | MarkJP | nah, definitely a neat one liner |
| 13:34 | rhickey | Chouser: wow - what a fun graph! |
| 13:35 | rhickey | have to put it up on my wall so I can remember my design :) |
| 13:40 | rhickey | missing a few things, though |
| 14:18 | Chouser | oh, is it? well, I think a hand-created one will look better anyway. |
| 14:18 | Chouser | What's missing? |
| 14:19 | rhickey | IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible |
| 14:20 | rhickey | IPersistentMap extends Iterable, Associative |
| 14:20 | rhickey | etc, all like that |
| 14:21 | rhickey | the nice thing about a generated one is you don't have to maintain it |
| 14:21 | rhickey | just regen |
| 14:22 | Chouser | yeah, but it's ugly. |
| 14:22 | Chouser | I have long wished for some tool that combines the best of both, but I don't know of any such beast. |
| 14:23 | rhickey | as long as you can follow the paths, it has great utility even if not beautiful |
| 14:23 | Chouser | Like have a script generate SVG. Then edit the SVG in inkscape. Then have the script read new graph data *and* the SVG and make minimal changes to update any edges and nodes that have changed |
| 14:24 | Chouser | hm. Well, maybe I'll try to refine the autogen process a bit then. |
| 14:24 | Chouser | dot can be a little prettier, I think. |
| 14:24 | rhickey | I have OmniGraffle - if you can get it into a form it can import, it can make it pretty |
| 14:25 | Chouser | I've not seen OmniGraffle. Looks pretty. The front page says it has Graphviz built in... and it import dot scripts? |
| 14:25 | Chouser | er, "can it import"...? |
| 14:26 | rhickey | got me, looking now |
| 14:26 | rhickey | says a subset |
| 14:27 | Chouser | hm. |
| 16:05 | MarkJP | how do I do (new Foo.SubFoo ...) |
| 16:05 | MarkJP | ? |
| 16:06 | rhickey | nested classes are separated by $ from their parents (a JVM thing): Foo$SubFoo |
| 16:07 | MarkJP | thx |
| 16:20 | Chouser | any easy way to convert a String to a java byte array? |
| 16:21 | rhickey | (. s (getBytes)) |
| 16:21 | Chouser | oh. :-) right, thanks. |
| 16:47 | Chouser | this works: (new javax.swing.ImageIcon "/tmp/tmp.png") |
| 16:47 | Chouser | this doesn't: (new javax.swing.ImageIcon (. (slurp "/tmp/tmp.png") (getBytes))) |
| 16:48 | Chouser | An ImageIcon object is created, but it doesn't display anything. |
| 17:00 | Chouser | (int (first (slurp "/tmp/tmp.png"))) ==> 65533 ...but how could the first byte be larger than 255? |
| 17:05 | hoeck | unicode? |
| 17:06 | hoeck | (slurp ) returns a string |
| 17:08 | Chouser | yeah. I thought of that, but that doesn't seem to be it. |
| 17:08 | Chouser | oh! |
| 17:09 | Chouser | well, it's not 2-byte unicode. Maybe it thinks it's utf-8 or something. |
| 17:12 | Chouser | UTF8 it is. |
| 17:14 | Chouser | drat. forcing US-ASCII isn't helping. |
| 17:15 | Chouser | Oh, that's 7-bit. ISO-8859-1 does it. |
| 17:23 | hoeck | maybe it needs the magic number from the beginning of the image be stripped off? |
| 17:24 | hoeck | or the actual image-data begins at an certain offset in the image file |
| 17:27 | Chouser | no, you were right. It was just unicode. |
| 17:27 | hoeck | oh, ok |
| 17:28 | Chouser | If I create the InputStreamReader with ISO-8859-1, and write the bytes into ByteArrayOutputStream, I can do toByteArray and the icon works fine. |
| 17:31 | hoeck | mhh, i'm wondering wether one could directly read data from /dev/video using this method |
| 17:49 | hoeck | bye |
| 19:59 | Chouser | generate dot script from Clojure Java source: http://n01se.net/paste/yW2 |
| 20:02 | Chouser | resulting dot script: http://n01se.net/paste/WL7S |
| 20:07 | Chouser | resulting png (updated): http://n01se.net/paste/yVa |