#clojure logs

2008-09-12

03:51mhincheyHi. How do I get the namespace for a symbol? Shouldn't (namespace 'map) return something? It always returns nil.
03:55hoeck_mhinchey: hi
03:56hoeck_mhinchey: i think because 'map is not a namespace qualified symbol, if you try (namespace 'user/map) it will return "user"
04:02mhincheyoh, I was expecting it to return "clojure" since 'map is clojure/map. What I need is something to return the Namespace object of an existing symbol. Trying ...
04:05hoeck_well, you could try (resolve 'map), but this gives you only the var-object, not the namespace
04:09mhincheythanks, this is what I need: (:ns ^(resolve 'map))
04:13hoeck_mhinchey: (ns-name (. (resolve 'map) ns))) would do the job
04:14mhincheyhoeck, thanks, this is what I need: (:ns ^(resolve 'map))
04:17mhincheybut that would work too
04:20hoeck_ahh, metadata, haven't thought of that, definitely better than poking around in clojure implementation-details :)
09:19Chouser(namespace `map)
09:21rhickeyok
09:22ChouserI'm glad you agree. ;-)
09:22ChouserJust answering a question from 4am, for the record.
09:24rhickeyah
09:39Chouserhoeck_: naw, looks like you got him to an answer.
10:28ChouserThe structure I'm cobbling together for clojurescript could be mimicked to make a Clojure obfuscator.
10:29Chouserdunno how good it would be, but at least at first glance I imagine it would look pretty impenetrable.
10:31rhickeyit's not obfuscated enough?
10:40Chouseroh, the JS is plenty obfuscated. I meant one could emit Clojure source again, but a bit scrambled.
10:42rhickeyI think we should focus on clarity for a while :)
11:54jamiiIs there a prefix form of the syntax-quote reader macro?
11:55Chouser(quote foo) ?
11:55jamiiI'm after ` as opposed to '
11:55jamiiSorry - could have been clearer there
11:56Chouseroh! hm.
12:04jamiiuser=> ``a
12:04jamii(quote user/a)
12:04jamiiThats not a good sign - looks like ` might be special cased
12:04Chouseryou're trying to generate this from a macro?
12:05jamiiYep - I want a macro that takes a form, does some processing and returns the form syntax-quoted
13:59ChouserI can't think of how to do looping inside a JS expression.
13:59Chouser(conj [] (loop [i 5] (if (pos? i) (recur (- i 2)) i))) ==> -1
13:59ChouserJS: conj( PersistentVector.EMPTY, do{..oops..}while() )
14:00Chouserwill I have to turn all expressions inside out, assigning to temp vars along the way?
14:00rhickeythe basic approach to this is, if you can't make an expression out of it, make a lambda and call it
14:01rhickeyapplies to loops, blocks, try/catch etc.
14:01Chouserhm... since this is a control structure point (unlike "let"), I guess a lambda would work fine.
14:02rhickeyessentially you/ are translating an everything-is-an-expression lang into a statement/expr lang
14:02Chouserwell, I was thinking that the comma operator would save me from some of this.
14:02rhickeysome things work (i.e. if can be ?: expr), others don't
14:03Chouserand I guess it does some, but being unable to drop a do/while into the middle of it mucks things up a littl.e
14:03rhickeycomma helps, I wished I had it when generating Java/C#
14:03rhickeythe compiler tracks what 'context' you are in - expr/statement/return
14:03rhickeymany emits have 2 flavors depending on context
14:04rhickeywhile as statement is easy, as expr needs to be lifted
14:04rhickeyer, loop
14:04Chouserok.
14:05ChouserI'm doing a lot of things the "simpler" way for now, as in what's simple to emit -- more work for JS at runtime.
14:05ChouserIf the dumb thing actually works at all then we can clean it up.
14:11rhickeyare you flowing context through tojs calls?
14:12Chouseryeah :-/
14:13Chouserclojure-contrib/clojurescript/tojs.clj
14:13ChouserI'm not passing along expr/statement/return yet, but I've got a hashmap that could hold that too if I need it.
14:14Chouserrhickey: jamii had a syntax-quite question I couldn't answer.
14:15rhickeyjamii: syntax-quote is a reader thing, can't emit from compiler/macro
15:14Chousershould clojurescript provide something like vars? I guess it has to if we want metadata on them and things like the "var" builtin to work.
15:17Chouserwhich would make (def foo 5) translate to something like: foo = new Var(5) instead of foo = 5
15:19Chouserand later references to foo would have to be foo.get()
15:21rhickeyChouser: it depends on how rich/compatible you want clojurescript to be
15:22rhickeydynamic binding is the big var feature
15:23Chouserah, push/pop. Hm.
15:24ChouserI guess there's still a little value in that, even when in single-threaded JS.
15:24achim_phi! in case anyone's interested in a browser based doc ...well... browser, i made one today: http://launchpad.net/clojure-docbrowser/trunk/0.1/+download/docbrowser.tbz2
15:24achim_pit's a quick hack, very much unfinished. but perhaps it's useful to someone. jetty is required to run it. still needs lots of work - contributors welcome! :)
15:25rhickeyChouser: also indirection in referencing globals, defs go into vars, and you can pass the var around. If you use global js names, what would you pass around strings?, and how would you resolve - eval? hmm...
15:26Chouserachim_p: that's a pretty little servlet you've got there. nice.
15:27Chouserrhickey: well, I don't pass vars around much, but I suppose (var foo) needs to return something.
15:28rhickeyChouser: it doesn't necessarily, just thinking through the implications. Will there be symbols?
15:29ChouserI've punted so far on symbols and keywords, but I can't do that forever.
15:31rhickeyyour fiddling with js has made me think about cranking out AOT Java like I said the other day. That would give you a model, but doesn't solve the 'how much of a runtime' problem for you
15:38Chouserwell, don't let me distract you from something people actually want. Like better error messages for example. ;-)
15:39rhickeybetter error messages is too generic to implement
15:41cemerickrhickey: I had no idea you were considering generating java source as a path to AOT. I would have thought that asm would give you the raw materials you needed to emit classfiles from scratch.
16:00achim_pChouser: thanks for having a look! it's a bit paltry. i'd love to see some tool like this done properly, but am lacking both time and gui skills, i'm afraid
16:01ChouserI've got several little projects (mostly web-based) that I'd like to put together, but although they would be possible with Clojure as it is, I think it'll be more fun (for me!) to get more infrastructure in place first.
16:02Chouserthings like clojurescript, gxp, and maybe some alternative to sql for on-disk storage.
16:07ozzileerhickey: Out of curiosity, what do you mean by better error messages being too generic to implement?
16:09rhickeyozzilee: it's a generic request. Each scenario is different. I'd need examples: I typed this, it said that...
16:10ozzileerhickey: Ah. Gotcha.
16:10rhickeybut the general aversion to stack traces is something I don't relate to at all. The cause is now at the top, the rest is easy to ignore
16:11rhickeyif there are common errors/patterns then that is something to go after
16:13rhickeythe big-ticket items I'm interested in: datalog, AOT compilation, JavaScript generation, abstraction of queues/JMS
16:15ozzileeI hacked this together over my lunch break: http://pastie.org/271445
16:16ozzileeI think something like that would be helpful, where it would print out the actual forms that caused the error.
16:16rhickeyI just don't see what's unclear about: Unable to resolve symbol: foo in this context
16:17ozzileerhickey: Well, with just a single line on the Repl it's obvious, but more complicated stuff is... more complicated.
16:17rhickeybut one thing is true, evaling right at the repl takes away line numbers, which would be present if code was loaded instead
16:17ozzileerhickey: Yeah, the line numbers are nice for loaded code.
16:20ozzileeAnd honestly, the 20-odd lines of stack traces are pretty useless in this case, and I think most others as well.
16:20rhickeyno one's forcing you to read it :)
16:21rhickeybut it would be easy to have to repl store it away and print only the cause message, with the rest available on request
16:21rhickeypatch welcome
16:21ozzileeWell, yeah, but it does force me to scroll up on the Repl to see what I was doing. Not a deal-breaker, just an annoyance.
16:21ozzileerhickey: Yeah, I like that idea, I might dick around with it tonight.
16:22ChouserI wonder how easy/useful it would be to do the -----^ style ascii-art pointer.
16:22ozzileeSomething like (print-stack-trace) you think? (print-last-stack-trace) ?
16:24ozzileeChouser: I always thought lining up the sexps would be pretty, myself :-) http://pastie.org/271445
16:25Chouserheh. You'd have to teach me how to read that output.
16:26ozzileePerhaps (.throw *last-exception*)... ho hum.
16:28ozzileeChouser: Yeah, it'd probably make more sense reversed and cleaned up: http://pastie.org/271445.
16:28ozzileeAnyway. Back to work.
16:35achim_pi'd like every var defined in the repl to be annotated with its defining form as metadata. would i have to doctor clojure's internals to achieve this or is there an easier way i don't see right now?
16:35achim_pe.g.:
16:35achim_p(defn foo [x] "test")
16:35achim_p(:def ^#user/foo)
16:35achim_p=> (defn foo [x] "test")
16:37Chouseryou could probably write your own def macro
16:48achim_pthat would be an option ... but it won't work for the stuff in boot.clj, obviously, and i believe it wouldn't work for code that gets loaded into different namespaces either
16:49rhickeythe file and line number are already in the metadata, you could just find the code
16:56achim_pthe filenames are class-path-relative, right?
16:57achim_pwrong :)
18:39defunkthey guys, clojure looks awesome
18:40defunkti've never done any java - is that going to be a big problem as i try to learn it?
18:43arbschtnot a big problem
18:43arbschta small one, perhaps :)
18:43defunktheh
18:44arbschtdefunkt: what is your programming history?
18:45defunktmost recently a lot of lisp, objective-c, and ruby
18:46arbschtyou should not have much difficulty, then
18:46defunktexcellent
18:52fyuryudefunkt: you'll probably need to learn something about classpath for java interop (but not only)
22:39gnuvince_How would I open an URL and download the entire content with Clojure? I don't know any Java.
22:40arohnergnuvince_: clojure would rely on the java libraries to do that
22:40arohnerI don't know enough java to help you, I've only started to learn java because of clojure
22:41gnuvince_I found this URL class in java.net, but I can't seem to "finish the job"
22:46arohnerlisppaste8: help
22:46lisppaste8To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste.
22:50lisppaste8arohner pasted "print-url" at http://paste.lisp.org/display/66740
22:50arohnertry that
22:51gnuvince_arohner: very kind of you
22:51arohnerbtw, I stole the java example of this from http://www.devdaily.com/java/edu/pj/pj010011/pj010011.shtml
22:52arohnerfeel free to ask any questions about how it works or why I did it that way
22:53gnuvince_Only one question
22:53gnuvince_If I wanted to accumulate this into a string, how'd I do that?
22:56lisppaste8arohner pasted "str-url" at http://paste.lisp.org/display/66741
22:56arohnerI'm not entirely sure about the performance of this, but it works
22:58gnuvince_arohner: doesn't matter, I'm currently more interested in exploring Clojure
22:59arohnerdo you understand how the code works?
23:00gnuvince_Yes
23:00gnuvince_I'm pretty familiar with Lisp and functional programming in general, but Java is a complete mystery to me.
23:00arohneryeah
23:01arohnerI learned C & C++, then completely skipped java and learned python, ruby, lisp
23:01arohnernow I find myself pushed to learn java because clojure is so nice
23:01gnuvince_I went the other way, Ruby, Python, Lisp, OCaml and then went to C.
23:03albinoOcaml even
23:03gnuvince_Right now, Clojure is at #2 on my list of interesting languages
23:04arohnerwhat is #1?
23:04albinognuvince_: do you have a bunch of sample programs you right code in to learn languages?
23:04albinos/right/write
23:04albinoman it's been a long week
23:05gnuvince_arohner: Haskell. Crazy, crazy language :)
23:05gnuvince_albino: usually I start with the usual little stuff like fib and fact and stuff, I like to write a Cribbage point counter
23:06gnuvince_For clojure, I was thinking of porting my Python script to scrape a bunch of comic sites and generate an XML file
23:06gnuvince_I figured I'd see if I can make it concurrent
23:06albinofirst google hit even http://gnuvince.wordpress.com/2008/02/06/cribbage-point-counter-in-haskell/
23:06gnuvince_Though I'm probably gonna have to take a break from it, read a little more on clojure, and then come back to the problem
23:07gnuvince_albino: that's me.
23:07albinognuvince_: I figured based on the subdomain
23:08gnuvince_Mind you, I got better code. Somebody showed me the Enum type class in Haskell which makes a couple functions pointless
23:09arohnerman, I should learn haskell
23:10arohnerI find it irritating that I can figure my way through most languages, but haskell is very hard to intuit
23:10gnuvince_arohner: it's a lot of fun and it completely obliterates the brain :)
23:10gnuvince_Oh yeah, me too
23:10gnuvince_I picked up quite a few languages since I started programming
23:10gnuvince_but I needed to try Haskell 4 times before it finally clicked
23:10gnuvince_It's one weird puppy
23:15ChouserFWIW, I like projecteuler.net for trying out a new language
23:20albinognuvince_: ahh, python
23:20gnuvince_albino: yah, my main language
23:21albinognuvince_: mine also