#clojure logs

2008-05-13

07:36rhickeyesquesque: just saw you comment re: :tag on maps, you can apply :tag to maps, it's just not used by the compiler for any purpose:
07:37rhickeyuser=> (def m #^:Tag {:a 1 :b 2})
07:37rhickey#'user/m
07:37rhickeyuser=> (meta m)
07:37rhickey{:tag :Tag}
10:23Chouserozzilee: clojure's reduce takes an optional "starting" value that may do what you want (for fold)
10:24ozzileeChouser: I did not see that. Thank you.
10:24ozzileeThat is indeed what I was looking for.
10:53asbjxrnI have some trouble creating a Ellipse2D.float object.
10:56asbjxrnI've (import '(java.awt.geom Ellipse2D))
10:56esquesque_is it a subclass?
10:56asbjxrnIt's an inner class of Ellipse2D.
10:56esquesque_ech that is what i meant =P
10:56esquesque_maybe you would try:
10:57esquesque_(import '(java.awt.geom.Ellipse2D float))
10:58asbjxrnClassNotFoundException.
10:58esquesque_hmmm, what does your (new ...) look like?
10:59asbjxrnI've tried (new Ellipse2D.Float).
10:59asbjxrnDoesn't work, though.
10:59rhickeyjava.awt.geom.Ellipse2D$Float
11:00asbjxrnOh.
11:00rhickeyThat's the real Java name for a nested class
11:00esquesque_d'oh
11:01asbjxrnSeems to do the trick.
11:01asbjxrnthanks.
11:03asbjxrnDo you know the reason it's this way? (And the java doc only mentions Ellipse2D.Float as a constructor.)
11:03esquesque_they compile that way
11:04rhickeyit's a jvm thing, nested classes aren't really nested, so there is some name munging that occurs
11:04asbjxrnAh, so that is the name in the bytecode,
11:04rhickeyand the class files
11:04asbjxrnRight. I must admit I don't know the difference :)
11:05asbjxrnJava -> parser -> class file -> compiler -> jar/bytecode ?
11:06asbjxrnNah. The code goes through the compiler to transform into a class file, doesn't it?
11:06rhickeythe class files contain bytecode, my point was that naming is used for the class files themselves, as well as for references within the bytecode
11:06asbjxrnAh, I see.
11:06rhickeye.g. Ellipse2D$Float.class
11:07esquesque_i've done alot of work with bytecode
11:07esquesque_it's an irritating format
11:07rhickeydid you use ASM?
11:07esquesque_asm and bcel
11:08esquesque_i don't like asm's visitor pattern too much
11:09rhickeyI find ASM pretty easy, but ignore the visitor pattern (only doing code gen)
11:09esquesque_i made my own bc lib in java that never really got finished
11:09esquesque_so i know the format very well
11:09esquesque_the attribute model wasn't very well thought out
11:10rhickeyit has its quirks, but you have to give them props for stability
11:10asbjxrnAn agent can be a ref, but is that a good Idea?
11:13asbjxrnSince the agent is supposed to "guard" a place/state, but the ref is really a pointer to state?
11:13rhickeyasbjxrn: you mean the state of an agent be a ref? I'd wonder why
11:13rhickeyan agent's state can change - do you want to change it to a different ref at some point?
11:14esquesque_rhickey: when using proxy, is "super" bound?
11:14rhickeyesquesque: no, there is no access to super from a proxy
11:14asbjxrnI've got a JPanel, and want to have some environment for it. Among other things, a list of functions that draws into the panel and a framerate.
11:15rhickeyseems like a straight ref would work
11:15esquesque_is there any other function that gives me access to super?
11:16asbjxrnI was trying to put the JPanel in a closure, so when I trigger repaint, it can pass the environment to the render function. But for the framerate, the agent would need to know how long to sleep before retriggering.
11:16rhickeyesquesque: the new gen-class stuff has more power to access the superclass
11:16asbjxrnAnd I want the functions in the functionlist to be able to change the framerate.
11:18esquesque_gen-class?
11:18dudleyfrhickey: gen-class? Is that something for creating Java classes from Lisp?
11:18rhickeyasbjxrn: a ref will allow for coordinated access from multiple threads. That's orthogonal to how you might use scope to make it visible
11:19rhickeydudleyf: yes, relatively new in SVN. load genclass.clj and (doc gen-class)
11:19asbjxrnYes, I don't think I need to access from more than one thread.
11:20rhickeyasbjxrn: then you can use vars
11:20asbjxrnI'm struggling with this immutability-concept, and using a ref and rebinding it is the way I managed to keep state.
11:20rhickeyasbjxrn: refs are fine
11:21asbjxrnalter works on refs, for var I would use set! ? (I haven't looked at vars yet...)
11:22rhickeyyes, you'd set! a var
11:23rhickeyasbjxrn: I don't advocate changing if you've got refs working
11:23asbjxrnIt's not much code yet, and I'm just writing this code to learn... Don't worry.
11:24asbjxrnIt's not a real project.
14:52Chouserhm, it's a pity I have to say (filter #(.isDirectory %) files) instead of just (filter .isDirectory files)
14:55rhickeyyeah
14:57Chouserheh. does it bug you when people say things like that, implying that *you* ought to spend a few hours adding a feature so that *I* can save 5 keystrokes?
14:57rhickey:)
14:57rhickeyfirst-class-izing is something I've thought a bit about
14:58rhickeyas you might imagine
14:59rhickeythere is memfn, which has the drawback of requiring args be explicit
15:00rhickeyand now, not shorter than #()
15:00Chouserah, hadn't seen memfn
15:01rhickeypredates #()
15:01Chouserok
15:16rhickey(defn jcall [obj name & args]
15:16rhickey (clojure.lang.Reflector.invokeInstanceMethod
15:16rhickey obj
15:16rhickey (str name)
15:16rhickey (if args (to-array args) (clojure.lang.RT.EMPTY_ARRAY))))
15:16rhickey(defn jfn [name]
15:16rhickey #(apply jcall %1 name %&))
15:16rhickey((jfn 'substring) "fred" 2 3)
15:16rhickey((jfn 'toupperCase) "fred")
15:17rhickeyjust a reader macro away from #.isDirectory => (jfn 'isDirectory)
15:34Chouserso would there be any reason to not have .foo always decome (jfn 'foo) ?
15:36Chousers/decome/become/
15:37rhickeyRight now .foo is a symbol. It gets macroexpanded in the operator position, but not otherwise. There are no symbol macros at this time
15:41ozzileeI have to say, coming from scheme, Clojure sure seems to have a lot of magic in it.
15:42ozzileeOf course, scheme doesn't interact with Java, either :-)
15:42rhickeyexactly, most of the magic is there, and most of it is also based on standard reader/macro techniques
15:43rhickeyat least standard CL techniques
15:43rhickey:)
15:43rhickeyi.e. its not syntax, still data structures
15:44rhickeyClojure tends to be less verbose than the equivalent Scheme/CL
15:47ozzileeI think my clojure is outdated. Should (.count []) return zero?
15:48ozzilee(. [] (count)) works.
15:48rhickey(count [])
15:48rhickey?
15:49ozzileeWell, yeah, that. I mean calling java functions with the .foo syntax.
15:49rhickeyah, then yes, 0
15:50ozzileeOk, mine freaks out. Must be old.
15:50rhickeyyeah, (.member obj ...) is relatively new
15:51ozzileeIt freaked me out the first time I saw it. I'm still not sure what I think of it. Looks funny to me.
15:51ozzileeThe ... is the arglist?
15:52rhickeysome consider it more Lispy, yes, args follow object
15:52rhickey(obj.member ...) also works
15:52ozzileeOh, now that's way better, if you ask me.
15:52ozzileeSo ([].count) would work?
15:54rhickeyno, it's not syntax - obj.member is a single symbol that gets macroexpanded, [].count is a vector followed by the symbol .count
15:54rhickeyStill sexprs
15:54rhickeyjust symbols containing '.' are macros, effectively
15:55ozzileeAh.
15:55ozzileeIs there a nightly build, or should I checkout trunk and compile?
15:56rhickeyjust checkout trunk
15:56rhickeyant
15:56rhickeyor maven
15:57ozzileeOk. I'll play with that tonight maybe. I'm going to look at possibly writing a wrapper for prefuse.
16:13Chouserrhickey: I guess I was just thinking a reader macro for .foo instead of #.foo
16:13Chousernot all reader macros start with #, right?
16:14rhickeyright, the thing would be, reader macros happen on read, so (.foo x) would read as ((jfn 'foo) x)
16:15Chouserright.
16:15rhickeywhile functionally equivalent, jfn is a lot slower - always reflective
16:16rhickeyI wouldn't want that for (.foo x)
16:16Chouserah, ok. That was the kind of reason I was looking for. ;-)
16:18rhickeyso something would have to be 'special', either reinterpreting (jfn ...) when it appears in the operator position or .foo in a value context. I'd prefer the latter, but there is nothing else special like that, yet
16:18ozzileeIsn't .foo special like that, since it only gets interpreted when it's in the operator position?
16:18rhickeyspecial things mean greater complexity
16:19rhickey.foo is a macro, people can see its effects using macroexpand
16:19rhickeyuser=> (macroexpand '(.foo x))
16:19rhickey(. x foo)
16:21ChouserI think as it stands is entirely reasonable. It's not like #(.foo %) is hard to say, and if I want to give a type hint I know just how to do it.
21:05abrooksrhickey: I'm creating a "Finding Clojure" group on Facebook, is it okay to use the Clojure Google Group logo for that? Who has rights on the logo? How is it licensed?
21:08rhickeyI own the logo. You can use it to represent the Clojure language that I wrote.
21:08rhickeythere's no fancy license
21:08abrooksrhickey: Thanks. :) Is there a larger source image that I should start from?
21:09rhickeyhow big will it end up?
21:09abrooksrhickey: Well, technically copyright exists whether we acknowledge it or not. :)
21:09rhickeyI understand
21:09abrooksrhickey: 200x200 perhaps. It might be okay smaller but 200x200 would be better, I think.
21:11rhickeyhttp://clojure.googlegroups.com/web/Clojure_300x300.png
21:12abrooksAh, perfect. Thanks.
21:13rhickeyis there a url for the FaceBook group?
21:16abrooksThere is now: http://www.facebook.com/group.php?gid=13489774164
21:17abrooksI don't think it's visible outside of a Facebook login.
21:22abrooksdrewr has apparently joined the group already. ;-)
21:27abrooksrhickey: I saw that you joined and added you as an admin.
21:28rhickeyok
21:36drewrabrooks: :-)
21:56esquesque_hi rhickey, how would i do load-file and keep all the bindings?
21:56esquesque_i do (load-file "genclass.clj") and gen-class is still unbound
21:57rhickeyheading home now, maybe someone else can help, please?
21:57esquesque_i'm not picky :)
22:10esquesque_nevermind, i've got it sorted out
22:11esquesque_(in-ns 'clojure) gen-class