#clojure log - Mar 11 2008

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

7:14 hoeck: rhickey: thanks for fixing!!!

7:36 rhickey: you're welcome

9:16 MarkJP: what am I doing wrong: (ns-interns 'clojure)

9:17 rhickey: 'clojure is a symbol, ns- fns take namespaces: (ns-interns (find-ns 'clojure))

9:18 I hope to change most of these to take a ns 'designator', i.e. either the ns itself or its (symbol) name

9:18 in my spare time...

9:20 * bgeron sees the benefits of static typing here

9:21 bgeron: (because you could set up a rule on how to make a ns out of a symbol

9:22 rhickey: ew

9:22 bgeron: not nice?

9:22 rhickey: user-defined conversions ruin static typing

9:22 bgeron: depends on how it's implemented

9:22 rhickey: because you can;t control when they are used

9:23 * bgeron wants to try such static typing in a language: such a find-ns only gets namespaces, and the calling code automagically makes a ns out of the symbol (such converters are lexically scoped)

9:25 rhickey: not worth it - every feature like that adds more complexity than it reduces

9:26 see Scala

9:30 Chouser: bgeron: yeah, Scala has a complete set of features for auto-converting from types to other types.

9:31 * bgeron should really look into it then

9:31 rhickey: I meant more generally - see Scala for an example of exponential complexity of interacting features

9:31 bgeron: ah

9: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.

9:33 when its features map well to your problem, it's *very* nice, though

9:33 bgeron: but then I also think that CL's &optional shouldn't have been hardcoded

9:33 then maybe its features are too hardcoded :)

9:34 PG's (opt x) syntax looks nice

9:36 rhickey: (opt x) ?

9:36 * bgeron wants to have 50 hours in a day, so bgeron has time for such things

9:36 la_mer: this is arc, yes?

9:36 bgeron: (fn (a b (opt c)) ..)

9:36 no, it was a plan for arc

9:36 well, maybe it is real arc

9:36 * la_mer rolls his eyes in the general direction of arc :-)

9:36 bgeron: but if it's real arc, it's probably hardcoded :(

9:37 down? ;)

9:37 la_mer: I hadn't thought that far.

9:37 Chouser: I think arc has optional args without using an "opt" keyword.

9:37 * bgeron looks it up

9:38 Chouser: ...And I think I prefer clojure's mechanism for different arities on the same function.

9:38 * la_mer nods

9:39 bgeron: what's the difference?

9:40 (not meaning to imply "there is no difference")

9:40 Chouser: The difference in how clojure does it?

9:40 bgeron: yes

9:41 Chouser: I think boot.clj's "reduce" function is a good example.

9:41 It takes 2 or 3 args: either [f coll] or [f val coll]

9:41 bgeron: blegh, arc does optional args with (o arg [default])

9:41 rhickey: fyi Clojure used to have full CL &optional &keys and &rest

9:42 bgeron: casing on different lengths is nice :)

9:42 rhickey: and each fn was a single entry point, which dealt with that stuff

9:43 la_mer: rhickey: that was dropped to align more closely with java's function call mechanics, yes?

9: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

9:43 rhickey: now each entry point is distinct - IFn has 20+ overloads

9:44 doing it this way is very much faster - esp when & comes into play

9: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. ;-)

9:44 rhickey: compare to other JVM langs which pack args into Object[]

9:44 Clojure uses real stack

9:46 Chouser's example is good too, real overloading is not the same as optional

9:47 Chouser: I must admit I have to beat down an occasional yearning for type-based overloading.

9:47 rhickey: multimethods

9:48 Chouser: oh!

9:48 hm, how did I forget about those.

10:05 * bgeron hates himself

10:06 Chouser: aww... why's that?

10:06 * bgeron has two health insurances for the rest of this year

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 (because if there would be no new board, the association would get disbanded)

10:08 maybe secretary would have been a better position for me

12:07 nsinghal: (def aa (fn [] :ns))

12:07 (aa) returns :ns

12:07 (def bb #(:ns))

12:07 (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 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 but I can add predicates for all the marker interfaces

12:31 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 Are those names currently documented anywhere?

12:32 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 sorry, I forgot the question mark

12:44 MarkJP: cool

12:46 so lets say I proxy class Foo

12:47 (proxy [Foo] [] (method1 [] ... ) (method2 []...))

12:48 the resultant object doesnt seem to pass the (instance? Foo o) test

12:49 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 interesting, it passes the instance? test for another proxy i did

12:54 I'm doing something wrong

13:00 rhickey: proxy should pass instance? for all of its supers

13:01 MarkJP: oh man

13:01 it works now

13:01 rhickey: gremlins

13:02 MarkJP: wow... don't do this:

13:02 (import '(clojure.lang.RT) '(clojure.lang.Var)) in clojure

13:02 :p

13:02 proxy wasnt working

13:03 I was able to make up methods within proxy without complaint

13:04 those imports where not intentional, cut and paste from java code

13:06 Chouser: extensive? really? http://n01se.net/paste/hV0

13:06 that's a quick pass. probably a little buggy.

13:06 not to mention ugly.

13:06 MarkJP: cool, how did you generate that?

13:07 Chouser: heh. well...

13:08 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 have to put it up on my wall so I can remember my design :)

13:40 missing a few things, though

14:18 Chouser: oh, is it? well, I think a hand-created one will look better anyway.

14:18 What's missing?

14:19 rhickey: IPersistentVector extends Associative, Sequential, IPersistentStack, Reversible

14:20 IPersistentMap extends Iterable, Associative

14:20 etc, all like that

14:21 the nice thing about a generated one is you don't have to maintain it

14:21 just regen

14:22 Chouser: yeah, but it's ugly.

14:22 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 hm. Well, maybe I'll try to refine the autogen process a bit then.

14:24 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 er, "can it import"...?

14:26 rhickey: got me, looking now

14:26 says a subset

14:27 Chouser: hm.

16:05 MarkJP: how do I do (new Foo.SubFoo ...)

16:05 ?

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 this works: (new javax.swing.ImageIcon "/tmp/tmp.png")

16:47 this doesn't: (new javax.swing.ImageIcon (. (slurp "/tmp/tmp.png") (getBytes)))

16:48 An ImageIcon object is created, but it doesn't display anything.

17:00 (int (first (slurp "/tmp/tmp.png"))) ==> 65533 ...but how could the first byte be larger than 255?

17:05 hoeck: unicode?

17:06 (slurp ) returns a string

17:08 Chouser: yeah. I thought of that, but that doesn't seem to be it.

17:08 oh!

17:09 well, it's not 2-byte unicode. Maybe it thinks it's utf-8 or something.

17:12 UTF8 it is.

17:14 drat. forcing US-ASCII isn't helping.

17:15 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 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 bye

19:59 Chouser: generate dot script from Clojure Java source: http://n01se.net/paste/yW2

20:02 resulting dot script: http://n01se.net/paste/WL7S

20:07 resulting png (updated): http://n01se.net/paste/yVa

Logging service provided by n01se.net