#clojure log - May 13 2008

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

7:36 rhickey: esquesque: 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:

7:37 user=> (def m #^:Tag {:a 1 :b 2})

7:37 #'user/m

7:37 user=> (meta m)

7:37 {:tag :Tag}

10:23 Chouser: ozzilee: clojure's reduce takes an optional "starting" value that may do what you want (for fold)

10:24 ozzilee: Chouser: I did not see that. Thank you.

10:24 That is indeed what I was looking for.

10:53 asbjxrn: I have some trouble creating a Ellipse2D.float object.

10:56 I've (import '(java.awt.geom Ellipse2D))

10:56 esquesque_: is it a subclass?

10:56 asbjxrn: It's an inner class of Ellipse2D.

10:56 esquesque_: ech that is what i meant =P

10:56 maybe you would try:

10:57 (import '(java.awt.geom.Ellipse2D float))

10:58 asbjxrn: ClassNotFoundException.

10:58 esquesque_: hmmm, what does your (new ...) look like?

10:59 asbjxrn: I've tried (new Ellipse2D.Float).

10:59 Doesn't work, though.

10:59 rhickey: java.awt.geom.Ellipse2D$Float

11:00 asbjxrn: Oh.

11:00 rhickey: That's the real Java name for a nested class

11:00 esquesque_: d'oh

11:01 asbjxrn: Seems to do the trick.

11:01 thanks.

11:03 Do you know the reason it's this way? (And the java doc only mentions Ellipse2D.Float as a constructor.)

11:03 esquesque_: they compile that way

11:04 rhickey: it's a jvm thing, nested classes aren't really nested, so there is some name munging that occurs

11:04 asbjxrn: Ah, so that is the name in the bytecode,

11:04 rhickey: and the class files

11:04 asbjxrn: Right. I must admit I don't know the difference :)

11:05 Java -> parser -> class file -> compiler -> jar/bytecode ?

11:06 Nah. The code goes through the compiler to transform into a class file, doesn't it?

11:06 rhickey: the 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:06 asbjxrn: Ah, I see.

11:06 rhickey: e.g. Ellipse2D$Float.class

11:07 esquesque_: i've done alot of work with bytecode

11:07 it's an irritating format

11:07 rhickey: did you use ASM?

11:07 esquesque_: asm and bcel

11:08 i don't like asm's visitor pattern too much

11:09 rhickey: I find ASM pretty easy, but ignore the visitor pattern (only doing code gen)

11:09 esquesque_: i made my own bc lib in java that never really got finished

11:09 so i know the format very well

11:09 the attribute model wasn't very well thought out

11:10 rhickey: it has its quirks, but you have to give them props for stability

11:10 asbjxrn: An agent can be a ref, but is that a good Idea?

11:13 Since the agent is supposed to "guard" a place/state, but the ref is really a pointer to state?

11:13 rhickey: asbjxrn: you mean the state of an agent be a ref? I'd wonder why

11:13 an agent's state can change - do you want to change it to a different ref at some point?

11:14 esquesque_: rhickey: when using proxy, is "super" bound?

11:14 rhickey: esquesque: no, there is no access to super from a proxy

11:14 asbjxrn: I'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:15 rhickey: seems like a straight ref would work

11:15 esquesque_: is there any other function that gives me access to super?

11:16 asbjxrn: I 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:16 rhickey: esquesque: the new gen-class stuff has more power to access the superclass

11:16 asbjxrn: And I want the functions in the functionlist to be able to change the framerate.

11:18 esquesque_: gen-class?

11:18 dudleyf: rhickey: gen-class? Is that something for creating Java classes from Lisp?

11:18 rhickey: asbjxrn: a ref will allow for coordinated access from multiple threads. That's orthogonal to how you might use scope to make it visible

11:19 dudleyf: yes, relatively new in SVN. load genclass.clj and (doc gen-class)

11:19 asbjxrn: Yes, I don't think I need to access from more than one thread.

11:20 rhickey: asbjxrn: then you can use vars

11:20 asbjxrn: I'm struggling with this immutability-concept, and using a ref and rebinding it is the way I managed to keep state.

11:20 rhickey: asbjxrn: refs are fine

11:21 asbjxrn: alter works on refs, for var I would use set! ? (I haven't looked at vars yet...)

11:22 rhickey: yes, you'd set! a var

11:23 asbjxrn: I don't advocate changing if you've got refs working

11:23 asbjxrn: It's not much code yet, and I'm just writing this code to learn... Don't worry.

11:24 It's not a real project.

14:52 Chouser: hm, it's a pity I have to say (filter #(.isDirectory %) files) instead of just (filter .isDirectory files)

14:55 rhickey: yeah

14:57 Chouser: heh. 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:57 rhickey: :)

14:57 first-class-izing is something I've thought a bit about

14:58 as you might imagine

14:59 there is memfn, which has the drawback of requiring args be explicit

15:00 and now, not shorter than #()

15:00 Chouser: ah, hadn't seen memfn

15:01 rhickey: predates #()

15:01 Chouser: ok

15:16 rhickey: (defn jcall [obj name & args]

15:16 (clojure.lang.Reflector.invokeInstanceMethod

15:16 obj

15:16 (str name)

15:16 (if args (to-array args) (clojure.lang.RT.EMPTY_ARRAY))))

15:16 (defn jfn [name]

15:16 #(apply jcall %1 name %&))

15:16 ((jfn 'substring) "fred" 2 3)

15:16 ((jfn 'toupperCase) "fred")

15:17 just a reader macro away from #.isDirectory => (jfn 'isDirectory)

15:34 Chouser: so would there be any reason to not have .foo always decome (jfn 'foo) ?

15:36 s/decome/become/

15:37 rhickey: Right now .foo is a symbol. It gets macroexpanded in the operator position, but not otherwise. There are no symbol macros at this time

15:41 ozzilee: I have to say, coming from scheme, Clojure sure seems to have a lot of magic in it.

15:42 Of course, scheme doesn't interact with Java, either :-)

15:42 rhickey: exactly, most of the magic is there, and most of it is also based on standard reader/macro techniques

15:43 at least standard CL techniques

15:43 :)

15:43 i.e. its not syntax, still data structures

15:44 Clojure tends to be less verbose than the equivalent Scheme/CL

15:47 ozzilee: I think my clojure is outdated. Should (.count []) return zero?

15:48 (. [] (count)) works.

15:48 rhickey: (count [])

15:48 ?

15:49 ozzilee: Well, yeah, that. I mean calling java functions with the .foo syntax.

15:49 rhickey: ah, then yes, 0

15:50 ozzilee: Ok, mine freaks out. Must be old.

15:50 rhickey: yeah, (.member obj ...) is relatively new

15:51 ozzilee: It freaked me out the first time I saw it. I'm still not sure what I think of it. Looks funny to me.

15:51 The ... is the arglist?

15:52 rhickey: some consider it more Lispy, yes, args follow object

15:52 (obj.member ...) also works

15:52 ozzilee: Oh, now that's way better, if you ask me.

15:52 So ([].count) would work?

15:54 rhickey: no, it's not syntax - obj.member is a single symbol that gets macroexpanded, [].count is a vector followed by the symbol .count

15:54 Still sexprs

15:54 just symbols containing '.' are macros, effectively

15:55 ozzilee: Ah.

15:55 Is there a nightly build, or should I checkout trunk and compile?

15:56 rhickey: just checkout trunk

15:56 ant

15:56 or maven

15:57 ozzilee: Ok. I'll play with that tonight maybe. I'm going to look at possibly writing a wrapper for prefuse.

16:13 Chouser: rhickey: I guess I was just thinking a reader macro for .foo instead of #.foo

16:13 not all reader macros start with #, right?

16:14 rhickey: right, the thing would be, reader macros happen on read, so (.foo x) would read as ((jfn 'foo) x)

16:15 Chouser: right.

16:15 rhickey: while functionally equivalent, jfn is a lot slower - always reflective

16:16 I wouldn't want that for (.foo x)

16:16 Chouser: ah, ok. That was the kind of reason I was looking for. ;-)

16:18 rhickey: so 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:18 ozzilee: Isn't .foo special like that, since it only gets interpreted when it's in the operator position?

16:18 rhickey: special things mean greater complexity

16:19 .foo is a macro, people can see its effects using macroexpand

16:19 user=> (macroexpand '(.foo x))

16:19 (. x foo)

16:21 Chouser: I 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:05 abrooks: rhickey: 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:08 rhickey: I own the logo. You can use it to represent the Clojure language that I wrote.

21:08 there's no fancy license

21:08 abrooks: rhickey: Thanks. :) Is there a larger source image that I should start from?

21:09 rhickey: how big will it end up?

21:09 abrooks: rhickey: Well, technically copyright exists whether we acknowledge it or not. :)

21:09 rhickey: I understand

21:09 abrooks: rhickey: 200x200 perhaps. It might be okay smaller but 200x200 would be better, I think.

21:11 rhickey: http://clojure.googlegroups.com/web/Clojure_300x300.png

21:12 abrooks: Ah, perfect. Thanks.

21:13 rhickey: is there a url for the FaceBook group?

21:16 abrooks: There is now: http://www.facebook.com/group.php?gid=13489774164

21:17 I don't think it's visible outside of a Facebook login.

21:22 drewr has apparently joined the group already. ;-)

21:27 rhickey: I saw that you joined and added you as an admin.

21:28 rhickey: ok

21:36 drewr: abrooks: :-)

21:56 esquesque_: hi rhickey, how would i do load-file and keep all the bindings?

21:56 i do (load-file "genclass.clj") and gen-class is still unbound

21:57 rhickey: heading home now, maybe someone else can help, please?

21:57 esquesque_: i'm not picky :)

22:10 nevermind, i've got it sorted out

22:11 (in-ns 'clojure) gen-class

Logging service provided by n01se.net