#clojure logs

2008-03-13

07:14hoeckrhickey: thanks for fixing!!!
07:36rhickeyyou're welcome
09:16MarkJPwhat am I doing wrong: (ns-interns 'clojure)
09:17rhickey'clojure is a symbol, ns- fns take namespaces: (ns-interns (find-ns 'clojure))
09:18rhickeyI hope to change most of these to take a ns 'designator', i.e. either the ns itself or its (symbol) name
09:18rhickeyin my spare time...
09:21bgeron(because you could set up a rule on how to make a ns out of a symbol
09:22rhickeyew
09:22bgeronnot nice?
09:22rhickeyuser-defined conversions ruin static typing
09:22bgerondepends on how it's implemented
09:22rhickeybecause you can;t control when they are used
09:25rhickeynot worth it - every feature like that adds more complexity than it reduces
09:26rhickeysee Scala
09:30Chouserbgeron: yeah, Scala has a complete set of features for auto-converting from types to other types.
09:31rhickeyI meant more generally - see Scala for an example of exponential complexity of interacting features
09:31bgeronah
09:33la_merbgeron: 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:33la_merwhen its features map well to your problem, it's *very* nice, though
09:33bgeronbut then I also think that CL's &optional shouldn't have been hardcoded
09:33bgeronthen maybe its features are too hardcoded :)
09:34bgeronPG's (opt x) syntax looks nice
09:36rhickey(opt x) ?
09:36la_merthis is arc, yes?
09:36bgeron(fn (a b (opt c)) ..)
09:36bgeronno, it was a plan for arc
09:36bgeronwell, maybe it is real arc
09:36bgeronbut if it's real arc, it's probably hardcoded :(
09:37bgerondown? ;)
09:37la_merI hadn't thought that far.
09:37ChouserI think arc has optional args without using an "opt" keyword.
09:38Chouser...And I think I prefer clojure's mechanism for different arities on the same function.
09:39bgeronwhat's the difference?
09:40bgeron(not meaning to imply "there is no difference")
09:40ChouserThe difference in how clojure does it?
09:40bgeronyes
09:41ChouserI think boot.clj's "reduce" function is a good example.
09:41ChouserIt takes 2 or 3 args: either [f coll] or [f val coll]
09:41bgeronblegh, arc does optional args with (o arg [default])
09:41rhickeyfyi Clojure used to have full CL &optional &keys and &rest
09:42bgeroncasing on different lengths is nice :)
09:42rhickeyand each fn was a single entry point, which dealt with that stuff
09:43la_merrhickey: that was dropped to align more closely with java's function call mechanics, yes?
09:43ChouserSo 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:43rhickeynow each entry point is distinct - IFn has 20+ overloads
09:44rhickeydoing it this way is very much faster - esp when & comes into play
09:44ChouserI'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:44rhickeycompare to other JVM langs which pack args into Object[]
09:44rhickeyClojure uses real stack
09:46rhickeyChouser's example is good too, real overloading is not the same as optional
09:47ChouserI must admit I have to beat down an occasional yearning for type-based overloading.
09:47rhickeymultimethods
09:48Chouseroh!
09:48Chouserhm, how did I forget about those.
10:06Chouseraww... why's that?
10:06bgeronpretty pricey
10:06ChouserI bet.
10:07bgeronand I'm supposed to become the treasurer of an association this evening :p
10:07bgeron(because if there would be no new board, the association would get disbanded)
10:08bgeronmaybe secretary would have been a better position for me
12:07nsinghal(def aa (fn [] :ns))
12:07nsinghal(aa) returns :ns
12:07nsinghal(def bb #(:ns))
12:07nsinghal(bb) throws Arity error
12:09rhickey#(...) => (fn [args] (...)) so #(:ns) => (fn [] (:ns))
12:09nsinghal(def cc #(:ns %))
12:10rhickeyin the latest version error would be:
12:10rhickeyjava.lang.IllegalArgumentException: Wrong number of args passed to keyword: :ns
12:11nsinghalthanks that explains it
12:13Chouserrhickey: great update to the error message, by the way. Bound to be helpful.
12:14rhickey:)
12:26Chouserwhat do you think of: (defn coll? [x] (or (seq? x) (vector? x) (map? x) (set? x)))
12:27rhickey(instance? IPersistentCollection x)
12:29Chouserhm! 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:30rhickeysometimes - that fact that it includes maps may not be what they intend - There's also Sequential
12:31rhickeybut I can add predicates for all the marker interfaces
12:31rhickeyIPersistentCollection, Sequential, Reversible, Associative etc
12:32Chouseryou 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:32ChouserAre those names currently documented anywhere?
12:32ChouserDocs may be sufficient, and then you don't have to clutter up the clojure namespace with a bunch of new predicates.
12:33rhickeyunfortunately I still haven't gotten around to documenting the Java side - which is quite extensive
12:33Chouserok
12:43MarkJPwhat is the equivalent of instanceof in clojure
12:44Chouserinstance
12:44MarkJPthx
12:44Chouser(instance? Classname obj)
12:44Chousersorry, I forgot the question mark
12:44MarkJPcool
12:46MarkJPso lets say I proxy class Foo
12:47MarkJP(proxy [Foo] [] (method1 [] ... ) (method2 []...))
12:48MarkJPthe resultant object doesnt seem to pass the (instance? Foo o) test
12:49MarkJPactually sorry, Foo is an interface in this case
12:50ChouserWell, you've just surpassed my knowledge. :-/ sorry.
12:52MarkJPnp, I'll wait for Rich, he seems to know Clojure pretty well
12:54MarkJPinteresting, it passes the instance? test for another proxy i did
12:54MarkJPI'm doing something wrong
13:00rhickeyproxy should pass instance? for all of its supers
13:01MarkJPoh man
13:01MarkJPit works now
13:01rhickeygremlins
13:02MarkJPwow... don't do this:
13:02MarkJP(import '(clojure.lang.RT) '(clojure.lang.Var)) in clojure
13:02MarkJP:p
13:02MarkJPproxy wasnt working
13:03MarkJPI was able to make up methods within proxy without complaint
13:04MarkJPthose imports where not intentional, cut and paste from java code
13:06Chouserextensive? really? http://n01se.net/paste/hV0
13:06Chouserthat's a quick pass. probably a little buggy.
13:06Chousernot to mention ugly.
13:06MarkJPcool, how did you generate that?
13:07Chouserheh. well...
13:08Chousera little perl, a little bash, and graphviz's "dot" command: http://n01se.net/paste/o9V
13:09MarkJPcool
13:09ChouserI think the word you're looking for is "gross", but I'll take "cool". ;-)
13:11MarkJPnah, definitely a neat one liner
13:34rhickeyChouser: wow - what a fun graph!
13:35rhickeyhave to put it up on my wall so I can remember my design :)
13:40rhickeymissing a few things, though
14:18Chouseroh, is it? well, I think a hand-created one will look better anyway.
14:18ChouserWhat's missing?
14:19rhickeyIPersistentVector extends Associative, Sequential, IPersistentStack, Reversible
14:20rhickeyIPersistentMap extends Iterable, Associative
14:20rhickeyetc, all like that
14:21rhickeythe nice thing about a generated one is you don't have to maintain it
14:21rhickeyjust regen
14:22Chouseryeah, but it's ugly.
14:22ChouserI have long wished for some tool that combines the best of both, but I don't know of any such beast.
14:23rhickeyas long as you can follow the paths, it has great utility even if not beautiful
14:23ChouserLike 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:24Chouserhm. Well, maybe I'll try to refine the autogen process a bit then.
14:24Chouserdot can be a little prettier, I think.
14:24rhickeyI have OmniGraffle - if you can get it into a form it can import, it can make it pretty
14:25ChouserI've not seen OmniGraffle. Looks pretty. The front page says it has Graphviz built in... and it import dot scripts?
14:25Chouserer, "can it import"...?
14:26rhickeygot me, looking now
14:26rhickeysays a subset
14:27Chouserhm.
16:05MarkJPhow do I do (new Foo.SubFoo ...)
16:05MarkJP?
16:06rhickeynested classes are separated by $ from their parents (a JVM thing): Foo$SubFoo
16:07MarkJPthx
16:20Chouserany easy way to convert a String to a java byte array?
16:21rhickey(. s (getBytes))
16:21Chouseroh. :-) right, thanks.
16:47Chouserthis works: (new javax.swing.ImageIcon "/tmp/tmp.png")
16:47Chouserthis doesn't: (new javax.swing.ImageIcon (. (slurp "/tmp/tmp.png") (getBytes)))
16:48ChouserAn ImageIcon object is created, but it doesn't display anything.
17:00Chouser(int (first (slurp "/tmp/tmp.png"))) ==> 65533 ...but how could the first byte be larger than 255?
17:05hoeckunicode?
17:06hoeck(slurp ) returns a string
17:08Chouseryeah. I thought of that, but that doesn't seem to be it.
17:08Chouseroh!
17:09Chouserwell, it's not 2-byte unicode. Maybe it thinks it's utf-8 or something.
17:12ChouserUTF8 it is.
17:14Chouserdrat. forcing US-ASCII isn't helping.
17:15ChouserOh, that's 7-bit. ISO-8859-1 does it.
17:23hoeckmaybe it needs the magic number from the beginning of the image be stripped off?
17:24hoeckor the actual image-data begins at an certain offset in the image file
17:27Chouserno, you were right. It was just unicode.
17:27hoeckoh, ok
17:28ChouserIf I create the InputStreamReader with ISO-8859-1, and write the bytes into ByteArrayOutputStream, I can do toByteArray and the icon works fine.
17:31hoeckmhh, i'm wondering wether one could directly read data from /dev/video using this method
17:49hoeckbye
19:59Chousergenerate dot script from Clojure Java source: http://n01se.net/paste/yW2
20:02Chouserresulting dot script: http://n01se.net/paste/WL7S
20:07Chouserresulting png (updated): http://n01se.net/paste/yVa