#clojure log - Sep 13 2008

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

7:48 meredydd: Whoever maintains clojure.contrib.sql - I just put a patch on the list to make 'with-connection return its body value rather than nil.

7:49 (and yes, I have the necessary contributor arrangement signed with rhickey)

8:29 rhickey: Do you have my CA?

8:35 rhickey: meredydd: only the photo, nothing in the mail

8:35 meredydd: Oh, dear. I sent that quite some time ago.

8:36 rhickey: I see your email was from July

8:37 meredydd: Blast. Looks like I'm going to have to send it again.

8:38 Am I okay with the photographed document just for the present patch (if it's accepted)?

9:22 markella_athens: hallo, is this a scottish chat room?

9:22 hallo, is this a scottish chat room?

11:14 StartsWithK: how to remove something from *ns* refere map? with ns-unmap?

11:14 rhickey_: StartsWithK: yes

11:15 StartsWithK: if i write my own with-refer macro, should i do something like (binding [*ns* *ns*] ..)

11:15 and then manipulate refer of that local *ns* var?

11:16 rhickey_: namespaces are global

11:16 StartsWithK: then maybe i woudn't need ns-unmap at all

11:16 thanks

11:25 ok, just one more question. Is this safe? do other threads see new refers? should i maybe create new ns, copy all referes from current ns and add my own in it.

11:26 rhickey_: StartsWithK: I don't think this is a promising endeavor, as I said, namespaces are global

11:26 gnuvince: Are there plans to add Clojure benchmarks to the Computer Language Shootout

11:26 ?

11:27 rhickey_: gnuvince: I presume someone will at some point

12:30 Chouser: rhickey_: care to briefly describe the purpose of delayed class loading, or should we just wait until you're done?

12:43 rhickey_: Chouser: it was an experiment to improve startup time - compile but do not load fns until called. Uses a self-replacing thunk. I only got ~20% improvement, which is less than I hoped.

12:43 My thinking now is that AOT will trump that.

12:43 Chouser: hm! ok.

12:44 compiling to Java source is the only AOT you're considering right now?

12:45 rhickey_: No, I'll look at both, but there are a lot of subtle tradeoffs. There seems to be some relcutance about AOT->Java, any reason?

12:46 Chouser: I'm not in the target market.

12:46 rhickey_: One nice thing about Clojure->Java is I can gen one Java file for one Clojure file, instead of 400 .class files. Of course, compiling the Java file will generate 400 classfiles...

12:47 Chouser: heh.

12:48 I guess I assumed AOT->.class would be easier. I hadn't really considered AOT->.java before you brought it up.

12:48 rhickey_: There are some awkwardnesses to Java for some expressions (in bytecode I have goto), but my experience with HotSpot tells me it can probably make them go away in the end

12:49 Chouser: As I said, I doubt I'll use any of the AOT stuff, but off the top of my head I can't think why AOT->.java is at all inferior.

12:50 rhickey_: Chouser: you might use AOT if you want to run on Android

12:51 Chouser: hm, sure. Does Android consume .class?

12:51 rhickey_: Chouser: yep

12:53 Chouser: but many things that consume .class trip over any bytecode sequences other than what javac would have generated.

14:10 jgracin: is there a variant of 'some' which returns the element that matched and not the value of predicate?

14:11 and not -> instead

14:20 achim_p: jgracin: i've been looking for something like that recently, but found nothing. i ended up rewriting pred as #(if (pred %) %)

14:21 jgracin: achim_p: yeah, that's what I've been doing too.

14:23 achim_p: I kinda remeber someone talking about that, but it might have been related to 'collect'.

14:27 parth_m: rhickey: (nth [1 2 3] -1 nil) throws "java.lang.ArrayIndexOutOfBoundsException: -1". Is this by design or is it a bug? (get ..) returns nil.

14:28 arohner: huh, the doc on get doesn't indicate that it also works on vectors

14:29 parth_m: Oh. I missed that. I just saw coll and assumed that it worked.

14:30 Is that a doc error or is it not supposed to work?

14:30 arohner: I don't know

14:31 achim_p: vectors are maps with implicit keys in clojure, as i understand it ...

14:31 parth_m: Actually (doc get) just talks about map but it seems to work like (nth coll idx nil) for vectors. I suppose thats by design.

14:31 Ah. .. that makes sense.

14:32 achim_p: might be wrong though, i'm not sure :)

14:33 arohner: I think clojure vectors have normal vector lookup characteristics, i.e. O(1) by index

14:33 I think it's better to say that vectors are functions of their indices, similar to how maps are functions of their keys

14:37 rhickey_: parth_m: get and nth work differently by design, that's documented

14:39 parth_m: rhickey: Is "not-found" arg ignored in nth for -ve index?

14:40 rhickey_: parth_m: looks like it

14:41 negative indexes are not meaningful

14:44 parth_m: True. But "not-found" being ignored is somewhat confusing. The use case I have is I want to get some items from a vector (nth v (- len 1) nil) .. (nth v (- len 2) nil) ... and so on.

14:44 This works fine. However, when len is 0. (- len 1) give -1 and we get an exception.

14:45 The work around is quite simple ... but I was just thinking what might be intuitive behavior.

14:45 I can fix it in my user code ... but do you think its a good idea to allow not-found for -ve args as well?

14:47 This would also be consistent with get, so nth+not-found = get for vecs

14:49 rhickey_: fixed nth with not-found arg - when negative index returns not-found - rev 1025

14:49 parth_m: Very cool :) Thanks.

16:26 arohner: is there a way to get the current function you're in?

16:27 functionality similar to __FILE__, __LINE__, etc in C?

16:37 rhickey_: arohner: *file*

16:37 arohner: but no line or function?

16:40 rhickey_: no

17:35 Chouser: In order to expand macros, I've got to resolve symbols at compile time, which means I have to honor (eval?) some expressions at compile time, like in-ns, refer, require, etc.

17:36 Or am I thinking about this incorrectly?

17:38 But clearly some expressions I do not want to eval at compile time, since that means they would try to run in the JVM when they're written to execute in the browser.

18:15 rhickey_: Chouser: those expressions won't be in macro logic, only in expansions

18:28 joubert: hello

18:29 I have a question about Java class / Clojure bridging

18:30 rhickey_: ok

18:30 joubert: in an API I am using I have to pass a parameter that references a generic type

18:30 for "normal" classes, referencing in Clojure is trivial

18:31 e.g. java.util.Date

18:31 however, I'm uncertain how to specify a generic

18:31 rhickey_: joubert: just leave off the generic bit

18:31 i.e. the type parameters

18:32 e.g. java.util.Collection

18:47 Chouser: rhickey_: You've explained it several times now, but I'm still not getting it. If I use Compiler/analyze on '(defn foo []), it needs to be able to find defn in the clojure namespace.

18:48 if the user has their own macros, they'd define them in some other namespace, like 'my-ns

18:49 So if I have a file of clojurescript (.cljs?) it seems most natural to start if off with something like (ns my-js-ns (:use my-ns)), and then proceed to use macros from 'my-ns and 'clojure

18:51 I can analyze that form and get the expansion, but if I just emit js and don't eval it, the following forms in the cljs file will fail to expand my-ns macros.

18:52 for now, I'm eval'ing just the (ns ...) form, but that doesn't feel right.

19:06 joubert: rich: perhaps I should be more specific

19:10 actually, let me experiment with a few approaches before I ask more questions

19:29 rhickey_: Chouser: you will have to load into Clojure any macros you'll use in emitting js

19:30 Since they are only used on the Clojure side, they'll likely be separate from the js code

19:32 there's no point in sending macro code over to the browser

19:34 I understand there is an extra level here - compilation deps vs runtime deps. The new Scheme modules distinguish code needed for syntax in some way IIRC. I don't know that we need anything as ornate

19:36 CL has eval-when

19:37 we could have a (use ... :when :compile ...)

19:37 or something

Logging service provided by n01se.net