#clojure logs

2010-03-06

00:09brandonwif you have a situation where you are using map and need to define an anonymous function, but you already have one in a higher scope, is it more idiomatic to define that first anonymous function as a private function in the same namespace, or as a function defined within the scope of the top level public function you are working on
00:09brandonws/but you already have one/but you already have an anonymous function
00:10brandonw(just to be clear)
00:15slyphonuh, where do i get swank-clojure.jar
00:15slyphoni followed the directions here: http://github.com/technomancy/swank-clojure
00:16rickmodeslyphon: that's the right place
00:17slyphonyeah, it says to copy swank-clojure.jar to the lib/ directory if you want to use the project feature
00:17slyphonbut i'm retarded tonight and can't seem to find that jar file
00:17rickmodeslphon: this helped me too: http://www.bestinclass.dk/index.php/2009/12/clojure-101-getting-clojure-slime-installed/
00:17slyphonrickmode: thanks :)
00:18rickmodeslyphon: I was referred that video by another person here in this channel within the last week ;)
00:19slyphonheh
00:19slyphonoh, bastard
00:20rickmodewatch the video anyway - there's lots of good bits there
00:20slyphoncool
00:20rickmodeit kinda explains the "why" of it all
00:21slyphonah
00:21slyphoni've been SLIMEd before, but yeah, any info is useful
00:22rickmodei'm still not entirely clear on the differences between slime and swank... but I got my emacs, clojure and leiningen stuff working smoothly now
00:23slyphonyeah, the slime/swank difference was always a bit of a mystery, i think swank is a lisp-impl-specific server that answers requests from slime
00:23slyphonor, something like that
00:24rickmodeya - that's my sense too - UI vs. server stuff
00:25slyphon10 years of muscle-memory is not easily undone
00:26rickmodetell me about it... but I'm coming from an IDE background (winblows and java IDEs)
00:26slyphonah
00:27rickmodei still get baffled by the frames/buffers/windows stuff in emacs - it's got its own *way*
00:27tomojslyphon: just use elpa
00:27tomojit's pretty simple http://tomojack.com/2010/02/emacs-for-clojure-from-scratch/
00:27slyphontomoj: yeah, i did, i needed to copy the swank-clojure.jar into an existing project
00:28tomojlein?
00:28clojurebotleiningen is a build tool designed not to set your hair on fire (http://github.com/technomancy/leiningen)
00:28slyphondidn't realize it put it in .swank-clojure
00:28tomojif your project needs swank-clojure, I think it should be in the dependencies for the build tool
00:28tomojit's pretty easy to work with a lein project through emacs
00:29slyphonwell, i'm not really using a build tool right now
00:29tomojwhy not? too much work?
00:29slyphoneh, i don't come from a java background, so it was a high barrier to entry for me to start thinking about leingen or maven or w/e
00:29tomojI think I will be making a screencast soon with emacs+lein
00:29tomojyeah
00:29slyphoni just put my jars in lib/
00:29tomojit can be a bit intimidating
00:30slyphonand wrote a Rakefile to spawn nailgun w/ vim-clojure
00:30tomojbut I think technomancy has really got it down so that it's easy to do
00:30slyphontechnomancy is a sharp cookie
00:30slyphon[sic]
00:30tomojoh, I kind of assumed you were using emacs :)
00:30slyphonyeah, i switched
00:30slyphonwell
00:31slyphonthat makes it sound really official
00:31slyphoni used emacs for about a year back in 2005 or so
00:31slyphoni wanted to see where it was at
00:31tomojand now you're a vim dude?
00:31slyphoni've always been a vim dude :)
00:32tomojwell, there's a lein-nailgun plugin
00:32tomojI dunno how well it works, though
00:32slyphoni was working on an all-emacs team though at the time, and i got tired of everyone always giving me shit about it
00:32tomojhaha
00:32tomojI didn't know there were all-emacs teams who gave shit about it
00:32slyphonwell
00:32slyphonheh
00:32slyphonit was twisted-python
00:32tomojif my coworkers start trying to use vim for clojure, I'd give them shit
00:32tomojbut not aggressively :)
00:32slyphonand it was my first real gig, and i kind of wanted to fit in
00:33tomojyeah makes sense
00:33tomojwell, maybe I can convert you with my screencast
00:33slyphonnow that i'm not trying to use emacs for IRC and reading email, and all that other nonsense, i'm interested primarily because i remember SLIME being *really* impressive with sbcl
00:33slyphonplus, messing around with elisp is kind of fun
00:34tomojyes, I've done a couple fun things with elisp
00:34tomojI've made it so the editor can be aware of which namespace a source file defines
00:34slyphonah, that's handy
00:35tomojso you can get a skeleton ns decl from the path, or cause the repl to switch to the namespace in the current buffer, for example
00:35tomojbut I feel like there is much more you could do
00:35tomoj(and a lot I love already works with slime)
00:35slyphoncontext-awareness is a really powerful thing
00:35tomoje.g. M-. will jump to the function definition, even if the clj source file is buried in a jar
00:35slyphonsee, *that* stuff is really nifty
00:35tomojslime macroexpansion stuff works, some documentation stuff
00:36tomojplus, ...paredit
00:36slyphonyeah, srsly
00:36tomojthis is what my screencast will cover
00:36slyphonoh, excellent
00:36slyphoni look forward to watching it
00:36tomojbut I can't stop the pain of learning (or using) emacs
00:36tomoj:(
00:36slyphonhahaha
00:36slyphonwell, i've got the basics down
00:37slyphonand having vim-mode (which is light-years better than Viper) definately helps
00:37slyphoni just need hjkl
00:37tomojI suppose you don't need much more than the basics
00:37slyphonand :e :w
00:37tomojunless you want to live in emacs
00:37slyphonthe 'C-w j' bindings are good too
00:38slyphonthat's one thing that always drove me insane about emacs, i didn't think the split-handling was nearly as straightforward
00:38slyphon"Why did that open up down there?
00:38slyphon"
00:38tomojhmm
00:38tomojwith paredit?
00:39slyphonnah, just with standard emacs buffer stuff
00:39tomojI don't notice anything that sounds like that with my setup
00:39tomojbut I don't really understand what you mean
00:39slyphonit could just be some insane combination of plugins i was using back in the day
00:39slyphonit seems much more intuitive now
00:39slyphonwith this setup i have
00:40tomojI think there was some plugin that made it so while you're editing, the parens are exploded c-style, but when you are done they are redone to be lisp-style (e.g. '))))))' at the end of a line)
00:40tomojbut I don't find the need for that
00:41slyphonargh, one thing i wish i could figure out is how to globally define the friggin font i want EVERYWHERE
00:55tomojaquamacs is :/
00:55tomojI'm not really sure what to do about emacs on osx
00:55tomojalmost want to just run it in Terminal.app, but I hate Terminal.app
00:56danlarkinI live inside console emacs in iTerm
00:57slyphoni usually run everything in mrxvt
00:57slyphonwell, anything that has to do with "work", but the meta key in X11 on OS-X is totally hosed, iirc
01:00offby1newbie question -- just built my program with leiningen. When I try to run it with 'clj anagrams.jar "Your Mother Wears Army Boots"', I get 'Exception in thread "main" java.lang.Exception: No such namespace: ' (followed by a bunch of binary garbage). What might be wrong?
01:01tomojdanlarkin: will check iTerm out, thanks
01:01tomojI hadn't considered trying to get rxvt to work on mac
01:02slyphoni require jmk-neep
01:02slyphonwell, that too
01:02slyphonusually non-concurrently though
03:03ennuihave a public Java class 'Bar' in package 'foo'. (import 'foo.Bar) succeeds. How can I now call its (public static) main method?
03:04derefed(foo.Bar/main) I think
03:04derefedthat's just a guess though
03:06tomojI imagine you will need to pass a string[] in, no?
03:07tomoj(foo.Bar/main (into-array String []))
03:11ennuiderefed, tomoj, thanks. the last one works perfectly. i was struggling with how to properly pass the string argument.
03:11derefednp =)
04:13dmileshttp://libomv.pastebin.ca/1824907 <- am i runing the pastebin line 109 every "new" ?
04:14nteonso if i have ((a b) (c d) (e f)), how can i get (a b c d e f)? I want to use reduce but my brain is tired
04:15gregh,(flatten '((a b) (c d) (e f)))
04:15clojurebot(a b c d e f)
04:17nteongregh: ah! cool
04:17nteonthanks
04:22nteon,(doc flatten)
04:22clojurebot"([x]); Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat sequence. (flatten nil) returns nil."
04:22hiredman,`flatten
04:22clojurebotclojure.contrib.seq-utils/flatten
04:25nteonhiredman: yes, that was the command I was looking for, thanks :)
04:35zabEvening all. I'm trying to get Enlive working on App Engine. GAE docs say I can read files using Class.getResource() or ServletContext.getResource(). NFI how to do that from Clojure. Any pointers?
04:45tomojzab: (.getResourceAsStream (clojure.lang.RT/baseLoader) "filename")
04:46tomojmaybe that's what you're looking for
04:46zabtomoj: thanks!
05:41tomojwhat is the point of having (:load) in the ns macro?
05:42tomojI mean, I understand what it does, I just don't understand why we need it
05:42tomojso that we can split a namespace into multiple files easily?
10:01nedforgive my stupidity but whats the proper way to 'clone' a lein repo?
10:01nedi cant quite figure it out and i've searched relatively extensively
10:02tcrayforduse git clone?
10:02nedsorry the repos hosted on clojars
10:02nedjust git clone http://clojars.org/repo/name ?
10:07nedoh it would seem i have to create some boilerplate code, before lein deps.
10:11tcrayfordyep
10:11tcrayfordin project.clj
10:16rshis there a good way to tell emacs to indent custom macros a certain way? particularly when dealing with macros that contain a parameter like (& body)?
10:18vyrsh: It should indent them right, that's how (with-foo ...) macros get indented also.
10:23rshI see. with-foo macros seem to work fine, but any arbitrary name doesn't like (defmacro =bind [parms & body])
10:27vyHrm... That feature might be implemented in recent versions of SLIME, Clojure uses an obsolete version.
10:27vyBut I'm pretty sure SLIME is capable of indenting by looking at function's arguments.
11:33jkrIf I want to use clojure-mode from ELPA with my own clojure.jar in /opt/clojure (as opposed to downloading a new one), what should I set?
11:33jkrI used to be able to set swank-clojure-jar-path, but it seems to have changed in the months since I last used it.
12:18joshua-choiPerformance-wise, which is better: conj!-ing many times onto a vector transient, or cons-ing many times onto a list?
12:24rshwhat is the clojure equivalent to CL's atomp function?
12:27boojumjoshua-choi: seems to be transient is faster
12:28joshua-choiOkay
12:28joshua-choiThanks
12:31boojumjoshua-choi: http://gist.github.com/323814
12:32joshua-choiGreat, thanks for running that.
12:35krumholt_rsh, probably it's (not (coll? x))
12:36rshthanks
12:37krumholt_rsh, but thats not quite it i think a function is not an atom in CL but it is not a coll in clojure either
12:37dnolenkrumholt_ rsh: I believe seq? is more equivalent to atomp
12:38krumholt_,(seq? [1 2 3])
12:38clojurebotfalse
12:41krumholt_,(seq? (list 1 2 3))
12:41clojurebottrue
12:43krumholt_,(map #(not (or (coll? %) (fn? %))) [1 "foo" 'foo (list 1 3) [1 3] (fn [x] x) {:a 1} #{1 2 3}])
12:43clojurebot(true true true false false false false false)
12:43krumholt_i think (not (or (coll? x) (fn? x))) should be atomp
12:44rshis that kind of calculation not common in clojure?
12:44krumholt_rsh, you mean for recursion?
12:44rshye
12:44rshyes*
12:45dnolenkrumholt_: interesting when I wrote clj-cont I brought it this very topic, but I don't recall why I decided seq? was better than coll?
12:45dnolenbrought -> brought up
12:45krumholt_rsh, i used it a lot in commonlisp almost never in clojure. i ceased to use symbols that much
12:46krumholt_dnolen, i think seq? checks if it implement ISeq like lists. coll is almost everything
12:47krumholt_dnolen, look at this beautiful class diagram :) http://github.com/Chouser/clojure-classes/blob/master/graph-w-legend.png
12:48krumholt_dnolen, you can see very good what coll? checks for and what seq? checks for
12:49dnolenyeah, again I don't remember why I chose seq?. It was a for a code walker.
12:50dnolencode is from almost a year ago
12:50dnolenI remember intending to use coll?
12:50dnolenbut bringing it up on IRC and changing my mind.
12:52rshif recursing through a list representing a tree is uncommon in clojure, what are the alternatives
12:53technomancyrsh: I don't think it's particularly uncommon. have you used tree-seq?
13:08rshtechnomancy: I have not heard of tree-seq, i will look into it more. We were discussing earlier the clojure equivalent of atomp and landed on (or #(coll? %) #(fn? %)) . Does this look right to you?
13:09rshCL's atomp
13:10offby1newbie question -- just built my program with leiningen. When I try to run it with 'clj anagrams.jar "Your Mother Wears Army Boots"', I get 'Exception in thread "main" java.lang.Exception: No such namespace: ' (followed by a bunch of binary garbage). What might be wrong?
13:10technomancyrsh: isn't atomp just "is this not a compound data type?" it's been a while since my last CL usage.
13:10rshtechnomancy: yes
13:11technomancyoffby1: does your project.clj specify the :main namespace?
13:11rshtechnomany: clojure not having a this included seems odd to me, like it is implying you should not be doing this much
13:11technomancyoffby1: the JVM has some odd rules wrt translating between dashed-namespaces and files_on_disk.clj
13:11rshtechnomany: not having this*
13:11technomancyrsh: if you want to know if something is not a collection, you can just call (not (coll? x))
13:12offby1technomancy: lemme check
13:12rshtechnomany: yeah, but a fn would return true there even though it shouldn't
13:13offby1technomancy: it says nothing about :main
13:13offby1I let leiningen create it, and didn't edit it further
13:15technomancyoffby1: oh, I see. yeah, your clj script is probably expecting to be pointed at a .clj file instead of a jar
13:16offby1oh?
13:16technomancyyou'd want to run jar files using the "java" command-line launcher, but the rules about that are quirky too
13:17technomancyyou need to either build it as a standalone jar, or include all the deps on the classpath
13:17offby1technomancy: aha, you are correct, sir
13:17offby1clj ./src/anagrams/core.clj yo ho ho => happiness
13:17technomancyand you'd also need to specify a :main namespace containing a -main function
13:17technomancyright... command-line launching is definitely a weak point of clojure
13:19technomancyoffby1: you can also try the leiningen-run plugin
13:19offby1oh hell -- next problem is my program runs out of heap space. Is there a way I can increase it with clj, or do I just need to cruft up a shell script that directly invokes java on the .jar?
13:19offby1.oO("plugin"?)
13:19technomancywhere'd you get your clj script? there's not really a standard one yet.
13:20offby1ClojurX
13:20technomancyoffby1: looks like the one in contrib takes a CLOJURE_OPTS env var
13:20technomancyCLOJURE_OPTS="-Xmx1g" clj [...]
13:21technomancyif yours is based on that you could try that
13:21technomancyJAVA_OPTS is also a common one
13:21technomancy(bbiab)
13:23offby1tx
13:27LauJensenEvening team
13:39joshua-choiI think I asked this before, but I don't remember the answer. Is there a high-level function mystery so that (mystery f g) is equivalent to (fn [& args] (and (apply f args) (apply g args)))?
13:41slyphonjoshua-choi: you could write that macro pretty easily
13:42joshua-choiYeah. Just wondering if there was a standard one.
13:46texodusAnyone bored who wants to give me some feedback on a Clojure library I wrote to wrap Netty? http://github.com/texodus/saturnine
16:25greybeardIs there One True Swank/Slime Configuration document? Particularly in the use of swank-clojure-extra-classpaths?
16:29greybeardMy code runs fine from the command line - but not in slime. It doesn't seem to find the jars as I get the "No suitable driver found for jdbc:mysql://..."
16:43dnolengreybeard: install via ELPA and you'll probably find it easier to get working estup
16:43dnolenestup -> setup
16:45greybeardI did use ELPA. But I prefer to have less magic and more understanding.
16:48greybeardIn .emacs I have something like: (setq swank-clojure-extra-classpaths (list "/Users/edglas/jars/" "/opt/jars/"))
17:16bsteuberwhy is there a difference between concat and lazy-cat, though concat states the seq is lazy?
17:18hiredmanone of them is a macro so it can make things lazier
17:19bsteuberhmm
17:19hiredman,(first (lazy-cat [1] (println :x)))
17:19clojurebot1
17:19hiredman,(first (lconcat [1] (println :x)))
17:19clojurebotjava.lang.Exception: Unable to resolve symbol: lconcat in this context
17:19hiredman,(first (concat [1] (println :x)))
17:19clojurebot1
17:19clojurebot:x
17:20bsteuber,(take 4 (concat (repeat 1) [2]))
17:20clojurebot(1 1 1 1)
17:21bsteuberi see
17:21bsteuberthe there is only a difference when side effects are involved?
17:21bsteuberor is there a pure example where they differ?
17:22hiredmanif the things you are concating are all lazy it makes no difference
17:22hiredmanwell
17:23hiredmanlazy-cat wraps things in an additional layer of laziness
17:23bsteuberso if I have a 5000000 element array as first argument, will concat traverse it eagerly?
17:23hiredmanno
17:23bsteubergood
17:23hiredmanconcat doesn't traverse
17:24bsteuberok, so it is usually "lazy enough"
17:24hiredmanbut if you have a function that generats a 50000 element list, and (concat (f) [1]) because concat is a function f will be evaluated
17:24hiredmaner
17:24hiredman(f)
17:25hiredmanthe arguments to functions are evaluated and the result is passed
17:25bsteuberok, that makes sense
17:25hiredmanlazy-cat essential generates a thunk of each argument and that thunk is not called until it is needed
17:26bsteuberso I will just remember that not even function calls are evaluated
17:26bsteuberthank you :)
17:28chouserdisconnecting to rearrange my network at home. please refrain from saying anything interesting until the logger is back online.
17:28chouser:-)
17:36bsteuberI'm wondering why replicate is there as well as repeat
17:36chouserbsteuber: historical reasons. I would expect replicate to go away
17:38bsteuberchouser: ic - so maybe it should be marked depricated?
17:38chousersounds good to me
17:40rhickeyticket/patch welcome
17:46bsteuberoh, didn't know it is spelled deprecated
17:47bsteuberrhickey: ok, sounds like fun and a good reason to start learing about your assembla stuff
17:47bsteuberthough it's just a patch of one line saying "DEPRECATED" :)
17:54hiredman,(doc *asert*)
17:54clojurebotGabh mo leithscéal?
17:54hiredman,(doc *assert*)
17:54clojurebot"; "
17:54tomojwhat's that for?
17:55hiredmangood question
17:55bsteuber,*assert*
17:55clojurebottrue
17:55hiredman,(doc assert)
17:55clojurebot"([x]); Evaluates expr and throws an exception if it does not evaluate to logical true."
17:56tomojaha
17:57tomojso bind *assert* to false to skip assertions
17:58hiredman(when *assert* (binding [*out* *err*] (println "X is depricated, use Y")))
17:58hiredmanpre
18:00bsteuber.(assert false)
18:00bsteuber,(binding [*assert* false] (assert false))
18:00clojurebotjava.lang.Exception: Assert failed: false
18:01bsteuberhmm
18:04hiredman,(binding [*assert* false] *assert*)
18:04clojurebotfalse
18:07hiredman,(binding [*assert* false] (macroexpand '(assert false)))
18:07clojurebotnil
18:08hiredmanit must be some kind of quirk of clojurebot's sandbox
18:08hiredmanor not
18:22bsteuberhiredman: I think the binding is done at run-time while the macroexpand already expands at compile-time
18:23bsteuberso *assert* is still true at this point
18:23hiredmanmm
18:25bsteuberso how can we rebind *assert* at compile-time?
18:25hiredmanwrite or find a binding macro
18:26bsteubernot sure if it's that easy
18:26hiredmanwhy not?
18:28bsteuber,(defmacro with-production-mode [& body] (binding [*assert* false] `(do ~@body)))
18:28clojurebotDENIED
18:31bsteuber(with-production-mode (assert false))
18:31bsteuberthis fails
18:32bsteuberbecause the binding is only there when the `(do) is returned, but not when it's macroexpanded
18:34bsteuberwe had to do sth like that
18:34bsteuber(defmacro with-production-mode [form] (binding [*assert* false] (macroexpand form)))
18:34bsteuberbut explicit macroexpand is ugly
18:34hiredman,(X [*assert* false] (assert false))
18:34clojurebotnil
18:35hiredmanbut that is rather horrible
18:35bsteuber,(doc X)
18:35clojurebot"([[name value] & code]); "
18:40bsteuberyeah, why not
18:41bsteuberin CL you would do this kind of thing with (eval-when (compile) ...)
18:42bsteuberbut the CL stuff is doing side effects, so you can't transfer this to clojure easily
18:42hiredman(defmacro X’ [x & code] `(binding ~x (eval '~@code)))
18:43hiredmanthere really should be a do in there somewhere
18:45bsteuberhow about eval and the environment?
18:45bsteuberit won't work in a let, right?
18:45hiredmanright
18:46hiredmanit's hardly perfect
18:46hiredmanif you really want to you can always alter-var-root
18:47bsteubersomehow it stays true
18:48bsteubermaybe we're not supposed to alter the vars from core
18:48hiredmanoh
18:49hiredmandirect binding maybe
18:49bsteuber,`macroexpand-all
18:49clojurebotclojure.walk/macroexpand-all
18:50hiredmanand the repl must bind it
18:50hiredman,(set! *assert* false)
18:50clojurebotjava.lang.IllegalStateException: Can't change/establish root binding of: *assert* with set
18:50hiredmanbut clojurebot doesn't
18:50bsteuber(defmacro in-prod [& code] (binding [*assert* false] `(do ~@(macroexpand-all code))))
18:50bsteuber,(defmacro in-prod [& code] (binding [*assert* false] `(do ~@(macroexpand-all code))))
18:50clojurebotDENIED
18:51bsteuberthat does the job
18:52bsteuberthough I don't know whether it is okay to macroexpand-all on arbitrary code
18:52bsteuberbut I guess it's better that eval :)
18:54bsteuberwhy did clojurebot deny my in-prod macro?
18:55hiredmanclojurebot doesn't allow defs
18:56bsteuberhm okay :)
20:05ichernetskyHi. Is there possibility to gen-class some class that has some java annotation?
20:20danlarkinichernetsky: I don't think clojure can do annotations yet
20:20ichernetskydanlarkin: Is it going to be added in the near future?
20:21danlarkinnot to my knowledge
22:48mikemhi, if I have a function with arguments such as [first & rest], in the body of the function rest is a list. how can I pass that list to another function which accepts arguments the same way (ie: [firt & rest])?
22:52nteon,(doc apply)
22:52clojurebot"([f args* argseq]); Applies fn f to the argument list formed by prepending args to argseq."
22:52nteonmikem: so (apply some-fn rest)
22:56mikemnteon: I'm actually trying to reply to this email on the mailing list: http://groups.google.com/group/clojure/browse_thread/thread/ea67c317dafb47df
22:56mikemin the last posting, the author wraps (struct-map) in his own function, passing in & init, but when inits is passed to struct-map it's a single list, not a variable number of arguments.
23:00nteonmikem: I would guess its because he's returning the struct 'sm', not the modified one returned from assoc
23:02mikemactually, it's the call to (struct-map ) which fails. the correct way to call struct-map is: (struct-map st :a 1 :b 2) ... inside his my-struct-map, it ends up being called (struct-map st (:a 1 :b 2))
23:02mikemso I'd like to "expand" that sequence (:a 1 :b 2) before passit it to the real struct-map
23:02mikems/passit/passing/
23:06nteonmikem: (apply struct-map s inits)
23:06nteonis the particular change
23:07nteonah, I misread that if statement
23:07mikemnteon: ok, that works
23:07mikemthanks
23:08mikemyeah, the if statement is correct
23:08nteonmikem: glad I could help
23:31hiredmanhttp://gist.github.com/324145 my first chunked seq