#clojure log - Jan 07 2012

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

0:16 sgronblom: Doesn't clojure have support for nested namespaces?

0:18 technomancy: sgronblom: no, the appearance of hierarchy in namespaces is an illusion

0:19 replaca: although a useful one. For example autodoc groups "sub-namespaces" onto the same page as their root

0:20 sgronblom: I was just extrapolating it from the fact that the clojure reader page mentions that / can be used once in a symbol to separate the namespace from the name

1:40 kprav33n: I'm new to clojure. I installed clojure 1.3 on Mac OS X Lion using homebrew.

1:42 I also installed leiningen 1.6.2 using homebrew. However, when I run 'lein help', I get the following error (ClassNotFoundException). https://gist.github.com/948e0b20da9f6ea4b517

1:42 Any pointers?

2:08 Something was badly messed up in my ~/.m2 directory that caused the problem that I mentioned above.

2:08 I blew the entire .m2 directory away and reinstalled leiningen and that solved the issue.

3:20 strager: I'm learning Clojure using 4Clojure, and I'm on a reduce problem: http://www.4clojure.com/problem/64

3:21 Why can I solve it using: (partial +)

3:21 To produce: (reduce (partial +) [1 2 3 4 5])

3:24 (I had to enter (partial + 0) to make it work.)

3:25 Well, simply "+" worked (reduce + [1 2 3 4 5]), which makes total sense.

3:26 I guess partial really wants to partially apply something, and won't take nothing for an answer.

3:30 hiredman: strager: why are you using partial at all?

3:31 ,(reduce + [1 2 3 4 5])

3:31 clojurebot: 15

3:31 strager: Because I'm new to Clojure and it was taught that functions can be created using partial.

3:31 hiredman: ,(apply + [1 2 3 4 5])

3:31 clojurebot: 15

3:31 strager: I didn't think of using just + until later.

3:31 But still, why doesn't partial work like that? Wouldn't it be more general to just accept no extra arguments and return the function?

4:13 dbushenko: hi all!

4:13 how to check whether the item is any kind of compund data structure (list,vector,map,set -- doesn't matter)?

4:16 ok, I've just found. it's 'sequential?'

6:25 zilti: I still have that "java.lang.RuntimeException: Unable to resolve symbol: pst-elem-str in this context" error when trying to "lein swank" but don't know why. I did everything written on https://github.com/mmcgrana/clj-stacktrace .

6:29 rippy: new to clojure, working on 4clojure exercises...

6:30 not sure why this is failing the = test -> http://pastebin.com/gNwirzvA

6:31 broquaint: Which problem, rippy?

6:31 rippy: the #() generates [1] but when i check to see if it's (= #() [1]) it's not equal

6:31 the pastebin has the code and the failing test

6:31 zilti: rippy: Why did you write (#( instead of #( ?

6:32 rippy: defining and invoking it, per the 4clojure test case http://www.4clojure.com/problem/99

6:33 broquaint: [\1] != [1]

6:33 rippy: ohhhhhh

6:33 thanks broquaint !

6:33 that makes perfect sense

6:33 broquaint: np :)

6:33 rippy: it's odd that the REPL doesn't print it as \1

6:33 broquaint: It does here ...

6:33 rippy: hmmm

6:34 clj -> Clojure 1.3.0

6:34 broquaint: lein repl?

6:34 rippy: on OSX, I did a "port install clojure"

6:34 sorry, really new to clojure ... just startd working on this :)

6:35 maybe my version is old from OSX ports

6:36 broquaint: 1.3.0 is the most recent, so not sure why you're seeing what you're seeing.

6:37 rippy: yeah, it outputs [1] instead of [\1] ... unless i'm misunderstanding what it should print

6:37 you are my hero though broquaint!

6:37 thanks a ton!

6:37 broquaint: np

6:38 lein is leiningen BTW, a useful clojure tool - https://github.com/technomancy/leiningen

6:38 rippy: i will check that out

6:38 any other pro-tips of packages or sites I should also check out broquaint?

6:39 broquaint: And if you're using it in conjunction with 4clojure then I wrote a plugin that might be of use - foreclojure-plugin

6:39 https://github.com/broquaint/lein-foreclojure-plugin (even)

6:39 rippy: i'm editing in vi at the moment, didn't check to see if eclipse groks clojure better yet

6:39 what do you edit in broquaint?

6:39 broquaint: Not that I can think of off the top of my head, rippy, I'm kind of a clojure newb too ;)

6:40 I use emacs to edit clojure.

6:40 rippy: i've used slime in the past for lisp stuff, maybe it supports clojure too

6:40 er emacs slime

6:40 broquaint: It does indeed.

6:40 rippy: oh nice, i'll try to get that working

6:41 broquaint: https://github.com/technomancy/swank-clojure

6:41 rippy: broquaint: i like your project! i was doing that manually

6:42 broquaint: have you been solving the 4clojure tests too by chance? i'd like to follow you to compare/contrast solutions

6:43 broquaint: Thanks, it's my first non-4clojure bit of clojure ;)

6:43 And yep, I'm on 4clojure with the same user name.

6:43 zilti: brk

6:44 broquaint: Does lein swank clojure work for you? What's your leiningen config?

6:44 broquaint: http://www.4clojure.com/user/broquaint

6:44 It does, zilti.

6:44 rippy: following you broquaint! :) i'm http://www.4clojure.com/user/rippy

6:44 broquaint: I'm just using whatever the results are.

6:45 s/results/defaults/

6:45 Ditto, rippy :)

6:45 zilti: broquaint: Did you have to manually install that clj-stacktrace plugin?

6:46 broquaint: Yup, and manually configure IIRC.

6:46 * broquaint -> AFK

6:46 zilti: Because it doesn't work for me

7:03 rippy: broquaint: nice, lein + your plugin all worked straight from OSX ports

9:01 zilti: Hmm how do I get the clj-stacktrace to actually work?

9:11 And what does "Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration loop should be a vector" mean?

9:12 gf3: zilti: it means you have probably missed the arguments vector when defining your function

9:12 (defn name [args] body)

9:14 zilti: gf3: But I've got only a defpage and a preroute in that file, and they're declared correctly

9:15 gf3: zilti: using noir?

9:15 zilti: yes

9:15 gf3: zilti: can you paste your file?

9:18 zilti: gf3: https://gist.github.com/1574853

9:20 gf3: zilti: yes, you're missing the arguments vector

9:20 zilti: (defpage [:get "/news/:category"] {:keys [category]} → (defpage [:get "/news/:category"] [] {:keys [category]}

9:21 zilti: gf3: I'll try that, but that shouldn't be necessary - the examples on the noir page don't have it either.

9:22 gf3: zilti: they do indeed

9:22 zilti: http://webnoir.org/tutorials/routes

9:22 zilti: gf3: Look at the first defpage example with parameter

9:22 gf3: zilti: although it's not in the docs

9:23 zilti: oh shi-, you're right

9:23 zilti: Now I've added [] to both the preroute and the defpage but I still get the error...

9:24 gf3: zilti: my mistake, sorry

9:24 zilti: It was worth the try. I got two of these errors before, now it's one so it seems it helped

9:36 That error seems to be unsolvable

9:45 AeroNotix: is there a function to test if all arguments return true?

9:46 cgray: AeroNotix: and

9:46 AeroNotix: cgray: derp

9:47 :P

10:25 bsteuber: is there a way to deploy a noir/compojure webapp in an uberjar such that css files are taken from an external folder respecting changes?

10:25 I tried dropping the changed files in the uberjar, but it seems the changes in there aren't monitored by compojure

10:26 zilti: Did anyone already work with forms in noir/hiccup? It seems that all that arrives are NULL values...

10:26 bsteuber: so basically I want an external designer play with the site without showing him any code

10:28 zilti: bsteuber: So where's the problem? The CSS gets fetched from where you tell the templating engine to take it from? That doesn't have to be inside the war

10:29 Oh. pre-route doesn't have access to data sent via POST

10:32 bsteuber: zilti: the only way I find to tell noir about the place is :resource-root which assumes its target to be in the classpath

10:33 I am trying along the lines of "java -cp my.jar:resources" but I didn't manage to get it work yet

10:33 zilti: bsteuber: Just give hiccup the URL to the css file

10:35 bsteuber: but it's not being served anywhere and "file:///" doesn't seem to work

10:38 jkkramer: bsteuber: what code are you using to pull in css now? include-css or [:link :rel "stylesheet" …]?

10:38 bsteuber: you should be able to use something like (include-css "/url/path/to/css") or (include-css "http://some/other/domain")

10:39 technomancy_: jkkramer: I'm heading off, but did you see this? https://github.com/Seajure/melange

10:39 jkkramer: technomancy_: i did not, cool. i will check it out. i did see your pull request about API or access to the data

10:40 bsteuber: jkkramer: (include-css "file:///path/to/css")

10:40 jkkramer: technomancy_: issue rather, not pull request

10:40 bsteuber: include-css deals with public urls, not file paths

10:40 bsteuber: jkkramer: but maybe it's better to leave it as it is and try to add resources later to the classpath

10:41 jkkramer: does that mean [:link ...] will work with local files?

10:42 jkkramer: bsteuber: include-css is just shorthand for [:link …], I believe. check out the HTML source it generates

10:43 bsteuber: hah

10:43 removing resources from the uberjar and using "java -cp resources:my.jar" did the job

10:43 jkkramer: bsteuber: see the include-css here: http://webnoir.org/tutorials/html. it just generates HTML, which refers to public URLs, not filesystem files

12:18 jodaro: hrm

12:19 is there a built in way to do something like select() on a group of lamina channels?

12:19 i can mimic it with one pretty easily with (wait-for-message (fork ch) timeout)

12:40 pandeiro: <TimMc> pandeiro: I don't know, it can get weird when you have marked-up

12:40 text. I've seen some l10n libs use format strings, actually.

12:41 ^^ this is a good point you make

12:41 I realized today while working that I'm gonna have a terrible time dealing with escaping with the way I'm doing my l10n fn

12:45 zilti: Does someone here know Pinot? I have a problem with that code I wrote, it doesn't work (just puts me onto a page with the text "null"): https://gist.github.com/1575435

12:48 TimMc: pandeiro: It's one of those things that seems so easy on the surface...

12:49 Anyone can solve 95% of the problem. :-)

12:51 pandeiro: TimMc: with Android it´s less of an issue because the strings are in an XML document... but in a Clojure file... not sure how best to deal with that... but have to go to a flat, \n-separated file

12:52 TimMc: pandeiro: You can probably do soemthing just as good with s-expressions.

12:53 pandeiro: TimMc: you mean without quoting the strings?

12:53 either way I'd have to think about escaping quotation marks or parentheses, right?

12:54 I guess the good thing about XML is that angle brackets are much less common in natural language than () and "

12:54 TimMc: pandeiro: I see the problem, yeah.

13:01 mavallad: Hi, could someone explain to me, why in this code: http://www.pastie.org/3144309

13:01 The first println works

13:01 But in the second case, it doesn't work

13:01 I don't understand the error message

13:03 rlb: mavallad: whad do you mean it doesn't work?

13:03 mavallad: Well, I mean, that I get an error

13:03 I understand that it is my fault, but I don't know why

13:04 rlb: Hmm, I don't...

13:04 jodaro: yeah works for me as well

13:04 whats the error?

13:04 rlb: (with 1.3.0)

13:05 jodaro: you can get the same thing with a future

13:05 (future (println "in a thread"))

13:06 mavallad: This is what I get: http://www.pastie.org/3144332

13:06 jodaro: and (map #(future (println "in the thread " % )) [:a :b :c])

13:08 hmmm, weird

13:08 rlb: mavallad: is this from a "clean" envt?

13:08 jodaro: works as expected for me still

13:08 rlb: i.e. a fresh clojure session?

13:09 mavallad: Yes, I started over the repl

13:13 TimMc: pandeiro: So, what's the worst case? Maybe something like this: "Click here for <a href="..." title="go to shopping cart">your shopping cart</a> etc. etc."

13:14 and maybe add a <em></em> around something

13:15 I feel like there's probably some really clever and readable way of representing that, even though different localizations may even have different orderings of markup tags.

13:15 amalloy: mavallad: in the first case you're passing a function to the Thread. constructor; in the last case you're calling println immediately and passing nil to the constructor

13:18 mavallad: amalloy: You are right. I understand now

13:27 pandeiro: TimMc: yeah that is a nightmare case! come to think of it, quote escaping might be the least complicated solution...

13:28 rlb: mavallad: not sure what's going on, then.

13:28 pandeiro: TimMc: but when you say "represent that", you mean turning it into a tree of sexp's or something?

13:29 TimMc: yeah

13:29 mavallad: As amalloy said, you are supposed to pass a function to the Thread. call

13:29 TimMc: Maybe some indirection is needed.

13:29 mavallad: But in the second case I am executing the function, not passing a function

13:30 TimMc: pandeiro: Including the whole wad of HTML is overkill and a maintenance nightmare. There needs to be a way to inject the extra properties (e.g. href).

13:32 I would represent it as ["pre text " (a :title "title text" "link text") " etc. etc.")

13:32 and then 'a would match to the link

13:34 Ugh, and then there are plurals...

13:34 mavallad: rlb: I don't know why it is working in your case

13:34 pandeiro: TimMc: i don't follow, why would plurals matter?

13:36 TimMc: pandeiro: ["Your " (l "shopping cart") ~(if (zero? size) `[" is empty."] [" contains " ~size

13:36 ...let me finish that...

13:37 "item" ~(if (pos? size) "s." ".")]]

13:38 Either that or you duplicate the localization message for every conditional.

13:38 pandeiro: TimMc: yeah definitely into norvig territory with programmatic pluralization... i am not much of a coder so i embrace the duplicate-dont-complicate philosophy there

13:40 i would just do :zero-items-cart :one-item-cart :plural-items-cart or something

13:43 zilti: If I use pinot remotes and send a clojure map from noir it arrives as clojure map, right?

13:50 jodaro: ooooo

13:50 at-at

14:13 semperos: for the Clojure 1.3 ecosystem, is there an existing equivalent for old contrib's repl-utils/show function?

14:14 amalloy: clojurebot: ~show |has| been replaced by clojure.reflect/reflect in 1.3

14:14 clojurebot: Roger.

14:16 amalloy: apparently i already taught him a better factoid than that

14:16 ~show

14:16 clojurebot: Show only exists in clojure.contrib.repl-utils, which is not 1.3-compatible. For a 1.3 replacement, consider clojure.reflect/reflect.

14:56 zilti: How do I reset the slime repl? Or is there another way to be able to re-load a file into it?

14:59 jcidaho: hi. First time on this chan and new to clojure. Wondering if anyone knows how to make swank-clojure when it's firing up in emacs automatically load a namespace / run a clojure file

14:59 raek: zilti: (requie 'the-ns :reload) in the repl or C-c C-k in the the_ns.clj buffer

14:59 jcidaho: i.e. we are playing around some clojure code that sets up test-data so it's easily available in the repl

15:01 was wondering of a way of skipping the step, so as soon as people open the repl the right namespace has been loaded.

15:01 zilti: raek: That doesn't work... getting a "extend already refers to blah blah" error

15:04 raek: zilti: ok, then you need to fix the "extend" issue in the file and then either run (ns-unmap 'the-ns 'extend) or (remove-ns 'the-ns) and then load the file again

15:05 amalloy: jcidaho: you don't really want that for slime/swank specifically, you want it for your repl. check out repl-init in project.clj

15:05 $google leiningen sample project.clj repl-init

15:05 lazybot: [sample.project.clj at master from technomancy/leiningen - GitHub] https://github.com/technomancy/leiningen/blob/master/sample.project.clj

15:09 sandbox`: hi, is there a simple way to test if something is a numerical value in clojure?

15:10 k9quaint: number?

15:10 sandbox`: wow that was easy

15:10 k9quaint: or rather (number? foo)

15:11 sandbox`: i had trouble searching google for that question but just guessing that would have made sense

15:13 thank you

15:13 zilti: sandbox`: http://www.clojuredocs.org is a good resource

15:13 TimMc: and the clojure.org pages as well

15:16 jcidaho: amalloy thanks for the tip

17:30 adiabatic: I'm trying to reimplement flatten for 4clojure on https://gist.github.com/1576291 . Can someone give me a hint as to how I can tell my function to keep going even though it's exhausted a subsequence? Trying to flatten '((1 2) 3 [4 [5 6]]) gives me (1 2)

17:33 alexbaranosky: adiabatic, kinda vague question

17:34 there are more than one way to implement flatten, so "it dependes"

17:37 adiabatic: fair 'nuff; "just a hint" might be hard

17:39 alexbaranosky: one way might be to recursively pull it apart into sequential? chunks

17:39 and call flatten on each of them, then glue them all back together

17:39 adiabatic: I can't use flatten to implement flatten — that'd be cheating ;)

17:40 broquaint: A handy function for that solution is concat, adiabatic.

17:40 hiredman: ~flatten

17:40 clojurebot: flatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with.

17:41 adiabatic: well, I switched from conj to concat in a couple places once I realized that conj was prepending things, not appending

17:41 alexbaranosky: adiabatic, I meant call YOUR WON flatten on each of the parts

17:41 s/your won/your own/

17:41 adiabatic: I do — that's the :else clause

17:42 alexbaranosky: adiabatic, did you post a gist?

17:42 adiabatic: yeah — https://gist.github.com/1576291

17:43 alexbaranosky: can't use a def on 4clojure though right?

17:43 adiabatic: Right. I copy from "(fn" to the ending paren right before the println.

17:43 alexbaranosky: yep

17:46 a hint is to do something like (fn this [coll] (if (sequential? coll) (mapcat this coll) :else coll) ;; something like that, not at all tested, but it may serve as some type of hint :)

17:47 broquaint: Which problem is that, adiabatic?

17:47 adiabatic: http://www.4clojure.com/problem/28

17:48 broquaint: Ah yes, I've often wondered why that's considered "Easy".

17:48 adiabatic: somewhere in the teens the difficulty started getting uneven

17:48 like, not monotonically increasing

17:49 alexbaranosky: adiabatic I just tested the hint I gave you -- it has one bug, then it should work I think

17:50 good luck

17:51 adiabatic: why sequential? instead of seq??

17:51 lazybot: adiabatic: What are you, crazy? Of course not!

17:52 alexbaranosky: adiabatic, sequential? works ??? seq? not so much :)

17:52 adamspgh, vectors aren't ISeqs

17:53 (flatten [1 [2 [3]]]) => [1 2 3]

18:06 adiabatic, did you get it working?

18:06 adiabatic: no, not yet

18:07 alexbaranosky: adamspgh, I'd think of it recursively: what does it take to flatten [1] ?

18:07 adiabatic, then, what does it take to flatten [1 [2]] ?

18:08 can you spliy [1 [2]] up and call your-flatten on each part, then sow them back together?

18:10 adiabatic: yes, yes, and no, in that order

18:11 alexbaranosky: adiabatic, did you see my hint?

18:12 adiabatic: Yes. I'm still struggling to think of how I might use mapcat when I don't have a guaranteed list of lists of values.

18:12 alexbaranosky: that's the bug in my hint :)

18:12 if I straightout told you, though, then what fun would that be for you :)

18:25 jodaro: Unable to resolve symbol: catch in this context

18:25 heh

18:25 that can't be good

18:35 technomancy: (doc tree-seq)

18:35 clojurebot: "([branch? children root]); Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the tree."

18:37 zilti: I have a very weird problem... I'm using clojure.zip. I have the code (:id (zip/node loc)) which works fine inside the REPL but always returns nil inside my code.

18:48 amalloy: jodaro: catch isn't a function or macro in clojure.core - it's just a "magic" symbol that the try special form looks for

18:48 jodaro: huh

18:48 i fixed it, my parens were wonky

18:57 zilti: jodaro: try/catch are inherited directly from their java counterparts

18:58 technomancy: haha: http://mobile.twitter.com/ymasory/status/155735483014582274

18:59 amalloy: they're so devious

19:00 jodaro: heh

19:22 alexbaranosky: technomancy, I was trying to keep tree-seq under wraps until he got it to work with recursion

19:22 adiabatic, ever get your-flatten working?

19:22 adiabatic: no

19:22 going to leave it for tomorrow

19:23 alexbaranosky: its tough for me to resist just telling you.... but that would ruin the challenge for you I think...

19:23 adiabatic: yeah, it would

19:24 plus, I could just look at the implementation

19:33 technomancy: oops

19:33 well I didn't spell it out

19:33 TimMc: re: that tweet, don't use what? I don't understand. :-(

19:35 technomancy: TimMc: "Works great in Emacs!"

19:35 TimMc: heh

19:36 Something changed in Emacs and their plugin broke?

19:42 technomancy: You said not to worry about lein-jit affecting jars, since there's no reason to have a :main in a normal jar. If that's the case, why does uberjar produce both an uberjar and a normal jar?

19:43 technomancy: TimMc: code re-use I guess? it doesn't have to; it's just simpler to implement that way

19:44 TimMc: Ah, OK.

19:44 In any event, I think the normal jars it produces will be fine. They use the loader, and I guess if the classpath is set up correctly they will probably work.

19:44 technomancy: cools

19:45 TimMc: java -cp "`lein classpath`" -jar foo-1.0.0.jar doesn't work, but if I dump all the dependencies in by hand it does work. :-P

19:46 amalloy: TimMc: i think the joke is "don't tell the clojure programmers that the reason you want them to learn scala is so we can have a good emacs plugin"

19:47 adiabatic: That's…amusing…but not funny?

19:47 technomancy: it's funny that they can convince people to stop using lisp in order to write more lisp.

19:47 *that they think they can

20:19 metajack: I'm trying to use clojure-test-mode and it doesn't seem to put the test stuff on the classpath. This means I can run the foo.test.core tests, but not any that require foo.test.core (which contains some helpers). lein test works fine though. Anything I can do to fix this?

21:07 alexbaranosky: does every multimethod have to have the same arity?

21:07 amalloy: no

21:07 danlarkin: or my favorite, "try it and find out"

22:04 technomancy: metajack: clojure-test-mode doesn't have anything to do with the classpath, leiningen sets it

22:07 MarcusMcRandall: technomancy, my love.

22:07 Let us worship his shadow together

22:08 technomancy: bloody hell

22:08 * technomancy wishes /ignore worked retroactively

22:08 MarcusMcRandall: You an probabl put that in a client if you so desire.

22:17 alexbaranosky: lol

22:31 metajack: technomancy: I suppose I knew that. Is the test stuff not supposed to be on lein's classpath? Otherwise, it seems that test files must be completely self contained to work with clojure-test-mode.

22:32 technomancy: metajack: that's the first time I've heard of that problem; test directories should always be on the classpath unless LEIN_NO_DEV is set

22:32 maybe the filename doesn't match the ns name?

23:26 metajack: technomancy: It was user error. Apparently I was jacked in to another project.

23:27 Speaking of which, is there some easier way to run multiple repls than switching back and forth manually with clojure-jack-in or using lein swank manually?

23:51 alexbaranosky: amalloy, thanks, the problem was in the dispatch function:

23:52 espringe: How can I "flatten" a list, so I can pass it to a function. Like what's the best way to do this:

23:52 #(if (> %1 %&) "this list is in descending order" "its not")

23:52 amalloy: &(doc apply)

23:52 lazybot: ⇒ "([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args]); Applies fn f to the argument list formed by prepending intervening arguments to args."

23:52 espringe: Should I be adding %1 and %&, and then use apply?

23:53 amalloy: espringe: apply takes extra args

23:54 so if you need %1 separately elsewhere in the function you can use (apply > %1 %&). but if you don't, (apply > %&) is fine. for that matter so is (partial apply >)

23:54 espringe: Ohhh, cool

23:54 thanks!

Logging service provided by n01se.net