#clojure logs

2011-04-30

01:36semperoschrissbx: thanks for pointing out that repo
01:36semperosI piggy-backed on Seth Schroeder's seplunk-clj-irc lib, since he already took care of scraping the HTML for the info
01:37semperosspelunk-clj-irc, rather
02:19bartjcan I use leningen to create a jar for a Java application ?
02:19kencauseylein help
02:19kencauseyuberjar might be what you are looking for but read the details
02:21bartjkencausey, I fail to understand the diff b/w jar and uberjar
02:24kencauseyvia google: http://zef.me/2470/building-clojure-projects-with-leiningen
02:26kencauseyIt appears to be determined by how you expect to deliver dependencies, jar assumes you will provide the dependencies seperately, uberjar packages all into one. That's my understanding anyway.
02:32amalloyyes. uberjar creates your jar, and then stuffs all your dependencies into it as well, so that the end user doesn't need dependency-resolution tools
02:32amalloyit should really only be used for deploying end users
03:09bartjamalloy_, kencausey thank you! I am getting started using lein.
03:47bartjis it incorrect to use: clojure 1.1.0-master-SNAPSHOT ?
03:47bartjand clojure-contrib 1.0-SNAPSHOT ?
03:48bartjin the lein build file
03:48hiredmanthat is very old
03:49bartjand isn't even present in the clojars too, I believe
04:06bartjinstead of .clj file, I have a Blah.java file
04:06bartjand my project.clj file has a ":java-source-path true"
04:07bartjyet, the class file for the Blah.java doesn't seem to get generated
04:26bartjis it not possible to use a Java class with a main method as the "starting" class ?
04:26bartjwhen using leiningen?
05:14fliebelbartj: I assume there is a reason some people use Maven, but I don't know if lein can do it.
05:17fliebelHow would you guys like you maps matched? Exact keys or at least the specified keys?
05:17fliebel( http://pepijndevos.nl/clojure-micro-pattern-matcher )
05:42thorwilfliebel: both/either?
05:47raekbartj: you can compile java source files with lein nowadays, however :java-source-path should be set to a path, not true
06:03raekbartj: https://gist.github.com/949577
06:03raekit is indeed possible :)
06:04raekjust run "lein uberjar", and then you can run it with "java -jar foo-1.0.0-SNAPSHOT-standalone.jar"
07:01kzarDoes anyone know what's wrong with this Enlive selector? (It broke when I tried to add in the rel=stylesheet part, otherwise it works.) [[:head] [:link (html/attr= :rel "stylesheet") (html/nth-of-type 1)]]
07:18bartjraek, thanks, I'll try that out!
07:34fliebelMayDaniel: I noticed you forked my gist. Just saying I've added a lot of stuff since then. :)
08:08fliebelI'm using sleep and notify inside a locking macro, but it still claims to give an java.lang.IllegalMonitorStateException. Does using recur or calling other functions affect the locking?
08:12fliebelApparently… Why does recur do that?
08:25fliebelCan I check what holds the monitor to an object?
10:23fliebel(assert (not (possible? seque)))
10:25fliebelI'd bake an apple pie for the one to prove me wrong :)
13:07mec,(clojure.lang.RT/nextID)
13:07clojurebot1331
13:07mec,(clojure.lang.RT/nextID)
13:07clojurebot1334
13:07fliebelIs that what gensym uses?
13:08mecwhy does that update different amounts? On mine its by 5, but in the source it should be just by 1
13:08mecfliebel: ya
13:08fliebelmec: I assume that's because of aother parts of Clojure consuming them as well?
13:10mecnextID is direct and the only thing that uses it otherwise is gensym, i cant make heads or tails of it
13:13mecoh maybe the reader uses them
13:13mecor printer
13:14mec,[(clojure.lang.RT/nextID) (clojure.lang.RT/nextID)]
13:14clojurebot[1337 1338]
13:14meclooks that way
13:14mec,*clojure-version*
13:14clojurebot{:major 1, :minor 2, :incremental 0, :qualifier ""}
13:15fliebelhm, I also have not figured out yet in which cases a transient mutates or copies.
13:16mecwhen the underlying data structure changes for efficiency
13:16fliebelmec: Sure, but when and where does that happen?
13:21mec{} are arraymaps that change to hashmaps with more than 8 keys, i think thats about it
13:49fliebelHow cool is that, using a queue to manage a queue.
13:52fliebelAnyway, it works perfectly and takes everything you trow at it.
13:54fliebel… except for the moronic test :)
14:27zrilakHi folks, noobish question ahead.
14:28fliebelzrilak: bring it on! I love questions :)
14:30arohnerclojurebot: questions
14:30clojurebotTitim gan éirí ort.
14:30arohnerI guess it forgot that one
14:30fliebelarohner: What one?
14:30fliebel~ask
14:30clojurebotExcuse me?
14:30arohnersomething about don't ask if you can ask a question. just ask the question
14:30zrilakargh, this is so complex, I need to find a good way to write it down :)
14:31zrilakI'm trying to define something like this:
14:31fliebelWell, he did not ask anything really, he just said hi :)
14:31zrilakI have a state of a game, over which I'll be performing a number of effects during the course of the program.
14:31fliebelI like this one better; xy?
14:32zrilakErgo:
14:32zrilak (defprotocol Effect
14:32zrilak "An in-game effect."
14:32zrilak (act [_ state] "Make the effect act on the game state."))
14:33zrilakEffects are logically grouped into 30 or so classes of effects, which differ by their behavior and parameters. I call those classes "Powers".
14:33zrilakGood so far? :)
14:33fliebelzrilak: I'm doing something with games currently: https://github.com/pepijndevos/Begame/blob/master/src/examples/pong.clj#L12 Not 3D though.
14:33arohnerzrilak: yeah
14:34zrilakfliebel: cool, I'll take a look; I'm not going into 3D yet, just interested in designing a semi-universal engine.
14:34fliebelzrilak: Well, you're looking at one there, hopefully :P
14:34zrilakAnyways, to help build different Effects, I have this:
14:34zrilak(defprotocol Power
14:34zrilak "Takes a parameter map and yields an effect."
14:34zrilak (actualize [_ ctor-map] "Build an effect."))
14:35fliebelThe act method takes a world and the current object and returns the new object, in my case.
14:35arohnerzrilak: btw, if you're pasting multi-line code, it's better to use gist or pastie or something
14:35zrilakah, good point
14:35zrilakwhy should I be inlining everything here
14:38zrilakah, actually, pizza is here; I'll be back later -- thanks for your patience so far!
14:56fliebelHow can I use a gist in a project? Gists have git access, and I heard lein and cake support some form of checkouts. Will that work?
15:05fliebelThere, project-in-a-gist: https://gist.github.com/946857
15:30fliebelDo we have a canonical answer to this? https://twitter.com/#!/bramduvigneau/status/64408805215191040
15:31fliebelMayabe clojurebot knows… clojurebot, Clojure is a nice language, do you know why?
15:31fliebelwhy?
15:31clojurebothttp://clojure.org/rationale
16:01fliebelWhen I run lein jar, it prints Copying 1 file to <lib path> and then… nothing.
16:04fliebelI don't think lein likes me making a jar with :source-path ""
16:10amalloyanyone?
16:10clojurebotPlease do not ask if anyone uses, knows, is good with, can help you with <some program or library>. Instead, ask your real question and someone will answer if they can help.
16:10amalloyfliebel: ^
16:10miwillhiteI'm brand new to clojure and am having issues importing duck-streams from clojure-contrib
16:11miwillhitePlease take a look at the following code and error…
16:11miwillhitehttp://pastebin.com/r4cynuza
16:11miwillhiteI set up my project with leiningen
16:12mefestomiwillhite: can you use clojure-contrib v1.2.0 instead?
16:12fliebelamalloy: Is that to me, or just to show the right command? ;)
16:12raekmiwillhite: use clojure-contrib 1.2.0 instead
16:12amalloyfliebel: well, you didn't ask "can anyone help me with clojurebot?" so i'll give you the benefit of the doubt
16:13raekyou usually get this wierd "RestFN" error when you mix incompatible ahead of time compiled versions of libraries
16:13amalloymiwillhite: duck-streams are also pretty old, i think
16:13miwillhitewhats the best way to read the contents of a file?
16:13raek,(doc slurp)
16:13clojurebot"([f & opts]); Reads the file named by f using the encoding enc into a string and returns it."
16:14raekmiwillhite: that, and maybe functions from clojure.java.io (which superscedes duck-streams)
16:14raek(slurp is included in clojure.core nowadays)
16:15fliebelamalloy: Okay. I admit I did not add much detail or an explicit question. The question would be: How can I make a jar with leiningen when using a custom source path?
16:15miwillhiteah yeah okay
16:15miwillhitethanks
16:15amalloyfliebel: man, i was just showing you how to use the command
16:15amalloy$google lein project.clj sample
16:15sexpbotFirst out of 1810 results is: technomancy/leiningen - GitHub
16:15sexpbothttps://github.com/technomancy/leiningen
16:16amalloythat said, i think the sample project.clj has that
16:16raekmiwillhite: well, slurp returns the file as one big string. you could also check out line-seq (just give it what clojure.java.io/reader returns)
16:16amalloyfliebel: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L129
16:16fliebelamalloy: yeayea, I know, it goes :source-path "", but then lein does not want to make a jar anymore, onless I specify that I want to aot and exclude source files.
16:17amalloyfliebel: you said "custom source path"; you want your source path to be the project root?
16:17fliebelamalloy: yes. gists don't have a directory structure ;)
16:17amalloyif so i'd try "/" and "."; i don't expect "" to work
16:18fliebelokay, I'll try. Just using it from the repl works fine though.
16:18miwillhiteokay one more question…what is the best practice for file paths? say I want to read a file at the root of my application…
16:19mefestomiwillhite: if the file is bundled in your jar as a resource then you can use clojure.java.io/resource for that
16:20fliebelamalloy: Exception in thread "main" java.util.zip.ZipException: duplicate entry: project.clj
16:20amalloyfliebel: makes sense. i suppose
16:20fliebelamalloy: Yea, there was some exlude command...
16:20raekmiwillhite: to do what mefesto said, just make a resources/ directory in your project, and leiningen will include it in the classpath and generated jars
16:21fliebelhttps://github.com/technomancy/leiningen/blob/master/sample.project.clj#L146
16:22raekmiwillhite: but for arbitrary paths in the file system, you can join the segments in a platform independent way with clojure.java.io/file (in java-land, a 'file' is a file path...)
16:22raeka File object can then be passed to reader, etc
16:23miwillhiteokay thanks guys, I'll take a look into that stuff
16:23fliebelamalloy: And then I'm back where I started, and where lein hangs after saying "Copying 1 file to /Users/pepijndevos/git/seqex/lib"
16:25fliebelSo, either I need to debug lein somehow, or just live with aot'd files.
16:34Somelauw(Integer/parseInt (read-line)) to read nums
16:44currentBis there a way to use partial to create a function by only giving it it's named arguments, which come after its regular args?
16:45fliebelcurrentB: No, but you *can* use an anonymous function.
16:45currentBfor example (defn func [x y & {:keys [named-args]}] name-args) then call (partial func :named-args "test")
16:46amalloycurrentB: you could also use my argument-reordering HOF. something like (partial (reorder f) :name x :size 10)
16:46fliebel#(function %1 %2 :arg 2 :argb 3)
16:46amalloythough i suspect that's too much trouble in practice and fliebel's answer is better
16:46Somelauw (map #(read-string (read-line)) (range numPoly)))]
16:46currentBcool thanks guys
16:47amalloySomelauw: no good
16:47Somelauw(map #(read-string (read-line)) (range numPoly)))
16:47amalloythe function you pass to map needs to accept an argument
16:47fliebelSomelauw: You could use repeatedly
16:47amalloyyou want (repeatedly num-poly (comp read-string read-line))
16:47Somelauwhmm, so should I use for here?
16:48Somelauw,(repeatedly 5 3)
16:48clojurebotjava.lang.RuntimeException: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
16:48Somelauw,(repeatedly 5 #3)
16:48clojurebotNo dispatch macro for: 3
16:49Somelauwok
16:50Somelauw,(#(3))
16:50clojurebotjava.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn
16:51fliebel,(#(do 3))
16:51clojurebot3
16:51amalloySomelauw: you could keep writing nonsense and hoping for the best, or tell someone what your goal is
16:53amalloyfliebel: you're encouraging evil. (constantly 3)
16:55fliebelamalloy: Mhpf, maybe. Idk, I'm just going to bed. Good luck, and good night :) Maybe tomorrow will hold less evil.
16:56amalloyhah
16:56Somelauwthanks for the evilness
16:57fliebelamalloy: I hope you did not mean I am encouraging evil constantly? ;) But, Somelauw, amalloy has some point, it is more important to figure out what you want to do than how you are trying to do it.
16:58fliebel~xy
16:58clojurebotxy is http://mywiki.wooledge.org/XyProblem
16:58amalloyfliebel: i will put up with evil from someone trying to deliver a coherent queue
16:59fliebelamalloy: haha, I have something that works, but I don;t like the idea of using several queue to coordinate one.
16:59SomelauwWell, I want to read numPoly numbers from the commandline.
17:00fliebelamalloy: https://gist.github.com/934781
17:00SomelauwAnd I was testing the repeatedly function.
17:18SomelauwBecause I want to learn clojure, so for a practice I was writing a polynomial solver which needs the read the polynomials from *in*?
17:19amalloySomelauw: my point was you weren't trying out repeatedly; you were just writing anonymous functions that can't be called
17:19amalloyreading polynomials from *in* is great, knock yourself out
17:22raekSomelauw: you might be interested in this: http://groups.google.com/group/leiningen/browse_thread/thread/f9f9ed97eb8a2928/ccab95588ef50d05
17:22raekoh, (read-line) works fine in lein repl... ignore that...
17:27SomelauwWhat is the best way to debug. When simply running it, it does show exceptions, but no linenumbers.
17:29raekif you (re)load the namespace with (requie 'the.namespace) or (require 'the.namespace :reload), line numbers should be there
17:32raekif you use emacs, swank-cdt is worth checking out: http://georgejahad.com/clojure/swank-cdt.html
17:32SomelauwI don't really understand. I am using cake, but I am running this script standalone.
17:33Somelauwi use vim, unfortunately
17:34SomelauwBut I will remember swank-cdt for when I ever convert.
17:35SomelauwBut I think cdt can also be ran standalone.
17:40raekIt's probably easier to get line numbers if you develop in a project. (This is what I am used to, but perhaps there is a cleaver way to it with clojure scripts with cake too.)
18:20amalloyis there a list somewhere of the easily-available ring middlewares? i find myself wanting to write one, but it's pretty simple and i don't know how to find out if it exists already
18:24dakroneamalloy: https://github.com/mmcgrana/ring/wiki/Libraries has some
18:26amalloythanks dakrone
18:46mecIs there anything to check if something is Seqable?
18:49mecSomething like (seq x) that wont throw an exception on (sec 5)
18:52amalloymec: (coll? x) comes close
18:54mecim actually kind of surprised seq throws an exception instead of just returning nil
19:00meci guess ill just have to (try (seq x))
19:17TimMc,(empty? 5)
19:17clojurebotjava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer
19:17TimMcfascinating
19:18dnolen,(instance? clojure.lang.Seqable 5)
19:18clojurebotfalse
19:19dnolenmec: ^
19:19dnolen,(instance? clojure.lang.Seqable [])
19:19clojurebottrue
19:20mec,(instance? clojure.lang.Seqable (to-array [1 2 3]))
19:20clojurebotfalse
19:20mec,(seq (to-array [1 2 3]))
19:20clojurebot(1 2 3)
19:25amalloysame for String and the other types the runtime secretly makes seqable
19:27mecya thats why it surprises me theres no parallel seq? function
19:28amalloymec: seqable, you mean. seq? exists and doesn't do what you want
19:28meci mean seq? doesnt parallel seq
19:38dnolenmec: ah yeah, a thought define a protocol like ISeqable, extend-type on the primitive array types, extend-protocol ISeqable to clojure.lang.Seqable
19:39dnolenmec: did a quick test and it seems to work and would be fast.
19:40mecfaster than (try (seq x)) ?
19:40amalloymec: for sure
19:40amalloynothing is slower than try/catch :P
19:40meci thought try/catch was just a label and a goto
19:41amalloyno
19:41mecmaybe thats why my implementation of multiple-value-bind was so slow, binding has a try/finally in there
19:42amalloyit has to handle nonlocal exceptions: if seq calls something that calls something that throws an exception, the stack has to be smart enough to come back to *you*
19:42dnolenmec: creating an exception object is slow, you want to create one exception instance and reuse it if you're going to do control flow things.
19:42amalloythat too. creating an exception snapshots the stack
19:42mecah
19:56TimMc,(coll? nil)
19:56clojurebotfalse
20:01TimMcSo, the set of things that it is safe to call seq on: nil, and anything that coll? approves?
20:02amalloyTimMc: no. like i said, it only gets you close
20:02amalloy&((juxt coll? seq) "test")
20:02sexpbot⟹ [false (\t \e \s \t)]
20:02TimMcblerg, right
20:03TimMc,(coll? (seq "foo"))
20:03clojurebottrue
20:05TimMcSo... there's no seqable? function?
20:06dnolenTimMc: mostly likely because it would be a slow test, many things are seqable. Thus my above idea.
20:08mecif only seq didnt throw an exception :x
20:10amalloymec: that's a bad idea. having seq be slow would be a lot worse than having a slow seqable? function available
20:10amalloyTimMc: i think there's one in contrib, somewhere
20:16mecamalloy: what do you mean seq be slow?
20:16amalloymec: if seq checked for seqable-ness to return nil instead of throwing an exception it would be slow
20:17mecnot really, its a giant if statement, and if it gets to the end it throws an exception, so just return nil instead
20:17mechttps://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L462
20:17amalloyhm
20:18amalloybut
20:18amalloythen how could you tell (seq 5) from (seq nil) or (seq [])
20:26mecthats the point, right now (seq 5) throws an exception so the only way to check is try/catch
20:29amalloymec: and if you made (seq 5) return nil, there would be no way at all to check
20:30amalloyyou'd make your particular use-case more convenient, for sure
20:32mecbeats having to do this https://gist.github.com/950133
20:32dnolenmec: to slow for a predicate I would think, you could implement my solution (which seems fine to me) and bring it up on the clojure-dev list.
20:39amalloyif you were going to write it that way, mec, you could at least do (or (nil? x) (-> x class .isArray) (some #(instance? % x) [clojure.lang.ISeq...]))
20:50dnolenmec: https://gist.github.com/950144
20:51dnolenthis test can be run 1e8 times in ~380ms
20:52dnolenneeds to extend to the arrays o' course
21:01mechow would you extend for arrays?
21:16mec,(clojure.lang.ArraySeq/createFromObject (to-array [1 2 3]))
21:16clojurebotjava.lang.IllegalArgumentException: No matching method: createFromObject
21:16mec,(show clojure.lang.ArraySeq)
21:16clojurebotjava.lang.Exception: Unable to resolve symbol: show in this context
21:21mecdnolen: wow thats a lot faster than how clojure.core does seq
22:11cemerickThis is totally off-topic, but I just laughed so hard at this I can't help but… http://lgv.s3.amazonaws.com/AmazonFail_explainedByEmployee.jpg