#clojure log - Jul 01 2008

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

9:40 wlr: rhickey:apropos your recent identity/entity essay, this may interest you: http://arxiv.org/pdf/0806.4746

9:41 Lau_of_DK: wlr, where is that essay ?

9:41 notyouravgjoel: the jvm supports os level threads, and thus clojure will use all of my cores, correct?

9:45 wlr: Lau_of_DK: http://clojure.org/state

9:47 spacebat: notyouravgjoel: yes it can

9:49 Lau_of_DK: wlr, thanks

10:21 Anybody here working with Chousers zip-filter-xml lib ?

12:20 JamesIry: Gang, if any of you happen to be in LA, Orange County, or San Diego I've formed a group called Southern California Functional Porgrammers: http://socalfp.org.

13:13 rhickey: Anyone ever gotten Shoal or Jxta to work with IKVM? Trying to do some Clojure/.Net interop

13:17 kotarak: These numbers in the compiler messages... Are these line numbers? Eg. monad.clj:906, but this file has only 70 lines...

13:18 rhickey: there are some instances where you'll get a line number from a macro

13:19 can you paste a small reproducing case?

13:19 cemerick: rhickey: No, but what problems are you running into?

13:20 rhickey: ffailla can provide some details of the problem

13:22 kotarak: rhickey: the problem is a wrong defmethod call: (defmethod monad/bind [m k] (cond (is-ok? m) (k m) (is-nok? m) m)) It's missing the dispatch value.

13:30 rhickey: kotarak: when I put these 2 lines in a clj file and load, I get an error on line 2:

13:30 (defmulti bind identity)

13:30 (defmethod bind [m k] (cond (is-ok? m) (k m) (is-nok? m) m))

13:30 kotarak: I get one on line 906.

13:30 From the REPL: clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:906: Unable to resolve symbol: m in this context

13:30 rhickey: just those 2 lines in a file?

13:31 what version of Clojure?

13:31 kotarak: I'll try. Just a second

13:31 20080612 zip

13:33 rhickey: rev 909, on 6/17, improved things in this area

13:34 ffailla: cemerick: I have compiled jxta to IL via IKVM and ported the DiscoveryClient/DiscoveryServer Java tutorial to .NET as a test. It seems that my discovery callback never gets executed that was wired up with DiscoveryService.addDicoveryListener. The client and server apps appear to be running with out error, but the communication between the two does not appear to function. The Java example works fine.

13:35 cemerick: ffailla: What version of ikvm are you using?

13:36 kotarak: rhickey: ok. Will try the svn version.

13:36 Lau_of_DK: Chouser: You in the house tonight ?

13:37 Chouser_: Lau_of_DK: I am.

13:41 ffailla: cemerick: ikvm-0.36.0.11

13:41 pjb3: In Clojure terminology, is there a difference between a Var and a Symbol?

13:41 rhickey: pjb3: definitely

13:42 a symbol is just a name

13:42 like a string except it has 2 parts, ns and name

13:43 cemerick: ffailla: the first thing I'd do is compile the java example to IL, and bootstrap that up to make sure the whole stack works.

13:43 ffailla: cmerick: will do... i'll let you knwo how it turns out

13:43 thx

13:43 rhickey: a var is a reference

13:43 cemerick: no prob

13:44 pjb3: rhickey, so when you do (def x) you are assigning a Var to the Symbol x?

13:44 rhickey: there is no storage in a symbol, it is an immutable value, so no such thing as assigning to it

13:44 we names vars in our programs using symbols

13:45 so (def x) says create a var with the name x in the current namespace

13:46 we could use the same symbol x to refer to something else in a different ns

13:46 symbols don't have a 1:1 relationship with places

13:47 pjb3: do you know CL?

13:47 pjb3: rhickey: not really, coming from more of a Java/Ruby background

13:48 Chouser_: so "symbol" is almost synonymous with "identifier"?

13:49 rhickey: symbols can be used as identifiers, and are in program's code-as-data

13:49 when you type a symbol into the repl, the evaluator tries to find the var associated with it

13:49 pjb3: gotta go, be back later

13:49 rhickey: ok

13:51 Chouser_: I always flail a bit trying to talk about clojure code. I keep reaching for the word "variable" which is clearly wrong, and am never sure what to say instead.

13:53 kotarak: "naming" maybe?

13:57 cemerick: rhickey: (conj (hash-set) 5) => #{5}, but (conj (sorted-set) 5) => IllegalArgumentException

13:57 rhickey: there's no substitute for owning up to symbols being first class objects, vs just names in program text...

13:58 cemerick: That's in svn r927.

13:59 rhickey: clean? what does (sorted-set) return?

14:01 Chouser_: I just got the same error on r926. ant clean and rebuild fixed it.

14:01 rhickey: Chouser: I've taken to calling let-bound locals just locals

14:01 cemerick: Yeah, I cleaned, updated, built. (sorted-set) => {}

14:01 I'll try another wash and rinse. :-P

14:01 rhickey: user=> (sorted-set)

14:01 #{}

14:02 Chouser_: cemerick: specifically it was java.lang.IllegalArgumentException: Don't know how to create ISeq from: Integer

14:02 cemerick: Chouser_: Yeah, that's what I'm getting too.

14:02 Chouser_: rhickey: "locals", nice.

14:02 rhickey: vars are much trickier, people have such presumptions

14:04 Chouser_: a global var pretty much is a global variable, isn't it? You can point it at a new value anytime you want, you're just not supposed to.

14:05 rhickey: it is until you distinguish def from set! and binding

14:05 Chouser_: binding them is a bit different, but elisp and perl do that, so there's some reference for it.

14:05 rhickey: CL too

14:06 * rhickey can't seem to keep people from misusing def

14:06 Chouser_: perl's such an odd beast. it only had globals and dynamically-bound variables for a while, lexicals came later. Also has closures, but no named function arguments.

14:07 cemerick: wow, that was way harder than it should have been -- I cleaned 3x -- ended up checking out anew, all's well now.

14:07 Chouser_: rhickey: really? I don't see *too* much code on the groups with misused def

14:08 rhickey: not among the more experienced

14:08 but re-def-ing is many people's first inclination

14:08 Chouser_: is there some reason you allow def inside functions?

14:09 rhickey: Sure, you might have a program that writes a program

14:09 Chouser_: surely you could detect it at compile time and error out. ...would stop it quick.

14:09 rhickey: dynamically

14:09 stop redef? how will we fix bugs?

14:10 or just non-top redef?

14:11 kotarak: I have my math point of view: a definition is something special, long lasting. Eg. N is the set of natural numbers. This won't change (in a given context). Namings are local to eg. a proof. Let f_x be the density of x blablabla. The (def) is something important, which won't change. And (let) gives local namings for a limited context.

14:11 Chouser_: no, I just meant when you see a def that's not at the top level of the expr

14:11 but your point about building a program dynamically stands.

14:12 rhickey: kotarak: that was the idea, defs are durable, lets transient, set!s dangerous and not allowed on globals

14:12 but people see the effect of def and consider it assignment

14:13 also, one tends to re-def dummy var names in the repl

14:13 Chouser_: hm, although allowing it via (eval '(def foo 5)) would still pass the "top-level" test and would be weird enough to perhaps discourage casual use.

14:13 rhickey: most code shouldn't ever eval

14:14 Chouser_: most code should also never call def from inside a function, right? so it lines up?

14:14 I'm just musing here. Don't let me keep you from something important. ;-)

14:14 kotarak: OCaml got me cured of re-defing things. However one these it also in introductory code: (define *some-state* ...)

14:14 rhickey: no, when I call evel I think "there must be a better way"

14:14 eval

14:15 kotarak: s/these/sees/

14:16 rhickey: in OCaml are subsequent defines (with the same name) different bindings?

14:17 kotarak: Just let me check, but if remember correctly, your are not allowed to re-def things. Doing this like let x = f 5 in let x = g x in let x = h x in x are always "new" x's.

14:18 Hmm... Ok. you can re-def.

14:19 rhickey: right but def x 5, write code using x, def x 6, code using x still sees 5 unless recompiled?

14:20 kotarak: Yes. Eg.: let x = 5;; let f () = x;; let x = 6;; f ();; will give 5.

14:31 Hmmm. Is it bad to modify the meta-data of a "foreign" object?

14:32 rhickey: what do you mean by foreign?

14:33 kotarak: I'm a library and the user passed in

14:33 oops.

14:34 the user passes in something. Then I will most likely use with-meta, I suppose. Then I get a copy.

14:35 rhickey: you can merge metadata safely using namespace-qualified symbols as keys - `my-key will become 'my-ns/my-key

14:36 kotarak: o.O Uh? Nice.

14:37 rhickey: also note, recently symbols became fns of maps like keywords (`my-key ^blah) works

15:31 kotarak: hmmm..., x and y not def'd, I expect ^x = nil and ^y = {:Foo :Bar} and x and y = "Hello": (def x "Hello") (def y (with-meta x (assoc ^x :Foo :Bar))), but I get an IncompatibleClassChangeError. Where is my mistake?

15:33 StartsWithK: i'm trying to clojure applet, so i was reading this http://is.gd/JRW and using gen-and-save-class created my class that extends clojureapplet class http://pastebin.com/d7efff553 but i'm still geting this error http://pastebin.com/d48033846

15:33 can someone tell me what that means

15:33 *to make

15:36 rhickey: kotarak: strings can't have metadata

15:37 kotarak: -.- Ok.

15:37 rhickey: StartsWithK: ClojureApplet is not public

15:42 StartsWithK: rhickey, tnx that was it :) so just a quick question http://pastebin.com/d66048d8c means that i have to sign my applet?

15:43 and clojure.jar hmm..

15:44 kotarak: doh, "symbols and collections support metadata". Those who can read shall have a clear advantage.

15:44 rhickey: StartsWithK: it may not work even when signed - Clojure needs a classloader which may be disallowed, but that story could be different with the latest plugin stuff

15:45 StartsWithK: i use JNLPAppletLaucher, and on that thread he used web start too, so i was thinking it sould work as applet if it can be made to work as web start application

15:46 https://applet-launcher.dev.java.net/

15:46 rhickey: forgot he did that, looks promising

15:47 blackdog: StartsWithK, did you try without creating a main class? I was hoping that it would pick up user.clj auto, but it doesn't seem to want to work

15:48 StartsWithK: blackdog, i don't know how to make applet run without some class extendind javax.swing.JApplet or java.awt.Applet

15:48 blackdog: duh, i'm getting mixed up with webstart

15:48 StartsWithK: i don't think it can be done any other way

15:49 blackdog: i was trying to run it auto from a jar,

15:49 without a main class

15:50 StartsWithK: i don't think that could work, jnlp needs entrypoint class

15:50 blackdog: yea i was giving it a stub main,

15:51 StartsWithK: i'm using this http://pastebin.com/m5e817f05 as applet launcher

15:51 blackdog: but user.clj still didn't kickj in

15:51 thanks that's useful

15:51 apparently with the new update n jdk 6, applet and webstart stuff is unified to a degree

15:52 you can drag an applet of the page and have it run stand alone (apparently)

15:52 StartsWithK: yes, and my line of thinkis is - if web start can launch clojure then applet should too

15:52 ill have to run my applet first :)

15:53 and i think there is some option for that, i'm not sure, still reading the docs

15:53 but i found you can force it to use separate jvm, maybe that is it

15:53 blackdog: i thought that was one of the innovations in updaten

15:54 updateN (or whatever it's called)

15:54 StartsWithK: i think it was update5 or 10..

15:56 blackdog: i hope sun don't fu on the new applet stuff it would be nice to write everything in clojure from back to front

15:56 StartsWithK: yes, i would like to run my jogl apps as applets :)

15:56 https://jdk6.dev.java.net/plugin2/jnlp/

15:56 blackdog: i was suprised to see applet usage on facebook, but that's a hopeful sign

15:57 StartsWithK: i tested it with some demos from jogl and it runs really nice and fast.

16:10 ok, i certified clojure.jar and my helloworld.jar as show in http://is.gd/JTG

16:11 it no longer is bothering me with security, it just asked do i trust this untrusted certificate

16:11 blackdog: nice

16:11 StartsWithK: now i have this http://pastebin.com/m5e1ebdeb

16:12 but that looks like i just don't know how to use genclass

16:12 Chouser_: no, you're doing it right.

16:13 you have a (refer) inside your genclass namespace, right?

16:13 You either have to do a bunch of :exclude, :only, or :rename.

16:13 StartsWithK: yes

16:14 Chouser_: or skip the refer entirely and use clojure/defn and such everywhere.

16:14 StartsWithK: ok ill try that (this is how it looks at the moment http://pastebin.com/m43685eff)

16:18 Chouser_: it's pretty annoying, because either way you generally screw up and leave something out of your :exclude or :only list, and just have to try again, note the exception, and add the name to the list.

16:18 on the other hand, it's hard to think of how it ought to work instead.

16:19 rhickey: one possibility is to have all of the 'method' names be munged in some fixed way

16:20 Chouser_: another would be if you could define names in a namespace without having to be in that namespace. (defn classns/init [this] ...)

16:22 rhickey: since most namespaces will be long com.blah.ClassName seems like a -method suffix or m- prefix would be shorter

16:22 StartsWithK: changet it to http://pastebin.com/d37cd7943 but now i get "unable to resolve clasname : Graphics"

16:24 Chouser_: yeah, although with namespace aliasing that problem would go away too.

16:25 hm, with munging you could have a handy macro to do the right munging for you. (defmethod foo [this]...)

16:25 well, no defmethod, but something. def-genclass-method. ;-)

16:26 rhickey: defhandler?

16:26 Chouser_: yeah

16:27 StartsWithK: how will that help with the need to use clojure/let and others?

16:27 Chouser_: that way the actual munging could be entirely internal to clojure and not show up in the user's code at all.

16:28 rhickey: and with munged names you could (refer 'clojure) without conflicts

16:29 Chouser_: I suppose the names manually given to genclass would remain unmunged? :factory, :state, etc?

16:30 rhickey: right

16:30 Chouser_: yeah, this would be a lot better than how it is now.

16:32 StartsWithK: ok, i think it will work.. now i get no matching field found: getSize

16:32 so applet must be running

16:32 * StartsWithK steps outside for some fresh air..

16:32 Chouser_: defhandler could even add the "this" arg for you, like proxy does

16:33 * rhickey muses about the munge being the prefix '.'

16:33 Chouser_: hm, except some of the unmunged names probably still take "this", which might be confusing

16:33 ha!

16:38 so you can define .foo, and you can refer to it, but you can't call it. in the context of a genclass ns, though, I suppose you could do (.foo this ...) and have it refer to the .foo you just def'ed.

17:49 StartsWithK: it was silly mistake on my part Graphics has no getSize method, JApplet has it.

17:49 so (.getSize this) works

17:49 and i can say applet works :)

17:50 Chouser_: very cool! how hard was it to sign the various bits?

17:50 you should write it up and send it to the google group.

17:50 blackdog: ii'm interested :)

17:50 StartsWithK: i will do it sometime tomorow, ill try to find ant tasks to automate signing the jars.

17:51 so for now i can only say it works on jre 1.6_05 under xp

17:52 Chouser_: if you've got it up somewhere I can point linux with jre 1.6_06 at it.

17:53 StartsWithK: for now i think it should be at http://rekram.homelinux/neman/neman.html

17:53 Chouser_: is there a .net or .org in there somewhere?

17:54 StartsWithK: uff sorry, jer org

17:54 *yes

17:54 Chouser_: Publisher: sun microsystems

17:54 blackdog: i get the blank gray applet box :)

17:55 StartsWithK: hmm

17:55 blackdog: not asking me for anything

17:55 StartsWithK: can you open java console to see the output?

17:55 Chouser_: ah, another auth box for published by K-something. ;-)

17:55 StartsWithK: thats me

17:55 Chouser_: yeah, I figured. and now a grey box. :-(

17:55 StartsWithK: it could take some time, i included jogl jars inthere too

17:55 blackdog: i;m on openjdk ubuntu here

17:56 ok maybe it's stilldownloading here

17:56 StartsWithK: hmm.. i used openjdk on arch (64bit) and it didn't work for jogl textures..

17:56 blackdog: i'm on 64 too

17:56 :/

17:56 no worries

17:57 StartsWithK: icedtea6 worked with applets, but didn't display jogl correctly.. ill try it with 1.7

17:58 blackdog: where do i find the java console in ff3

17:58 StartsWithK: under xp in control panel there is java icon, i checked java console from there

17:59 but i don't know under linux :/

17:59 http://www.java.com/en/download/help/5000021200.xml

17:59 blackdog: my java is enabled but i'm not seeing any console optipon maybe it's another extension or so

18:00 Chouser_: did it open a new window?

18:01 blackdog: no, i'm getting the gray box and nothing else right now, i'll check my install

18:01 StartsWithK: i can say that it work on another xp box with jre 1.6_06

18:07 blackdog, if dcc is working on freenode i can send you the files so you can try localy?

18:07 blackdog: sure, i'll give it a try, but i think it's my setup

18:08 woops

18:08 can you do that again

18:10 StartsWithK: ill send you the sources too, but they are just a mess at the moment, there is a ant task "ant dist-helloworld-applet"

18:11 and you should sign helloworld after each modification

18:11 blackdog: ok, no joy locally either

18:12 but i seems ubuntu is carrying a jdk7 gck web plugin, so i don't think it's entirely standard :)

18:13 gcj

18:13 StartsWithK: im just happy it works under xp :) it it will not be fun to work with applets if i can't test them on my box

18:13 Chouser_: Hello World

18:14 blackdog: for real,

18:14 Chouser_: It just worked for me here.

18:14 blackdog: anything to stop having to write flash :)

18:14 StartsWithK: Chouser_, under linux?

18:14 Chouser_: linux ubuntu java 6

18:14 StartsWithK: cool

18:14 thats 32bit?

18:15 blackdog: i'm 64bit

18:15 Chouser_: something about it doesn't like my window manager -- I think that's why I was getting a new window popping up.

18:15 but in a "normal" window manager, it worked just fine.

18:15 StartsWithK: :)

18:16 Chouser_: yes, I believe I'm all 32 bit here (although probably on a 64 bit cpu)

18:17 blackdog: yea, i was a bit hasty with my install :/ should have kept it standard,

18:17 the worst thing i found was that the mem consumption of java is even worse than usual

18:18 StartsWithK: blackdog, i think standard jdk6 under 64bit linux can't display applets at all

18:18 icedtea6 can

18:18 blackdog: so for my dev i use the 32 bit updateN under my login which works fine

18:19 ah, wonder if appletviewer works

18:19 the update n version

18:23 nopes

18:23 ~/usr/jdk1.6.0_10/bin/appletviewer http://www.rekram.homelinux.org/neman/neman.html

18:23 java.security.AccessControlException: access denied (java.net.SocketPermission download.java.net connect,accept,resolve)

18:23 StartsWithK: yes i get that one too, but i can't say why

18:23 blackdog: maybe appletviewer doesn't deal with the secirty stuff

18:23 no worries

18:24 thanks for the src,

18:24 StartsWithK: random link http://www.innovation.ch/java/security.html

18:25 with something about appletviewer and how to setup security

18:26 blackdog: k

21:02 Chouser: (defn f [] (let [x {:a #(...) :b #(...)}] ...))

21:03 Is x built each time I call f?

21:03 rhickey: yes, but the fns are not recompiled

21:04 Chouser: I'm thinking of use x like this instead of a (cond) ... is that bad idea for style or speed reasons?

21:06 rhickey: what that really is is case - value dispatch. The resulting dispatch, especially if there are many cases, will be much faster...

21:06 but - if you only dispatch once, you will have instantiated all the fns

21:07 a fn compiles into a class that implements IFn

21:07 Chouser: I have 3 or 4 cases ... right, ok. probably not worth it just for speed.

21:07 rhickey: creating an instance is a simple ctor that passes any closed-over values

21:07 Chouser: ah, ok.

21:08 my #() fns all close over args of f, so I can keep old instances. And then f will do a single lookup of x. So this is probably quite inefficient compared to a cond.

21:09 ...which is a pity because the hash look implementation is more terse.

21:10 does java bytecode have goto?

21:10 rhickey: I need to add case just so you don't have to (cond (= x :a) ... (= x :b) ...)

21:11 recur is goto

21:11 there's also a table switch, for numeric cases

21:11 Chouser: ah, yes. I looked that up once.

21:12 hm, hash values are numeric... oh, sequential?

21:12 rhickey: you need to know the values at compile time

21:12 Chouser: ah, never mind. I'm way off in the weeds now. I'll just go write my cond expression. :-)

21:12 rhickey: sort them

21:13 case would be (case x :a ... :b ...)

21:14 Chouser: that would fully solve my terseness issue. I guess I can write a case macro that produces a cond

21:15 would you provide an else for case?

21:15 rhickey: (case x :a ... :b ... x ...)

21:16 Chouser: oh! nice.

21:16 rhickey: CL has ecase where no match throws

21:17 case with no match should return nil

21:33 slava: you can do interesting optimizations with a case macro

21:36 Chouser: slava: like what?

21:37 slava: well, if your keys are integers, you can turn it into a binary search or a table switch, depending on how closely packed they are

21:37 for other types you can look at the hashcode, then only compare against the keys having that same hashcode modulo n, where n is the size of a dispatch table

21:39 Chouser: slava: if you have constant test values.

21:40 slava: yes

22:10 lisppaste8: Chouser pasted "naive case macro" at http://paste.lisp.org/display/63135

23:06 sterling: motd

Logging service provided by n01se.net