#clojure log - Aug 14 2008

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

4:27 blackdog: in a macro when a ~@body is being processed what is the reason for the @ ?

4:29 is the body automtically a ref?

4:40 Chouser: no, it has nothing to do with refs

4:41 ~ inserts a value, ~@ splices in a list

4:42 user=> `[1 ~[2 3] 4]

4:42 [1 [2 3] 4]

4:42 user=> `[1 ~@[2 3] 4]

4:42 [1 2 3 4]

4:42 blackdog: ok that helps

4:44 thx

4:44 Chouser: sure. It's documented on the Reader page on the site, but that's a pretty dense section.

4:46 blackdog: i have a pretty dense section between my ears too :)

4:47 Chouser: heh. if you got anything at all out of my first answer, then I highly doubt it.

4:50 blackdog: so if i'm supplying a macro body (using) and I notice that the macro is using ~@ I should return a list, cos right now i get a compilation error when the last value is a map

4:52 Chouser: If the thing to the right of ~@ isn't a collection, you'll get: java.lang.IllegalArgumentException: Don't know how to create ISeq from: X

4:53 blackdog: ok, making more sense

5:04 so to get a value out of macro the way is (let [x# ~@body]

5:04 (.commit ~con)

5:04 x#)

5:04 never mind the commit

5:04 so i return the x#

5:05 is that ok to do?

5:11 lisppaste8: blackdog pasted "returning the body value of a macro?" at http://paste.lisp.org/display/65307

5:12 roblally: I'm not an expert, so this me joining in to the speculation, but wouldn't the value of the let be the value of ~@body, so it kind of becomes unnecessary?

5:12 blackdog: but i need to do the commit which is the last step

5:12 so don't ignore the commit :)

5:13 roblally: I have removed the filter now, and can see the statement again.

5:13 blackdog: in that paste you can see i'm getting stuff from the db, processing it and then i want to return something different

5:14 roblally: So, if you splice the body into the let list, you'll get the unrolled list of expressions in the let statement. So that doesn't look right.

5:16 Would (let [x# (do ~@body)] ... ) make sense?

5:16 blackdog: :) i have no idea but i'll try it

5:17 roblally: If I understand it properly do would evaluate all the statements and return the last value.

5:17 blackdog: ok i see

5:19 crikey I'm in your deby

5:19 crikey I'm in your debt

5:19 that works

5:20 roblally: Neat! I was exaggerating when I said I wasn't an expert. I'm not even competent.

7:05 StartsWithK_: hi

7:06 i now have osgi bundle with clojure

7:06 using equinox

7:06 Chouser: cool!

7:07 I don't know what any of that means, but it sounds cool!

7:07 StartsWithK_: it works but, i had to merge clojure.jar with mine bundle and jar of every library that will interact with clojure

7:08 Chouser: http://www.osgi.org/About/Technology

7:09 equinox is eclipse implementation of osgi container

7:10 Chouser: yeah, I've been looking at that page. Too much Java for my poor little head.

7:10 StartsWithK_: second implementation (or first) is knopflerfish, but i had no luck with it

7:10 Chouser: But I'm sure there are people who will show up and say "does Clojure support OSGi? We only do OSGi."

7:10 and because of you, they will be happy. :-)

7:10 StartsWithK_: its like plugin system for your application, but much more generic

7:11 now :) there are problems :)

7:11 i extended clojure manifest so it can be registered in osgi container

7:11 that works if you never have to (import) anything

7:12 problem is, clojure bundle will have it's own class loader and your bundle will have it's

7:12 Chouser: ah.

7:12 StartsWithK_: and your file.clj is in your bundle

7:13 that could work maybe, but each bundle has to have Import-Package directive that list all packages this bundle will require

7:13 so clojure needs only org.xml.sax and org.xml.sax.helpers (xml.clj)

7:13 Chouser: hm, so OSGi is expecting a more static world than Clojure is.

7:13 StartsWithK_: yes

7:14 too much if you ask me

7:14 there is Dynamic-ImportPackage directive, you can use wildcards in it

7:14 but you can't use '*' as standalone, that could maybe solve importing problem

7:15 so i merged clojure with my bundle (each bundle will have to merge cojure.jar with itself)

7:15 this soled only one part of the problem

7:16 second one is when you create proxy (i don't know will it happend is some other situation)

7:17 library that is using proxy will be in another bundle, and i woulg get errors that clojure (?) can't find classes from clojure.lang package

7:17 so.. to solve this, i had to pack all libraries that will interact with clojure inside my own bundle

7:18 that kind of defeats the purpose of osgi :)

7:18 roblally: You probably want to look at a bundle fragment rather than merging the jar in. You could also use buddy loading, but that would restrict you to Equinox

7:18 StartsWithK_: knopflerfish didn't work anyway so i have no problem with using only equinox

7:19 i was thinking of using that, but then i would have to have for every lib a clojure bundle fragment that will provide new Import-Package directives

7:20 and i don't think that will solve second problem, when other bundle will use proxy

7:21 roblally: Yeah, you're probably right. Dynamic behaviour is always a problem in an OSGi environment. Personally I'd rather gnaw off my own foot than use OSGi where I didn't have to.

7:22 StartsWithK_: i would say biggest problem here is RT and how it handles class loaders

7:23 but i don't know that much about clojure or java

7:23 roblally: It'll start to get even uglier when if you want to use the parallel/fork-join framework and the jars from there.

7:24 And I can't even begin to guess what you'd have to do to get gen-class running in a sane way.

7:24 StartsWithK_: why? :) don't scare me :)

7:25 roblally: That's another jar that you'll need to declare as a dependency from each bundle that uses it, and if there's call-backs, you'll end up merging that into the same library.

7:25 Pretty soon you end up with one giant OSGi bundle containing the whole world.

7:27 The problems aren't intractable, apparently, but they're not easy to solve in a manner that's easy for normal humans to comprehend.

7:28 (I've had experts trying to explain this stuff to me for years and I've never been able to keep it in my head for more than a few minutes at a time.)

7:29 StartsWithK_: it that happens, i will try to split them up by implementing services in scala (other part of each bundle) and scala actors uses fork/join lib too

7:29 so maybe i will avoid most of the probles

7:31 roblally: Good luck.

7:31 StartsWithK_: but this should be resolved inside clojure, so i can do rt = new RT, there is no need for one static runtime

7:31 or is there?

7:36 albino: StartsWithK_: May I ask why you are using osgi? Is there a big benefit you're after?

7:37 StartsWithK_: albino: loading and unloading of plugins at runtime

7:38 albino: Does a plugin just have to meet the osgi spec to be loadable?

7:40 StartsWithK_: i theory yes, in practice there are some class loader problems, its not just clojure, there are others that have similar problems

7:42 but in some slides from knopflerfish, they state that it is not osgi problem, that libs use class loaders incorrectly and that it shows when you use them inside osgi container

7:43 i don't know is that true or not

12:32 roblally: If I have a method with a var-args parameter [& more] and I have a list that I want to pass it, is there a way to unroll the list so that 'more' is assigned to the contents of the list rather than the list?

12:32 kotarak: roblally: (apply your-func the-list)

12:32 Chouser: apply

12:32 roblally: Ahh, thanks guys. Much appreciated.

13:31 vixey: how does the compiler work?

13:31 drewr: Rich addresses that very well in one of the videos.

13:31 slava: it compiles, i guess :)

13:32 drewr: If you know anything about Lisp readers/compilers in general, it's fairly similar.

13:33 slava: the difference being that the JVM does most of the hard work

13:33 vixey: I don't know how you compile a dynamic language to the static jvm

13:33 slava: 'dynamic' and 'static' are pretty meaningless terms

13:33 the jvm supports runtime method dispatch and so on

13:37 main problem with compiling clojure to the jvm is that the jvm doesn't support tail calls or closures, but rich has some workarounds for those that seem pretty satisfactory for the mostpart

13:37 vixey: what are they ?

13:37 slava: i implementd a jvm language once with full continuations and tail calls, by managing my own call stack, but the gains are not really worth the extra overhead

13:38 so if i did it again i'd take the clojure approach

13:39 vixey: It looks like everything it emitted as boxed by the compiler unless it's possible to unbox

13:40 and I guess boxed just means that you've got type information in the value (maybe that's not quite it though)

13:40 slava: all java objects have runtime type information

13:40 primitives don't

13:40 so a compiler can only emit code using primitives if it can prove it is monomorphic

13:53 vixey: does he talk about it in one of these http://clojure.blip.tv/ ?

14:04 drewr: vixey: Yes. I *think* it's in Clojure for Java Programmers Part 1.

14:05 vixey: thanks

16:15 ericthor: jure

18:40 arohner: lisppaste8: url

18:40 lisppaste8: To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.

18:41 arohner: rhickey: I have a really tiny diff for you that helped me find a bug in my program

18:41 lisppaste8: arohner pasted "diff" at http://paste.lisp.org/display/65342

18:47 rhickey: arohner: I look at it tomorrow, thanks

18:47 arohner: ok

19:17 wwmorgan: I'm trying to write a function or macro that takes a list containing some symbols not bound in the current namespace, and returns a function that takes a map and evals the list using the key-val pairs as symbol-value pairs. http://paste.lisp.org/display/65343

19:17 any ideas?

19:18 Chouser: hm, sounds like fun...

19:22 can create-template be given the list of symbols it will need to bind, or does it have to discover them somehow?

19:25 wwmorgan: it's fine to assume that it knows what symbols it needs to bind

19:25 I've adopted a convention of making them begin with upper-case letters a la Prolog

19:28 Chouser: user=> (defmacro create-template [s & b] `(fn [{:keys ~s}] ~@b))

19:28 nil

19:28 user=> (def template (create-template [a b] (+ a b)))

19:28 #'user/template

19:28 user=> (template {:a 4, :b 6})

19:28 10

19:29 hope that helps, even if it's not exactly what you want.

19:30 anyway, I'm off to bed.

19:30 wwmorgan: thanks good night

20:33 arohner: what is the clojure equivalent to import java.io.*?

20:33 I tried (import '(java.io *)) but that didn't work

20:33 (import '(java.io.*)) works, but then the symbols aren't in the same namespace

Logging service provided by n01se.net