#clojure logs

2008-09-14

02:24Guest55704I have a basic clojure question regarding loops...
02:25tgreenum...anybody awake atm?
02:26arbschtask your question anyway
02:27tgreenok. so I'm attempting to create a 2D array like this ((1111)(2222)(3333)(4444)).
02:27tgreencode: ( let [x 1] (replicate 4 (replicate 4 x ) ))
02:28tgreenthis get's me to ((1111)(1111)...), but I'm a bit unclear on how to increment x
02:29arbschtthat's a list of lists, btw, not an array
02:30arbschtperhaps you could do something like (map (partial replicate 4) (list 1 2 3 4))
02:31tgreencool. so the clojure/lisp way is instead of passing in a var and incrementing in a loop, you reference a list and iterate over that list.
02:32arbschtif you wanted to use loop, you could do that too
02:37arbschthere's a quick first pass at doing it with loop http://paste.lisp.org/display/66794
02:37tgreenthanks. looking at it now.
02:41tgreenok. so you can mutate local variables? docs "(inc x) returns a number one greater than num", so within the loop, there is an implicit let, and that means we can mutate x?
02:42arbschtyou can rebind variables in a loop using recur
02:42arbschtit's not mutation
02:45tgreenok. thanks again.
07:53achim_phi!
07:54achim_pi'm trying to evaluate forms to be loaded from a file with a given binding. i tried using "load-...", with no success:
07:54achim_p(let [x 2] (load-string "x")) ;=> Unable to resolve symbol: x in this context
07:54achim_pany ideas?
09:50Chouserachim_p_: not quite sure what you're trying to do, but perhaps try "binding" instead of "let"?
10:17achim_p_Chouser: it's for a small html templating lib i'm writing. i'd like to have template files with something like (html (body (h1 -page-title-))) and then use (template [-page-title- "Foo"] "templatefile.tmpl") to get the html. so rebinding globals wouldn't help in this case, but thanks for your suggestion!
10:18achim_p_got it working now (i think), using read and macros
10:19Chouserok
11:00achim_p_erm, probably a rather strange question: is there a way to get to the 'contents' of a LispReader$Unquote?
11:00lisppaste8achim_p pasted "unquote" at http://paste.lisp.org/display/66807
11:15rhickeyachim_p_: the use of unquote outside of syntax-quote is undefined and unsupported
11:25achim_p_rhickey: okay, thanks! i was afraid it would be ...
12:53meredyddHey all. What's happened to load-resource, now contrib.lib-type functionality has been pulled into mainline?
13:07Chousermeredydd: renamed to just load
13:07meredyddOkay...
13:07meredydd...ah.
13:08meredyddMuch nicer. And I see it's in the (ns) macro now...excellent.
15:39ChouserI thought I'd seen obfuscated JS before, but nothing as perverse as this.
15:45rhickeyoh, yeah
15:46rhickeyLinj was an attempt to generate readable Java from a Lisp, but the Lisp was sort of like Java-with-parens
15:48ChouserHaving real closures is nice on the emit side, but what you end up with is deeply nested impenetrableness.
15:50rhickeystill, there are only a handful of primitive expressions, so once you get them right, arbitrary nesting, while scary looking, is still reliable
15:53Chousersure. But they're not right yet. ;-)
15:54ChouserRight now I've got a local (generated by a macro) that is getting called but never initialized.
15:54ChouserMaybe I shouldn't be trying "for" quite yet. :-)
15:55rhickeyprobably not :)
16:11Chouserah, I've got a localbinding for the enclosing fn, but I'm not initializing it.
16:15ChouserHm, how can I know which of FnMethod's locals refers to the FnExpr?
16:19rhickeyChouser: why would you need to do that?
16:21ChouserThe body of a named fn is apparently using a localbinding to talk about itself. I see this localbinding in the fnmethod's locals list, but I don't see how I'm supposed to know it's talking about this fn.
16:22Chouser(fn forever [] (forever))
16:22Chouseroh, I guess it's going to have the same name.
16:23Chouserof course that's rather a recurring feeling with this project.
16:29achim_p_hi! final question for today :) - how to locate (by absolute path or url) a resource on the classpath as it would be found by "load"? i tried (.findResource (RT/baseLoader) file), which yielded nil, which confuses me, since both load and (.getResourceAsStream (RT/baseLoader) file) work.
16:31rhickeyachim_p_: use getResource
16:34rhickeyChouser: yeah, I don't need to deal with that because I get the fn as 'this'
17:03achim_p_rhickey: okay, so no paths, i reckon ... it's probably better not to rely on cp entries mapping to fs paths anyway - thanks!
17:04rhickeyachim_p_: right, if you use the API you don't care where they are
17:35tgreen<newbie question> how do i make a list of increasing numbers? i've given this a shot : http://paste.lisp.org/display/66830
17:36rhickeytgreen: (range 10)
17:36tgreenthanks!
17:38tgreenbtw - i've read the website and i'm attempting to understand this language. But it's pretty different from what I'm used to (java/python/c#). Any pointers to references/tutorials to jumpstart seasoned developers that know nothing about lisp?
17:38tgreenfor instance, this was a great help : http://www.moxleystratton.com/article/clojure/for-non-lisp-programmers
17:41tgreenfor instance, I'm attempting to bootstrap my way into clojure by writing simple code samples in python, and then attempting the same thing in clojure. like, rotate an NxN matrix 90 degrees. that sort of thing. but i'm constantly running into issues like, how do i dereference a 2 d array? ...etc.
17:41rhickeytgreen: there's also the wiki: http://en.wikibooks.org/wiki/Clojure_Programming, and this series: http://writingcoding.blogspot.com/2008/06/clojure-series-table-of-contents.html
17:45tgreentwo great links. thanks again. i can't wait to have that 'aha' moment w/ clojure.
18:14Chousertgreen: I frequently recommend projecteuler.net for set of tasks that gently increase in complexity.
18:15ChouserI'm afraid that's more on the side of giving you questions than it is answering them.
18:18tgreenChouser: that's great! good for interview practice and general skills.
18:30Chouserit's what convinced me that Rhino's not ready for general-purpose programming. :-)
18:41arohneris it bad form to do: (dosync #( foo))?
18:45ChouserI wouldn't think so.
18:46ChouserBut this is not a strong area for me. ;-)
18:46arohnerI find myself commonly writing functions that are "do the thing I care about", and then a separate function to "do stuff to the ref"
18:46arohneri.e.
18:47arohner(def ref_struct (ref my_struct))
18:47ChouserI think that general pattern has actually been recommended by rhickey.
18:47arohner(def do_stuff [my_struct])
18:47arohner(def ref_do_stuff [ref] (dosync #(do_stuff %)))
18:47achim_p_rhickey: can't boot.clj's root-directory fn be public? otherwise it's hard to implement classpath loading that is consistens with load's path handling
18:48achim_p_(see paste)
18:48lisppaste8achim_p pasted "resource-stream" at http://paste.lisp.org/display/66837
18:53Chouserarohner: oh, maybe it's better to do have (def compute_stuff [my_data]) (def do_stuff [ref] (dosync (alter compute_stuff ref)))
18:53Chouserthat is, one func that knows how to do the work on that kind of data, regardless of whether it's in a ref or not.
18:54arohnerright
18:54Chouser...and then another func that knows how to apply that work to a ref.
18:54arohneryeah, that's what I've been doing
18:54rhickeyarohner: you should end up with more pure fns than transactional ones.
21:38Chouserhttp://n01se.net/paste/23H -- t01.cljs: ClojureScript, works in FF3 and Chrome
21:39rhickeycool!
21:39rhickeyshowing off with for, eh? :)
21:42rhickeywhat does that generate?
21:52Chouseryeah, showing off. what's the point in using clojure if you don't do something JS can't. :-)
21:53rhickeyI think it's great - congrats!
21:53Chouserheh, thanks.
21:53Chouserstill lots to do. Probably a little bit in the emit code, but a whole lot of RT
21:54rhickeyyeah, the runtime is not nothing...
21:57Chouseremits: http://n01se.net/paste/4m8
21:57Chouserit's all checked into clojure-contrib/clojurescript
21:59Chouserthat includes the clojure patch, which makes a bunch of Expr classes public and adds *allow-unresolved-var*
22:06rhickeyI was thinking about the vars thing, it seems like a big loss to just ignore var resolution. One option is to interpret defs during compilation just establishing the vars (not evaluating the init expr). top-level do can unroll its contents into the top level. Then the only thing you wouldn't resolve would be truly nested defs
22:08Chousermakes sense.
23:05Chouser:interpose might be nice to have in "for"