2008-09-12
| 03:51 | mhinchey | Hi. How do I get the namespace for a symbol? Shouldn't (namespace 'map) return something? It always returns nil. |
| 03:55 | hoeck_ | mhinchey: hi |
| 03:56 | hoeck_ | mhinchey: i think because 'map is not a namespace qualified symbol, if you try (namespace 'user/map) it will return "user" |
| 04:02 | mhinchey | oh, 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:05 | hoeck_ | well, you could try (resolve 'map), but this gives you only the var-object, not the namespace |
| 04:09 | mhinchey | thanks, this is what I need: (:ns ^(resolve 'map)) |
| 04:13 | hoeck_ | mhinchey: (ns-name (. (resolve 'map) ns))) would do the job |
| 04:14 | mhinchey | hoeck, thanks, this is what I need: (:ns ^(resolve 'map)) |
| 04:17 | mhinchey | but that would work too |
| 04:20 | hoeck_ | ahh, metadata, haven't thought of that, definitely better than poking around in clojure implementation-details :) |
| 09:19 | Chouser | (namespace `map) |
| 09:21 | rhickey | ok |
| 09:22 | Chouser | I'm glad you agree. ;-) |
| 09:22 | Chouser | Just answering a question from 4am, for the record. |
| 09:24 | rhickey | ah |
| 09:39 | Chouser | hoeck_: naw, looks like you got him to an answer. |
| 10:28 | Chouser | The structure I'm cobbling together for clojurescript could be mimicked to make a Clojure obfuscator. |
| 10:29 | Chouser | dunno how good it would be, but at least at first glance I imagine it would look pretty impenetrable. |
| 10:31 | rhickey | it's not obfuscated enough? |
| 10:40 | Chouser | oh, the JS is plenty obfuscated. I meant one could emit Clojure source again, but a bit scrambled. |
| 10:42 | rhickey | I think we should focus on clarity for a while :) |
| 11:54 | jamii | Is there a prefix form of the syntax-quote reader macro? |
| 11:55 | Chouser | (quote foo) ? |
| 11:55 | jamii | I'm after ` as opposed to ' |
| 11:55 | jamii | Sorry - could have been clearer there |
| 11:56 | Chouser | oh! hm. |
| 12:04 | jamii | user=> ``a |
| 12:04 | jamii | (quote user/a) |
| 12:04 | jamii | Thats not a good sign - looks like ` might be special cased |
| 12:04 | Chouser | you're trying to generate this from a macro? |
| 12:05 | jamii | Yep - I want a macro that takes a form, does some processing and returns the form syntax-quoted |
| 13:59 | Chouser | I can't think of how to do looping inside a JS expression. |
| 13:59 | Chouser | (conj [] (loop [i 5] (if (pos? i) (recur (- i 2)) i))) ==> -1 |
| 13:59 | Chouser | JS: conj( PersistentVector.EMPTY, do{..oops..}while() ) |
| 14:00 | Chouser | will I have to turn all expressions inside out, assigning to temp vars along the way? |
| 14:00 | rhickey | the basic approach to this is, if you can't make an expression out of it, make a lambda and call it |
| 14:01 | rhickey | applies to loops, blocks, try/catch etc. |
| 14:01 | Chouser | hm... since this is a control structure point (unlike "let"), I guess a lambda would work fine. |
| 14:02 | rhickey | essentially you/ are translating an everything-is-an-expression lang into a statement/expr lang |
| 14:02 | Chouser | well, I was thinking that the comma operator would save me from some of this. |
| 14:02 | rhickey | some things work (i.e. if can be ?: expr), others don't |
| 14:03 | Chouser | and 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:03 | rhickey | comma helps, I wished I had it when generating Java/C# |
| 14:03 | rhickey | the compiler tracks what 'context' you are in - expr/statement/return |
| 14:03 | rhickey | many emits have 2 flavors depending on context |
| 14:04 | rhickey | while as statement is easy, as expr needs to be lifted |
| 14:04 | rhickey | er, loop |
| 14:04 | Chouser | ok. |
| 14:05 | Chouser | I'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:05 | Chouser | If the dumb thing actually works at all then we can clean it up. |
| 14:11 | rhickey | are you flowing context through tojs calls? |
| 14:12 | Chouser | yeah :-/ |
| 14:13 | Chouser | clojure-contrib/clojurescript/tojs.clj |
| 14:13 | Chouser | I'm not passing along expr/statement/return yet, but I've got a hashmap that could hold that too if I need it. |
| 14:14 | Chouser | rhickey: jamii had a syntax-quite question I couldn't answer. |
| 14:15 | rhickey | jamii: syntax-quote is a reader thing, can't emit from compiler/macro |
| 15:14 | Chouser | should 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:17 | Chouser | which would make (def foo 5) translate to something like: foo = new Var(5) instead of foo = 5 |
| 15:19 | Chouser | and later references to foo would have to be foo.get() |
| 15:21 | rhickey | Chouser: it depends on how rich/compatible you want clojurescript to be |
| 15:22 | rhickey | dynamic binding is the big var feature |
| 15:23 | Chouser | ah, push/pop. Hm. |
| 15:24 | Chouser | I guess there's still a little value in that, even when in single-threaded JS. |
| 15:24 | achim_p | hi! 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:24 | achim_p | it'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:25 | rhickey | Chouser: 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:26 | Chouser | achim_p: that's a pretty little servlet you've got there. nice. |
| 15:27 | Chouser | rhickey: well, I don't pass vars around much, but I suppose (var foo) needs to return something. |
| 15:28 | rhickey | Chouser: it doesn't necessarily, just thinking through the implications. Will there be symbols? |
| 15:29 | Chouser | I've punted so far on symbols and keywords, but I can't do that forever. |
| 15:31 | rhickey | your 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:38 | Chouser | well, don't let me distract you from something people actually want. Like better error messages for example. ;-) |
| 15:39 | rhickey | better error messages is too generic to implement |
| 15:41 | cemerick | rhickey: 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:00 | achim_p | Chouser: 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:01 | Chouser | I'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:02 | Chouser | things like clojurescript, gxp, and maybe some alternative to sql for on-disk storage. |
| 16:07 | ozzilee | rhickey: Out of curiosity, what do you mean by better error messages being too generic to implement? |
| 16:09 | rhickey | ozzilee: it's a generic request. Each scenario is different. I'd need examples: I typed this, it said that... |
| 16:10 | ozzilee | rhickey: Ah. Gotcha. |
| 16:10 | rhickey | but 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:11 | rhickey | if there are common errors/patterns then that is something to go after |
| 16:13 | rhickey | the big-ticket items I'm interested in: datalog, AOT compilation, JavaScript generation, abstraction of queues/JMS |
| 16:15 | ozzilee | I hacked this together over my lunch break: http://pastie.org/271445 |
| 16:16 | ozzilee | I think something like that would be helpful, where it would print out the actual forms that caused the error. |
| 16:16 | rhickey | I just don't see what's unclear about: Unable to resolve symbol: foo in this context |
| 16:17 | ozzilee | rhickey: Well, with just a single line on the Repl it's obvious, but more complicated stuff is... more complicated. |
| 16:17 | rhickey | but one thing is true, evaling right at the repl takes away line numbers, which would be present if code was loaded instead |
| 16:17 | ozzilee | rhickey: Yeah, the line numbers are nice for loaded code. |
| 16:20 | ozzilee | And honestly, the 20-odd lines of stack traces are pretty useless in this case, and I think most others as well. |
| 16:20 | rhickey | no one's forcing you to read it :) |
| 16:21 | rhickey | but it would be easy to have to repl store it away and print only the cause message, with the rest available on request |
| 16:21 | rhickey | patch welcome |
| 16:21 | ozzilee | Well, 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:21 | ozzilee | rhickey: Yeah, I like that idea, I might dick around with it tonight. |
| 16:22 | Chouser | I wonder how easy/useful it would be to do the -----^ style ascii-art pointer. |
| 16:22 | ozzilee | Something like (print-stack-trace) you think? (print-last-stack-trace) ? |
| 16:24 | ozzilee | Chouser: I always thought lining up the sexps would be pretty, myself :-) http://pastie.org/271445 |
| 16:25 | Chouser | heh. You'd have to teach me how to read that output. |
| 16:26 | ozzilee | Perhaps (.throw *last-exception*)... ho hum. |
| 16:28 | ozzilee | Chouser: Yeah, it'd probably make more sense reversed and cleaned up: http://pastie.org/271445. |
| 16:28 | ozzilee | Anyway. Back to work. |
| 16:35 | achim_p | i'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:35 | achim_p | e.g.: |
| 16:35 | achim_p | (defn foo [x] "test") |
| 16:35 | achim_p | (:def ^#user/foo) |
| 16:35 | achim_p | => (defn foo [x] "test") |
| 16:37 | Chouser | you could probably write your own def macro |
| 16:48 | achim_p | that 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:49 | rhickey | the file and line number are already in the metadata, you could just find the code |
| 16:56 | achim_p | the filenames are class-path-relative, right? |
| 16:57 | achim_p | wrong :) |
| 18:39 | defunkt | hey guys, clojure looks awesome |
| 18:40 | defunkt | i've never done any java - is that going to be a big problem as i try to learn it? |
| 18:43 | arbscht | not a big problem |
| 18:43 | arbscht | a small one, perhaps :) |
| 18:43 | defunkt | heh |
| 18:44 | arbscht | defunkt: what is your programming history? |
| 18:45 | defunkt | most recently a lot of lisp, objective-c, and ruby |
| 18:46 | arbscht | you should not have much difficulty, then |
| 18:46 | defunkt | excellent |
| 18:52 | fyuryu | defunkt: you'll probably need to learn something about classpath for java interop (but not only) |
| 22:39 | gnuvince_ | How would I open an URL and download the entire content with Clojure? I don't know any Java. |
| 22:40 | arohner | gnuvince_: clojure would rely on the java libraries to do that |
| 22:40 | arohner | I don't know enough java to help you, I've only started to learn java because of clojure |
| 22:41 | gnuvince_ | I found this URL class in java.net, but I can't seem to "finish the job" |
| 22:46 | arohner | lisppaste8: help |
| 22:46 | lisppaste8 | To use the lisppaste bot, visit http://paste.lisp.org/new/clojure and enter your paste. |
| 22:50 | lisppaste8 | arohner pasted "print-url" at http://paste.lisp.org/display/66740 |
| 22:50 | arohner | try that |
| 22:51 | gnuvince_ | arohner: very kind of you |
| 22:51 | arohner | btw, I stole the java example of this from http://www.devdaily.com/java/edu/pj/pj010011/pj010011.shtml |
| 22:52 | arohner | feel free to ask any questions about how it works or why I did it that way |
| 22:53 | gnuvince_ | Only one question |
| 22:53 | gnuvince_ | If I wanted to accumulate this into a string, how'd I do that? |
| 22:56 | lisppaste8 | arohner pasted "str-url" at http://paste.lisp.org/display/66741 |
| 22:56 | arohner | I'm not entirely sure about the performance of this, but it works |
| 22:58 | gnuvince_ | arohner: doesn't matter, I'm currently more interested in exploring Clojure |
| 22:59 | arohner | do you understand how the code works? |
| 23:00 | gnuvince_ | Yes |
| 23:00 | gnuvince_ | I'm pretty familiar with Lisp and functional programming in general, but Java is a complete mystery to me. |
| 23:00 | arohner | yeah |
| 23:01 | arohner | I learned C & C++, then completely skipped java and learned python, ruby, lisp |
| 23:01 | arohner | now I find myself pushed to learn java because clojure is so nice |
| 23:01 | gnuvince_ | I went the other way, Ruby, Python, Lisp, OCaml and then went to C. |
| 23:03 | albino | Ocaml even |
| 23:03 | gnuvince_ | Right now, Clojure is at #2 on my list of interesting languages |
| 23:04 | arohner | what is #1? |
| 23:04 | albino | gnuvince_: do you have a bunch of sample programs you right code in to learn languages? |
| 23:04 | albino | s/right/write |
| 23:04 | albino | man it's been a long week |
| 23:05 | gnuvince_ | arohner: Haskell. Crazy, crazy language :) |
| 23:05 | gnuvince_ | albino: usually I start with the usual little stuff like fib and fact and stuff, I like to write a Cribbage point counter |
| 23:06 | gnuvince_ | For clojure, I was thinking of porting my Python script to scrape a bunch of comic sites and generate an XML file |
| 23:06 | gnuvince_ | I figured I'd see if I can make it concurrent |
| 23:06 | albino | first google hit even http://gnuvince.wordpress.com/2008/02/06/cribbage-point-counter-in-haskell/ |
| 23:06 | gnuvince_ | 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:07 | gnuvince_ | albino: that's me. |
| 23:07 | albino | gnuvince_: I figured based on the subdomain |
| 23:08 | gnuvince_ | Mind you, I got better code. Somebody showed me the Enum type class in Haskell which makes a couple functions pointless |
| 23:09 | arohner | man, I should learn haskell |
| 23:10 | arohner | I find it irritating that I can figure my way through most languages, but haskell is very hard to intuit |
| 23:10 | gnuvince_ | arohner: it's a lot of fun and it completely obliterates the brain :) |
| 23:10 | gnuvince_ | Oh yeah, me too |
| 23:10 | gnuvince_ | I picked up quite a few languages since I started programming |
| 23:10 | gnuvince_ | but I needed to try Haskell 4 times before it finally clicked |
| 23:10 | gnuvince_ | It's one weird puppy |
| 23:15 | Chouser | FWIW, I like projecteuler.net for trying out a new language |
| 23:20 | albino | gnuvince_: ahh, python |
| 23:20 | gnuvince_ | albino: yah, my main language |
| 23:21 | albino | gnuvince_: mine also |