#clojure logs

2012-01-07

00:16sgronblomDoesn't clojure have support for nested namespaces?
00:18technomancysgronblom: no, the appearance of hierarchy in namespaces is an illusion
00:19replacaalthough a useful one. For example autodoc groups "sub-namespaces" onto the same page as their root
00:20sgronblomI 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
01:40kprav33nI'm new to clojure. I installed clojure 1.3 on Mac OS X Lion using homebrew.
01:42kprav33nI 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
01:42kprav33nAny pointers?
02:08kprav33nSomething was badly messed up in my ~/.m2 directory that caused the problem that I mentioned above.
02:08kprav33nI blew the entire .m2 directory away and reinstalled leiningen and that solved the issue.
03:20stragerI'm learning Clojure using 4Clojure, and I'm on a reduce problem: http://www.4clojure.com/problem/64
03:21stragerWhy can I solve it using: (partial +)
03:21stragerTo produce: (reduce (partial +) [1 2 3 4 5])
03:24strager(I had to enter (partial + 0) to make it work.)
03:25stragerWell, simply "+" worked (reduce + [1 2 3 4 5]), which makes total sense.
03:26stragerI guess partial really wants to partially apply something, and won't take nothing for an answer.
03:30hiredmanstrager: why are you using partial at all?
03:31hiredman,(reduce + [1 2 3 4 5])
03:31clojurebot15
03:31stragerBecause I'm new to Clojure and it was taught that functions can be created using partial.
03:31hiredman,(apply + [1 2 3 4 5])
03:31clojurebot15
03:31stragerI didn't think of using just + until later.
03:31stragerBut still, why doesn't partial work like that? Wouldn't it be more general to just accept no extra arguments and return the function?
04:13dbushenkohi all!
04:13dbushenkohow to check whether the item is any kind of compund data structure (list,vector,map,set -- doesn't matter)?
04:16dbushenkook, I've just found. it's 'sequential?'
06:25ziltiI 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 .
06:29rippynew to clojure, working on 4clojure exercises...
06:30rippynot sure why this is failing the = test -> http://pastebin.com/gNwirzvA
06:31broquaintWhich problem, rippy?
06:31rippythe #() generates [1] but when i check to see if it's (= #() [1]) it's not equal
06:31rippythe pastebin has the code and the failing test
06:31ziltirippy: Why did you write (#( instead of #( ?
06:32rippydefining and invoking it, per the 4clojure test case http://www.4clojure.com/problem/99
06:33broquaint[\1] != [1]
06:33rippyohhhhhh
06:33rippythanks broquaint !
06:33rippythat makes perfect sense
06:33broquaintnp :)
06:33rippyit's odd that the REPL doesn't print it as \1
06:33broquaintIt does here ...
06:33rippyhmmm
06:34rippyclj -> Clojure 1.3.0
06:34broquaintlein repl?
06:34rippyon OSX, I did a "port install clojure"
06:34rippysorry, really new to clojure ... just startd working on this :)
06:35rippymaybe my version is old from OSX ports
06:36broquaint1.3.0 is the most recent, so not sure why you're seeing what you're seeing.
06:37rippyyeah, it outputs [1] instead of [\1] ... unless i'm misunderstanding what it should print
06:37rippyyou are my hero though broquaint!
06:37rippythanks a ton!
06:37broquaintnp
06:38broquaintlein is leiningen BTW, a useful clojure tool - https://github.com/technomancy/leiningen
06:38rippyi will check that out
06:38rippyany other pro-tips of packages or sites I should also check out broquaint?
06:39broquaintAnd if you're using it in conjunction with 4clojure then I wrote a plugin that might be of use - foreclojure-plugin
06:39broquainthttps://github.com/broquaint/lein-foreclojure-plugin (even)
06:39rippyi'm editing in vi at the moment, didn't check to see if eclipse groks clojure better yet
06:39rippywhat do you edit in broquaint?
06:39broquaintNot that I can think of off the top of my head, rippy, I'm kind of a clojure newb too ;)
06:40broquaintI use emacs to edit clojure.
06:40rippyi've used slime in the past for lisp stuff, maybe it supports clojure too
06:40rippyer emacs slime
06:40broquaintIt does indeed.
06:40rippyoh nice, i'll try to get that working
06:41broquainthttps://github.com/technomancy/swank-clojure
06:41rippybroquaint: i like your project! i was doing that manually
06:42rippybroquaint: have you been solving the 4clojure tests too by chance? i'd like to follow you to compare/contrast solutions
06:43broquaintThanks, it's my first non-4clojure bit of clojure ;)
06:43broquaintAnd yep, I'm on 4clojure with the same user name.
06:43ziltibrk
06:44ziltibroquaint: Does lein swank clojure work for you? What's your leiningen config?
06:44broquainthttp://www.4clojure.com/user/broquaint
06:44broquaintIt does, zilti.
06:44rippyfollowing you broquaint! :) i'm http://www.4clojure.com/user/rippy
06:44broquaintI'm just using whatever the results are.
06:45broquaints/results/defaults/
06:45broquaintDitto, rippy :)
06:45ziltibroquaint: Did you have to manually install that clj-stacktrace plugin?
06:46broquaintYup, and manually configure IIRC.
06:46ziltiBecause it doesn't work for me
07:03rippybroquaint: nice, lein + your plugin all worked straight from OSX ports
09:01ziltiHmm how do I get the clj-stacktrace to actually work?
09:11ziltiAnd what does "Exception in thread "main" java.lang.IllegalArgumentException: Parameter declaration loop should be a vector" mean?
09:12gf3zilti: it means you have probably missed the arguments vector when defining your function
09:12gf3(defn name [args] body)
09:14ziltigf3: But I've got only a defpage and a preroute in that file, and they're declared correctly
09:15gf3zilti: using noir?
09:15ziltiyes
09:15gf3zilti: can you paste your file?
09:18ziltigf3: https://gist.github.com/1574853
09:20gf3zilti: yes, you're missing the arguments vector
09:20gf3zilti: (defpage [:get "/news/:category"] {:keys [category]} → (defpage [:get "/news/:category"] [] {:keys [category]}
09:21ziltigf3: I'll try that, but that shouldn't be necessary - the examples on the noir page don't have it either.
09:22gf3zilti: they do indeed
09:22gf3zilti: http://webnoir.org/tutorials/routes
09:22ziltigf3: Look at the first defpage example with parameter
09:22gf3zilti: although it's not in the docs
09:23gf3zilti: oh shi-, you're right
09:23ziltiNow I've added [] to both the preroute and the defpage but I still get the error...
09:24gf3zilti: my mistake, sorry
09:24ziltiIt was worth the try. I got two of these errors before, now it's one so it seems it helped
09:36ziltiThat error seems to be unsolvable
09:45AeroNotixis there a function to test if all arguments return true?
09:46cgrayAeroNotix: and
09:46AeroNotixcgray: derp
09:47AeroNotix:P
10:25bsteuberis 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:25bsteuberI tried dropping the changed files in the uberjar, but it seems the changes in there aren't monitored by compojure
10:26ziltiDid anyone already work with forms in noir/hiccup? It seems that all that arrives are NULL values...
10:26bsteuberso basically I want an external designer play with the site without showing him any code
10:28ziltibsteuber: 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:29ziltiOh. pre-route doesn't have access to data sent via POST
10:32bsteuberzilti: the only way I find to tell noir about the place is :resource-root which assumes its target to be in the classpath
10:33bsteuberI am trying along the lines of "java -cp my.jar:resources" but I didn't manage to get it work yet
10:33ziltibsteuber: Just give hiccup the URL to the css file
10:35bsteuberbut it's not being served anywhere and "file:///" doesn't seem to work
10:38jkkramerbsteuber: what code are you using to pull in css now? include-css or [:link :rel "stylesheet" …]?
10:38jkkramerbsteuber: you should be able to use something like (include-css "/url/path/to/css") or (include-css "http://some/other/domain")
10:39technomancy_jkkramer: I'm heading off, but did you see this? https://github.com/Seajure/melange
10:39jkkramertechnomancy_: i did not, cool. i will check it out. i did see your pull request about API or access to the data
10:40bsteuberjkkramer: (include-css "file:///path/to/css")
10:40jkkramertechnomancy_: issue rather, not pull request
10:40jkkramerbsteuber: include-css deals with public urls, not file paths
10:40bsteuberjkkramer: but maybe it's better to leave it as it is and try to add resources later to the classpath
10:41bsteuberjkkramer: does that mean [:link ...] will work with local files?
10:42jkkramerbsteuber: include-css is just shorthand for [:link …], I believe. check out the HTML source it generates
10:43bsteuberhah
10:43bsteuberremoving resources from the uberjar and using "java -cp resources:my.jar" did the job
10:43jkkramerbsteuber: see the include-css here: http://webnoir.org/tutorials/html. it just generates HTML, which refers to public URLs, not filesystem files
12:18jodarohrm
12:19jodarois there a built in way to do something like select() on a group of lamina channels?
12:19jodaroi can mimic it with one pretty easily with (wait-for-message (fork ch) timeout)
12:40pandeiro<TimMc> pandeiro: I don't know, it can get weird when you have marked-up
12:40pandeiro text. I've seen some l10n libs use format strings, actually.
12:41pandeiro^^ this is a good point you make
12:41pandeiroI 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:45ziltiDoes 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:48TimMcpandeiro: It's one of those things that seems so easy on the surface...
12:49TimMcAnyone can solve 95% of the problem. :-)
12:51pandeiroTimMc: 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:52TimMcpandeiro: You can probably do soemthing just as good with s-expressions.
12:53pandeiroTimMc: you mean without quoting the strings?
12:53pandeiroeither way I'd have to think about escaping quotation marks or parentheses, right?
12:54pandeiroI guess the good thing about XML is that angle brackets are much less common in natural language than () and "
12:54TimMcpandeiro: I see the problem, yeah.
13:01mavalladHi, could someone explain to me, why in this code: http://www.pastie.org/3144309
13:01mavalladThe first println works
13:01mavalladBut in the second case, it doesn't work
13:01mavalladI don't understand the error message
13:03rlbmavallad: whad do you mean it doesn't work?
13:03mavalladWell, I mean, that I get an error
13:03mavalladI understand that it is my fault, but I don't know why
13:04rlbHmm, I don't...
13:04jodaroyeah works for me as well
13:04jodarowhats the error?
13:04rlb(with 1.3.0)
13:05jodaroyou can get the same thing with a future
13:05jodaro(future (println "in a thread"))
13:06mavalladThis is what I get: http://www.pastie.org/3144332
13:06jodaroand (map #(future (println "in the thread " % )) [:a :b :c])
13:08jodarohmmm, weird
13:08rlbmavallad: is this from a "clean" envt?
13:08jodaroworks as expected for me still
13:08rlbi.e. a fresh clojure session?
13:09mavalladYes, I started over the repl
13:13TimMcpandeiro: 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:14TimMcand maybe add a <em></em> around something
13:15TimMcI 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:15amalloymavallad: 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:18mavalladamalloy: You are right. I understand now
13:27pandeiroTimMc: yeah that is a nightmare case! come to think of it, quote escaping might be the least complicated solution...
13:28rlbmavallad: not sure what's going on, then.
13:28pandeiroTimMc: but when you say "represent that", you mean turning it into a tree of sexp's or something?
13:29TimMcyeah
13:29mavalladAs amalloy said, you are supposed to pass a function to the Thread. call
13:29TimMcMaybe some indirection is needed.
13:29mavalladBut in the second case I am executing the function, not passing a function
13:30TimMcpandeiro: 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:32TimMcI would represent it as ["pre text " (a :title "title text" "link text") " etc. etc.")
13:32TimMcand then 'a would match to the link
13:34TimMcUgh, and then there are plurals...
13:34mavalladrlb: I don't know why it is working in your case
13:34pandeiroTimMc: i don't follow, why would plurals matter?
13:36TimMcpandeiro: ["Your " (l "shopping cart") ~(if (zero? size) `[" is empty."] [" contains " ~size
13:36TimMc...let me finish that...
13:37TimMc "item" ~(if (pos? size) "s." ".")]]
13:38TimMcEither that or you duplicate the localization message for every conditional.
13:38pandeiroTimMc: 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:40pandeiroi would just do :zero-items-cart :one-item-cart :plural-items-cart or something
13:43ziltiIf I use pinot remotes and send a clojure map from noir it arrives as clojure map, right?
13:50jodaroooooo
13:50jodaroat-at
14:13semperosfor the Clojure 1.3 ecosystem, is there an existing equivalent for old contrib's repl-utils/show function?
14:14amalloyclojurebot: ~show |has| been replaced by clojure.reflect/reflect in 1.3
14:14clojurebotRoger.
14:16amalloyapparently i already taught him a better factoid than that
14:16amalloy~show
14:16clojurebotShow only exists in clojure.contrib.repl-utils, which is not 1.3-compatible. For a 1.3 replacement, consider clojure.reflect/reflect.
14:56ziltiHow do I reset the slime repl? Or is there another way to be able to re-load a file into it?
14:59jcidahohi. 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:59raekzilti: (requie 'the-ns :reload) in the repl or C-c C-k in the the_ns.clj buffer
14:59jcidahoi.e. we are playing around some clojure code that sets up test-data so it's easily available in the repl
15:01jcidahowas wondering of a way of skipping the step, so as soon as people open the repl the right namespace has been loaded.
15:01ziltiraek: That doesn't work... getting a "extend already refers to blah blah" error
15:04raekzilti: 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:05amalloyjcidaho: you don't really want that for slime/swank specifically, you want it for your repl. check out repl-init in project.clj
15:05amalloy$google leiningen sample project.clj repl-init
15:05lazybot[sample.project.clj at master from technomancy/leiningen - GitHub] https://github.com/technomancy/leiningen/blob/master/sample.project.clj
15:09sandbox`hi, is there a simple way to test if something is a numerical value in clojure?
15:10k9quaintnumber?
15:10sandbox`wow that was easy
15:10k9quaintor rather (number? foo)
15:11sandbox`i had trouble searching google for that question but just guessing that would have made sense
15:13sandbox`thank you
15:13ziltisandbox`: http://www.clojuredocs.org is a good resource
15:13TimMcand the clojure.org pages as well
15:16jcidahoamalloy thanks for the tip
17:30adiabaticI'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:33alexbaranoskyadiabatic, kinda vague question
17:34alexbaranoskythere are more than one way to implement flatten, so "it dependes"
17:37adiabaticfair 'nuff; "just a hint" might be hard
17:39alexbaranoskyone way might be to recursively pull it apart into sequential? chunks
17:39alexbaranoskyand call flatten on each of them, then glue them all back together
17:39adiabaticI can't use flatten to implement flatten — that'd be cheating ;)
17:40broquaintA handy function for that solution is concat, adiabatic.
17:40hiredman~flatten
17:40clojurebotflatten 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:41adiabaticwell, I switched from conj to concat in a couple places once I realized that conj was prepending things, not appending
17:41alexbaranoskyadiabatic, I meant call YOUR WON flatten on each of the parts
17:41alexbaranoskys/your won/your own/
17:41adiabaticI do — that's the :else clause
17:42alexbaranoskyadiabatic, did you post a gist?
17:42adiabaticyeah — https://gist.github.com/1576291
17:43alexbaranoskycan't use a def on 4clojure though right?
17:43adiabaticRight. I copy from "(fn" to the ending paren right before the println.
17:43alexbaranoskyyep
17:46alexbaranoskya 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:47broquaintWhich problem is that, adiabatic?
17:47adiabatichttp://www.4clojure.com/problem/28
17:48broquaintAh yes, I've often wondered why that's considered "Easy".
17:48adiabaticsomewhere in the teens the difficulty started getting uneven
17:48adiabaticlike, not monotonically increasing
17:49alexbaranosky adiabatic I just tested the hint I gave you -- it has one bug, then it should work I think
17:50alexbaranoskygood luck
17:51adiabaticwhy sequential? instead of seq??
17:51lazybotadiabatic: What are you, crazy? Of course not!
17:52alexbaranoskyadiabatic, sequential? works ??? seq? not so much :)
17:52alexbaranoskyadamspgh, vectors aren't ISeqs
17:53alexbaranosky(flatten [1 [2 [3]]]) => [1 2 3]
18:06alexbaranoskyadiabatic, did you get it working?
18:06adiabaticno, not yet
18:07alexbaranoskyadamspgh, I'd think of it recursively: what does it take to flatten [1] ?
18:07alexbaranoskyadiabatic, then, what does it take to flatten [1 [2]] ?
18:08alexbaranoskycan you spliy [1 [2]] up and call your-flatten on each part, then sow them back together?
18:10adiabaticyes, yes, and no, in that order
18:11alexbaranoskyadiabatic, did you see my hint?
18:12adiabaticYes. 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:12alexbaranoskythat's the bug in my hint :)
18:12alexbaranoskyif I straightout told you, though, then what fun would that be for you :)
18:25jodaroUnable to resolve symbol: catch in this context
18:25jodaroheh
18:25jodarothat can't be good
18:35technomancy(doc tree-seq)
18:35clojurebot"([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:37ziltiI 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:48amalloyjodaro: catch isn't a function or macro in clojure.core - it's just a "magic" symbol that the try special form looks for
18:48jodarohuh
18:48jodaroi fixed it, my parens were wonky
18:57ziltijodaro: try/catch are inherited directly from their java counterparts
18:58technomancyhaha: http://mobile.twitter.com/ymasory/status/155735483014582274
18:59amalloythey're so devious
19:00jodaroheh
19:22alexbaranoskytechnomancy, I was trying to keep tree-seq under wraps until he got it to work with recursion
19:22alexbaranoskyadiabatic, ever get your-flatten working?
19:22adiabaticno
19:22adiabaticgoing to leave it for tomorrow
19:23alexbaranoskyits tough for me to resist just telling you.... but that would ruin the challenge for you I think...
19:23adiabaticyeah, it would
19:24adiabaticplus, I could just look at the implementation
19:33technomancyoops
19:33technomancywell I didn't spell it out
19:33TimMcre: that tweet, don't use what? I don't understand. :-(
19:35technomancyTimMc: "Works great in Emacs!"
19:35TimMcheh
19:36TimMcSomething changed in Emacs and their plugin broke?
19:42TimMctechnomancy: 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:43technomancyTimMc: code re-use I guess? it doesn't have to; it's just simpler to implement that way
19:44TimMcAh, OK.
19:44TimMcIn 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:44technomancycools
19:45TimMcjava -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:46amalloyTimMc: 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:47adiabaticThat's…amusing…but not funny?
19:47technomancyit's funny that they can convince people to stop using lisp in order to write more lisp.
19:47technomancy*that they think they can
20:19metajackI'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:07alexbaranoskydoes every multimethod have to have the same arity?
21:07amalloyno
21:07danlarkinor my favorite, "try it and find out"
22:04technomancymetajack: clojure-test-mode doesn't have anything to do with the classpath, leiningen sets it
22:07MarcusMcRandalltechnomancy, my love.
22:07MarcusMcRandallLet us worship his shadow together
22:08technomancybloody hell
22:08MarcusMcRandallYou an probabl put that in a client if you so desire.
22:17alexbaranoskylol
22:31metajacktechnomancy: 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:32technomancymetajack: 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:32technomancymaybe the filename doesn't match the ns name?
23:26metajacktechnomancy: It was user error. Apparently I was jacked in to another project.
23:27metajackSpeaking 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:51alexbaranoskyamalloy, thanks, the problem was in the dispatch function:
23:52espringeHow can I "flatten" a list, so I can pass it to a function. Like what's the best way to do this:
23:52espringe#(if (> %1 %&) "this list is in descending order" "its not")
23:52amalloy&(doc apply)
23:52lazybot⇒ "([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:52espringeShould I be adding %1 and %&, and then use apply?
23:53amalloyespringe: apply takes extra args
23:54amalloyso 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:54espringeOhhh, cool
23:54espringethanks!