#clojure logs

2008-06-05

00:00Chouserbtw, I don't think I'd like suffix chars for primitive literal numbers.
00:01JamesIryChouser: They borrowed some syntactical structures from Java where they didn't have a strong reason to do otherwise
00:01rhickeyStill no substitute for a truly immutable data structure, just has much better memory and concurrency characteristics in the end
00:02rhickeyChouser: meaning you're opposed, or just wouldn't use them?
00:03Chouserrhickey: well, that's a good question. I guess my current opinion is that I'd rather not read them. :-)
00:04rhickeyI ripped out all of my effectively-but-not-really-immutable data structures once I got the hash tries working. They're plenty fast.
00:04Chouserhm, I dunno. That's a gut feeling -- I don't know if I can back it up with anything. You should probably ignore me. ;-)
00:05rhickeygotta run, thanks all for a nice conversation
00:05JamesIryrhickey: thanks for the pointers on STM
00:05JamesIryHopefully you and Martin Odersky can talk some time
00:05rhickeyyes
00:06JamesIryChouser: on my wishlist for Scala would be some equivilant of reader macros so I could create my own literal forms for things like regexs or BigInts
00:08ChouserJamesIry: Yeah, I asked about regular (non-reader) macros. Nobody seemed opposed...
00:08JamesIryI'm all for them. The natural model wouldn't be Lisp style macros though - it would be something more like Template Haskell or Nemerle templates.
00:09JamesIryOr the Ocaml one whose name I can never remember
00:09JamesIrycaml4p
00:10Chouserbut in most of those syntax-ical languages that have "macros", you can't call host language functions from within an macro.
00:10Chouser...which gets m4 or CPP-level functionality. Not impressive.
00:13JamesIryChouser: CPP is a poor comparison. And I'm not sure what you mean. A template can't call host language at expansion time, but it certainly can at runtime. Isn't that roughly similar to many lisps?
00:14Chouserno, lisp macros can call any function they want at expansion time.
00:14JamesIryNot talking about CL. Thinking more like Scheme
00:14Chouseroh. well.
00:15ChouserIt makes a huge difference in how powerful the macros can be.
00:16JamesIryOf course!
00:17ChouserHave you read On Lisp by Paul Graham?
00:17JamesIryYup
00:17JamesIryGood book
00:17JamesIryI also read his "Ansi Common Lisp" which was as dry as a 3 week old tortilla
00:17JamesIry:)
00:17ChouserI didn't "get" what the big deal was with macros until I read it. Now I'm a believer. ;-)
00:22JamesIryPractical CL is also a good book which conveys the power of macros. It's not quite as tight as On Lisp, but does give a better feel for the rest of the language. When people ask me about lisp I usually recommend SICP, Practical CL, and On Lisp in that order. Unfortunately, I also now have to recommend them to Clojure but there aren't any books on it just yet.
00:28JamesIryWell, I gotta run... thanks for the chat
00:48Leafwis there any way to create a string in a macro, and make it become a keyword, not a string, in the expanded code?
00:48Leafwfor example: (defmacro pra [T] `(println ~(str "#^" T "s")))
00:49Leafwthat generates a string with str, but, is there anyway to make it become cleanly #^doubles , for example, with (pra "double") ?
00:50ChouserLeafw: yeah, just a sec...
00:50Leafwok!
00:52Leafwthe idea being, I want to write generic functions, that can be automatically type-decoreated for int, float , etc.
00:52Leafwwith macros, of course
00:52Chousertry (symbol (str ... ))
00:52Chouserbut I think you have other problems with that macro
00:52Leafwthank you
00:53Leafwthat is just an example
00:53Chouserok
00:54Leafwwow this is nice.
00:54Leafwthank you Chouse
00:56Chouser:-) np
00:56Leafwthis is awsome
00:57Leafw:)
00:59Ycrosmmm, macro enlightenment
01:00Leafwyes.
01:00Leafwgood night all.
02:19Leafwclojure's pastebin ?
02:21lisppaste8leafw pasted "macro primitives" at http://paste.lisp.org/display/61746
02:21LeafwI'd appreciate help with that macro
02:22Leafwit macroexpand-1 ok, and the code alone urns ok, but when called from a macro it fails with ArrayIndexOutOfBoundsException, which puzzles me
02:23Leafwif it makes you scream, this is just a test ......
05:22cgrandLeafw: did you make your sum<T> macro work?
08:32Lau_of_DKIs (lambda () (...)) directed swapped with (fn [_] (...)) in Clojure?
08:34jteoyup.
08:34Lau_of_DKk, thx
08:38Lau_of_DKuser=> (def white (. (new Color 255 255 255 255) (getRGB)))
08:38Lau_of_DK#'user/white
08:38Lau_of_DKuser=> white
08:38Lau_of_DK-1
08:39Lau_of_DKShould this return an object ?
09:00Lau_of_DKNoone knows? :)
09:00rhickeyknows what?
09:00Lau_of_DKwhy white is -1 instead of a Color object
09:06tomhickeyi believe it's because that's the result from calling getRGB (which returns an int)
09:07Lau_of_DKokay, thanks tom
09:07Lau_of_DKNot having worked with Java can trigger some dumb questions and Netbeans seems to have some flaws in its "intellisense"
09:36Leafwcgrand : no, I didn't
09:36Leafwnew day, will try again
09:37Leafwshould be using gensym instead of a __ in front of a var name, will fix that too ...
09:37cgrandleafw: you problem is with #^
09:37Leafwit's still here http://paste.lisp.org/display/61746
09:38Leafwthe #^doubles type declaration?
09:39Leafwif I use it separately no problem
09:39rhickey_there are simple function casts for int/long/double/float and ints/longs/doubles/floats/ so you don't need to emit metadata
09:39Leafwwill get to it in an hour or so
09:40rhickey_(let [arr (doubles a)] ...
09:40Leafwfunction casts? That's new to me
09:40rhickey_cast functions
09:40Leafwok
09:40rhickey_they were always there for int/long etc, ints/longs are new
09:41Leafwyes, I know
09:41LeafwI'm Albert by the way.
09:41Leafwbrb
10:20lisppaste8Lau_of_DK pasted "Ants-modified" at http://paste.lisp.org/display/61761
10:21Lau_of_DKGents - Im trying to modified Rich's Ants example to simulate Langdons ant. So the first step was pretty simple, just modify the world to a checkerboard with alternating black/white squares. setup does this correctly, but I've hit a problem: Now it doesnt render anything at all. It wont render the checkers, and I tried just setting a random color to see if it would paint anything, but nothing happends - Am I overlooking something?
10:39Lau_of_DKno takers? :)
10:49ChouserIs there way to create a proxy with a method that returns "this"?
10:50ChouserLau_of_DK: what you pasted doesn't run because of missing earlier bits (import, etc.) I'm too lazy to figure out what needs to be added. ;-)
10:50Lau_of_DKNo that was on purpose, so you guys knew where the problem was :)
10:50Lau_of_DKBut I can paste the whole thing
10:50rhickey_Chouser: is the this-returning method a method of one of the superclasses?
10:51lisppaste8Lau_of_DK pasted "Ants-modded" at http://paste.lisp.org/display/61762
10:51Chouser(let [myobj (proxy ... (mymethod [] myobj))]) ... doesn't work because myobj isn't bound correctly yet, right?
10:51Chouserrhickey_: yes. has to be for proxy, right?
10:52rhickey_yes, 'this is bound to this in all proxy fns
10:52rhickey_(mymethod [] this) should work
10:52Chouserrhickey_: oh! great.
10:52ChouserLau_of_DK: are you not getting java.lang.ClassCastException: java.lang.Integer cannot be cast to java.awt.Color
10:53Lau_of_DK(getRGB) always returns an int, even in Rich's example
10:56Lau_of_DKChouser, if I compile the whole thing, I get "IllegalArgument xception ISeq from: Symbol) but its pretty unclear whats firing it
10:57ChouserLau_of_DK: I think I'm seeing the same exception
10:59Chouseranyone know how to get java to print the full stack trace instead of ending with "... 18 more" ?
11:00Lau_of_DKIn SBCL you can set *break-on-signals* t
11:00Lau_of_DKIf you want to break on signals that is
11:01Lau_of_DKChouser, the exception comes when (go) tries to map the send-off, so setup might not be returning something that you can Iseq
11:01Lau_of_DKbut this should affect the painting at this stage?
11:08ChouserLau_of_DK: you need a [] after (defn go
11:11ChouserLau_of_DK: I don't think you need (getRGB) at all -- just create the color object and pass that.
11:12Lau_of_DKAnd can test it, but can you see why it doesnt update the panel at all ?
11:12Chouser...and did you change setup? It looks like it used to return a seq of agents (as created by spawn-ant), but is now returning a seq of StructMaps (as returned by alter)
11:13Lau_of_DKyea, that was my mistake. I had to modify some of it. Now Ive simply moved the for loop to the bottom, which should return the ants, but instead it throws an error ala "No transaction running"
11:14Lau_of_DKAnd thats an illegal state exception
11:16ChouserI'm not seeing that.
11:17lisppaste8Lau_of_DK annotated #61762 with "setup-modded" at http://paste.lisp.org/display/61762#1
11:17Lau_of_DKAre you running it like that annotation ?
11:18Chousernope. You had two separate loops before, and now have them nested?
11:18Lau_of_DKyea
11:19Lau_of_DK(doall is a nest, and (dosync is another
11:20Lau_of_DKBut was does "no transaction running" mean? I was under the impression that dosync started a transaction
11:20Chouserto fit with the rest of the code, setup need to return a seq of agents.
11:21Lau_of_DKYes - And I suppose it will do that, if I get past that exception, right?
11:21Chouserwith your annotation, you've got an "alter coordiante" outside any sync
11:21Chouserand I think setup is returning a seq of alternating structmaps and agent-seqs.
11:22Lau_of_DKok, well I guess thats just a matter of applying a sequences structure to them, but I really dont get that exception, where does it come from? Even if I wrap the top-nest in a dosync, it still fires
11:24Lau_of_DKok, merged the loops, now it looks like its working
11:24Chousergreat
11:25Lau_of_DKYea - btw, thanks alot for helping out - I really hate these first few days with a new language, can feel abit like slamming your head against a wall :)
11:33lisppaste8Lau_of_DK annotated #61762 with "setup-working" at http://paste.lisp.org/display/61762#2
11:34Lau_of_DKThat works. It alternates all the colors in a transaction and creates a sequence of ants on locked start-positions. But it does not motivate the program to render anything on the panel
12:04lisppaste8Lau_of_DK pasted "Ants-mod" at http://paste.lisp.org/display/61767
12:04Lau_of_DKCould somebody please have a look at this. It somewhat works. Setup initializes the board and creates ants. The frame is setup the way it should be, the only thing thats wrong is that I cannot get it to paint the panel
12:05Lau_of_DKAlso, it doesnt throw any color exceptions
12:22Lau_of_DKAny ideas are welcome, Ive got nothing to go on
12:22cgrandLau_of_DK: move (. g (drawImage img 0 0 nil)) in render after (dorun ...)
12:23cgrand(you have to first draw on the image, then draw the image)
12:23Lau_of_DKhaah
12:23Lau_of_DKokay cgrand , thanks alot :(
12:34Lau_of_DKman this STM approach is awesome
12:36Chousercgrand: is your js* up anywhere I can peek at it?
12:38cgrandchouser: http://code.google.com/p/clj-stuff/source/browse/trunk/clj-stuff/template/js.clj#85
12:42Chousercgrand: thanks
12:42cgrandchouser: "process-form" is where the action tooks place
12:43cgrand(some examples: http://code.google.com/p/clj-stuff/wiki/TemplatingExamples#Javascript_HTML_templating_examples)
12:48Chousercgrand: cool.
12:48Chouserthe destructering is fantastic. ;-)
12:49cgrandthanks to macroexpand-1 :-)
12:50Chouserkeywords in function position are automatically evaluted instead of translated?
12:55cgrandHmm... a keyword in function position is handled by the default case of process-form: translating to a function call (and :kw becomes the identifier kw in js)
12:56cgrandso (:kw {:kw 1}) doesn't produce anything useful
13:33lisppaste8cgrand pasted "for chouser" at http://paste.lisp.org/display/61773
13:40Chouserhm. So what does (:id item) do in the wiki example?
13:47cgrandchouser: dynamically inserting the value of (:id item) (I was using an awkward special symbol named "jstr" but I changed that to support quote instead, I updated the wiki example)
13:55Chouserah, I see. great.
13:55cgrand(jstr "#" (:id item) " a") meant at *runtime* evaluate (str "#" (:id item) " a") -- keep in mind that's a templating lib so some parts are static (and serialized once for all) and some are dynamic (and jstr (now quote) is delimiting dynamic parts)
13:56Chouseryup.
13:58Chouserit's very interesting. I'm not sure, but I think it's slightly different than what I was imagining.
13:58ChouserOr maybe you're just using it differently than I had in mind.
14:00Chouserof the 38k lines of JS I mentioned yesterday, none of it is generated dynamically. It's all static .js files.
14:01rsynnottyargh
14:06cgranda simple use case is passing values computed by the server to the client-code eg generating something like: init({some: "js", data: structure}) (init being defined in an external js file)
14:09Chousersure. we do that, but the json is converted from C++ data structures instead of clojure ones.
14:09ChouserWhat intruiges me would be the possibility of replacing the 38k lines of JS with some smaller amount of clojure.
14:10cgranda complex use case is generating client-side templating functions from their server-side counterparts
14:10rsynnottcommon lisp has a very nice js generator thing; wonder has anyone done anything similar for clojure?
14:12cgrandchouser: by "some smaller amount of clojure", do you really mean Clojure or some notation for JS code?
14:13Chouserwell... that's a good question. I mean something very very close to clojure.
14:14Chouser...as was discussed here yesterday.
14:14ChouserNo sync or agents, but probably PersistentHashMaps and Vectors.
14:16ChouserI want to be able to use some (most?) of the Clojure idoims, instead of some new idioms required by a goofy offspring of JS and Clojure.
14:29Lau_of_DKCan somebody explain some of the syntax from Rich's ant simulator? In (behave) he sometimes has this action (-> loc drop-food (turn 4)) what is that?
14:34Chouser-> is a macro that pass each expression as the first argument of the next expression
14:34Chouserit turns it turns it inside-out, so that becomes: (turn (drop-food loc) 4)
14:38Chouserman, I can't type. sorry.
14:40Lau_of_DKman thats a weird macro, is that widely used in your programs?
14:42ChouserIt's nice in limited context where it's easier to read the other way around.
14:42Chouser...and it saves parens, which is great in this economy with the high paren prices and all.
14:42Lau_of_DKok, well thanks alot for the explanation, Im glad I didn't go with my intuition
14:51rapidorich, have you considered using treaps for set operations?
14:52rapidohere's the paper: http://www.cs.cmu.edu/afs/cs.cmu.edu/project/scandal/public/papers/treaps-spaa98.pdf
14:52rapidoa nice property of a treap is that they always turn into the same structure, independent of insertion order
14:53rapidoi think clojure has the right default: immutability will save the world ;)
14:54rapidowith persistents treaps the set operations, such as union, difference, etc can be made optimal
15:14lisppaste8Lau_of_DK pasted "Almost-Ants" at http://paste.lisp.org/display/61777
15:14Lau_of_DKChouser, - or anybody really - Can somebody tell me why behave looks like its executing once, and then returns nil and the program "halts"
15:14Lau_of_DK?
15:35Lau_of_DKGood question huh? :)
15:38Chouserwhy does it "#'behave" instead of just "behave". Rich's original does too.
15:38Lau_of_DKIm not sure
15:43Chouserwell, that code's still throwing an exception for me, regarding color.
15:44Lau_of_DKreally?
15:44Lau_of_DKThats "impossible", I've removed all those
15:44Lau_of_DKSure you loaded a fresh file in a fresh repl ?
15:45Chouseryeah, it's the 0 on line 25
15:46Lau_of_DKargh, you've got sharp eyes
15:46Lau_of_DKOr do you have some type of debugging tool that told you ?
15:47Chouserno, I'm running the thing and it crashes.
15:47Chouserjava gives me a stack trace.
15:48Chouserthe reason you only get one cycle appears to be because of a crash in the agent function as well.
15:49Chouserjava.lang.NullPointerException at clojure.fns.user.behave__1888.invoke(ant.clj:99)
15:49Lau_of_DKby "the agent function" you mean (behave) ?
15:51Chouserlooks like it. I just meant that because the crash is from inside an agent, it doesn't get reported as conveniently.
15:52ChouserI don't really know this code at all, so I'm learning as I go here.
15:56Lau_DKSorry Chouser , Gnome just crashed, last thing I got was you said some invoke error on line 99
15:57Chouserok. Yes, I guess I meant (behave). But the reason I didn't say that is I wasn't sure which function the agent was running when the exception was thrown.
15:57ChouserI don't really know this code at all, so I'm learning as I go here.
15:58Lau_DKah ok. Well I really appreciate you taking the time, just let me know if its too much. But before you say stop - What could cause that error in behave? Basically its just (move loc) loc) - thats it
15:59Chousersomehow the locs are getting set to nil.
16:02Lau_DKFor some odd reason I'm not getting the debug information that you are
16:03Lau_DKTo me it just runs, then stops
16:05Chouseroh, nevermind. it's still running, just the ants aren't going anywhere.
16:05Lau_DKOh - So it just returns nil after having sent off every ant?
16:05Chouserno, I was wrong about nit
16:06Chousernil
16:06Chouser(cond (not (:ant @ahead))
16:07Chouser (move loc))
16:08Chouser(:ant @ahead) seems to always return a hash, which is true, so (move loc) never gets called
16:09Lau_DKI just removed the whole cond, so its only (move loc) loc)
16:09Chouser...and I wasn't completely wrong about nil. (behave) used to return loc from inside the sync, but your version it's outside the sync. That seems to matter.
16:09Lau_DKstill just stays in the middle... but move seems to work when I test it in repl
16:10ChouserLau_DK: I think you've made more changes than you realize or something.
16:10Chouserwe've found several of these functions are returning different types of objects than they used to.
16:10Lau_DKIve made quite a few - But there's quite a gab in the purpose of the applications, they just share the name and the need for drawing a JPanel :)
16:10Chouseryou might want to back out your changes and make them more incrementally, testing as you go.
16:10Lau_DKI'll right, I'll run through the whole thing
16:11Chouseroh. well, in that case you might try starting from scratch and writing just what you need.
16:11ChouserIt's hard to change a program correctly without understanding what's already there.
16:11Lau_DKYea, maybe I should. I just figured I'd be an easy way to learn som basic clojure
16:11Lau_DKConsidering I've heard Rich explain most of it on a video
16:11ChouserI'm not sure that demo counts as "basic clojure" ;-)
16:11Lau_DKhehe - I would actually agree
16:12Chouseranyway, I'm done for now. good luck.
16:12Lau_DKThank you so much for your help
16:13Chouserif you want to tell me why I can't get my jtable to use a monospace font, that'd be great.
16:13Chouseractually, I think I need to punt on that problem as well.
16:13Lau_DKDid you set the font in the cell renderer?
16:14Lau_DKperhaps you should check out the API doc for this table.setDefaultRenderer(Object.class, new TableCellRenderer());
16:16Chouseryeah, I've got all that. And I can create and set the font, but only the size and style seem to actually get applied. The font family is ignored.
16:48Lau_DKSince progn is removed from clojure, what do we use instead?
16:50Chouserdo
16:51Lau_DKthanks, btw. Chouser , ants are moving now :)
16:51Chousernice
16:51Lau_DKYea, when you can change the code while the GUI is running, you really have an advantage
18:54Lau_DKChouser, you still up ?