#clojure log - Apr 30 2011

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

1:36 semperos: chrissbx: thanks for pointing out that repo

1:36 I piggy-backed on Seth Schroeder's seplunk-clj-irc lib, since he already took care of scraping the HTML for the info

1:37 spelunk-clj-irc, rather

2:19 bartj: can I use leningen to create a jar for a Java application ?

2:19 kencausey: lein help

2:19 uberjar might be what you are looking for but read the details

2:21 bartj: kencausey, I fail to understand the diff b/w jar and uberjar

2:24 kencausey: via google: http://zef.me/2470/building-clojure-projects-with-leiningen

2:26 It 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.

2:32 amalloy: yes. 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

2:32 it should really only be used for deploying end users

3:09 bartj: amalloy_, kencausey thank you! I am getting started using lein.

3:47 is it incorrect to use: clojure 1.1.0-master-SNAPSHOT ?

3:47 and clojure-contrib 1.0-SNAPSHOT ?

3:48 in the lein build file

3:48 hiredman: that is very old

3:49 bartj: and isn't even present in the clojars too, I believe

4:06 instead of .clj file, I have a Blah.java file

4:06 and my project.clj file has a ":java-source-path true"

4:07 yet, the class file for the Blah.java doesn't seem to get generated

4:26 is it not possible to use a Java class with a main method as the "starting" class ?

4:26 when using leiningen?

5:14 fliebel: bartj: I assume there is a reason some people use Maven, but I don't know if lein can do it.

5:17 How would you guys like you maps matched? Exact keys or at least the specified keys?

5:17 ( http://pepijndevos.nl/clojure-micro-pattern-matcher )

5:42 thorwil: fliebel: both/either?

5:47 raek: bartj: you can compile java source files with lein nowadays, however :java-source-path should be set to a path, not true

6:03 bartj: https://gist.github.com/949577

6:03 it is indeed possible :)

6:04 just run "lein uberjar", and then you can run it with "java -jar foo-1.0.0-SNAPSHOT-standalone.jar"

7:01 kzar: Does 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)]]

7:18 bartj: raek, thanks, I'll try that out!

7:34 fliebel: MayDaniel: I noticed you forked my gist. Just saying I've added a lot of stuff since then. :)

8:08 I'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?

8:12 Apparently… Why does recur do that?

8:25 Can I check what holds the monitor to an object?

10:23 (assert (not (possible? seque)))

10:25 I'd bake an apple pie for the one to prove me wrong :)

13:07 mec: ,(clojure.lang.RT/nextID)

13:07 clojurebot: 1331

13:07 mec: ,(clojure.lang.RT/nextID)

13:07 clojurebot: 1334

13:07 fliebel: Is that what gensym uses?

13:08 mec: why does that update different amounts? On mine its by 5, but in the source it should be just by 1

13:08 fliebel: ya

13:08 fliebel: mec: I assume that's because of aother parts of Clojure consuming them as well?

13:10 mec: nextID is direct and the only thing that uses it otherwise is gensym, i cant make heads or tails of it

13:13 oh maybe the reader uses them

13:13 or printer

13:14 ,[(clojure.lang.RT/nextID) (clojure.lang.RT/nextID)]

13:14 clojurebot: [1337 1338]

13:14 mec: looks that way

13:14 ,*clojure-version*

13:14 clojurebot: {:major 1, :minor 2, :incremental 0, :qualifier ""}

13:15 fliebel: hm, I also have not figured out yet in which cases a transient mutates or copies.

13:16 mec: when the underlying data structure changes for efficiency

13:16 fliebel: mec: Sure, but when and where does that happen?

13:21 mec: {} are arraymaps that change to hashmaps with more than 8 keys, i think thats about it

13:49 fliebel: How cool is that, using a queue to manage a queue.

13:52 Anyway, it works perfectly and takes everything you trow at it.

13:54 … except for the moronic test :)

14:27 zrilak: Hi folks, noobish question ahead.

14:28 fliebel: zrilak: bring it on! I love questions :)

14:30 arohner: clojurebot: questions

14:30 clojurebot: Titim gan éirí ort.

14:30 arohner: I guess it forgot that one

14:30 fliebel: arohner: What one?

14:30 ~ask

14:30 clojurebot: Excuse me?

14:30 arohner: something about don't ask if you can ask a question. just ask the question

14:30 zrilak: argh, this is so complex, I need to find a good way to write it down :)

14:31 I'm trying to define something like this:

14:31 fliebel: Well, he did not ask anything really, he just said hi :)

14:31 zrilak: I have a state of a game, over which I'll be performing a number of effects during the course of the program.

14:31 fliebel: I like this one better; xy?

14:32 zrilak: Ergo:

14:32 (defprotocol Effect

14:32 "An in-game effect."

14:32 (act [_ state] "Make the effect act on the game state."))

14:33 Effects are logically grouped into 30 or so classes of effects, which differ by their behavior and parameters. I call those classes "Powers".

14:33 Good so far? :)

14:33 fliebel: zrilak: I'm doing something with games currently: https://github.com/pepijndevos/Begame/blob/master/src/examples/pong.clj#L12 Not 3D though.

14:33 arohner: zrilak: yeah

14:34 zrilak: fliebel: cool, I'll take a look; I'm not going into 3D yet, just interested in designing a semi-universal engine.

14:34 fliebel: zrilak: Well, you're looking at one there, hopefully :P

14:34 zrilak: Anyways, to help build different Effects, I have this:

14:34 (defprotocol Power

14:34 "Takes a parameter map and yields an effect."

14:34 (actualize [_ ctor-map] "Build an effect."))

14:35 fliebel: The act method takes a world and the current object and returns the new object, in my case.

14:35 arohner: zrilak: btw, if you're pasting multi-line code, it's better to use gist or pastie or something

14:35 zrilak: ah, good point

14:35 why should I be inlining everything here

14:38 ah, actually, pizza is here; I'll be back later -- thanks for your patience so far!

14:56 fliebel: How 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:05 There, project-in-a-gist: https://gist.github.com/946857

15:30 Do we have a canonical answer to this? https://twitter.com/#!/bramduvigneau/status/64408805215191040

15:31 Mayabe clojurebot knows… clojurebot, Clojure is a nice language, do you know why?

15:31 why?

15:31 clojurebot: http://clojure.org/rationale

16:01 fliebel: When I run lein jar, it prints Copying 1 file to <lib path> and then… nothing.

16:04 I don't think lein likes me making a jar with :source-path ""

16:10 amalloy: anyone?

16:10 clojurebot: Please 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:10 amalloy: fliebel: ^

16:10 miwillhite: I'm brand new to clojure and am having issues importing duck-streams from clojure-contrib

16:11 Please take a look at the following code and error…

16:11 http://pastebin.com/r4cynuza

16:11 I set up my project with leiningen

16:12 mefesto: miwillhite: can you use clojure-contrib v1.2.0 instead?

16:12 fliebel: amalloy: Is that to me, or just to show the right command? ;)

16:12 raek: miwillhite: use clojure-contrib 1.2.0 instead

16:12 amalloy: fliebel: well, you didn't ask "can anyone help me with clojurebot?" so i'll give you the benefit of the doubt

16:13 raek: you usually get this wierd "RestFN" error when you mix incompatible ahead of time compiled versions of libraries

16:13 amalloy: miwillhite: duck-streams are also pretty old, i think

16:13 miwillhite: whats the best way to read the contents of a file?

16:13 raek: ,(doc slurp)

16:13 clojurebot: "([f & opts]); Reads the file named by f using the encoding enc into a string and returns it."

16:14 raek: miwillhite: that, and maybe functions from clojure.java.io (which superscedes duck-streams)

16:14 (slurp is included in clojure.core nowadays)

16:15 fliebel: amalloy: 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:15 miwillhite: ah yeah okay

16:15 thanks

16:15 amalloy: fliebel: man, i was just showing you how to use the command

16:15 $google lein project.clj sample

16:15 sexpbot: First out of 1810 results is: technomancy/leiningen - GitHub

16:15 https://github.com/technomancy/leiningen

16:16 amalloy: that said, i think the sample project.clj has that

16:16 raek: miwillhite: 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:16 amalloy: fliebel: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L129

16:16 fliebel: amalloy: 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:17 amalloy: fliebel: you said "custom source path"; you want your source path to be the project root?

16:17 fliebel: amalloy: yes. gists don't have a directory structure ;)

16:17 amalloy: if so i'd try "/" and "."; i don't expect "" to work

16:18 fliebel: okay, I'll try. Just using it from the repl works fine though.

16:18 miwillhite: okay 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:19 mefesto: miwillhite: if the file is bundled in your jar as a resource then you can use clojure.java.io/resource for that

16:20 fliebel: amalloy: Exception in thread "main" java.util.zip.ZipException: duplicate entry: project.clj

16:20 amalloy: fliebel: makes sense. i suppose

16:20 fliebel: amalloy: Yea, there was some exlude command...

16:20 raek: miwillhite: 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:21 fliebel: https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L146

16:22 raek: miwillhite: 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:22 a File object can then be passed to reader, etc

16:23 miwillhite: okay thanks guys, I'll take a look into that stuff

16:23 fliebel: amalloy: And then I'm back where I started, and where lein hangs after saying "Copying 1 file to /Users/pepijndevos/git/seqex/lib"

16:25 So, either I need to debug lein somehow, or just live with aot'd files.

16:34 Somelauw: (Integer/parseInt (read-line)) to read nums

16:44 currentB: is 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:45 fliebel: currentB: No, but you *can* use an anonymous function.

16:45 currentB: for example (defn func [x y & {:keys [named-args]}] name-args) then call (partial func :named-args "test")

16:46 amalloy: currentB: you could also use my argument-reordering HOF. something like (partial (reorder f) :name x :size 10)

16:46 fliebel: #(function %1 %2 :arg 2 :argb 3)

16:46 amalloy: though i suspect that's too much trouble in practice and fliebel's answer is better

16:46 Somelauw: (map #(read-string (read-line)) (range numPoly)))]

16:46 currentB: cool thanks guys

16:47 amalloy: Somelauw: no good

16:47 Somelauw: (map #(read-string (read-line)) (range numPoly)))

16:47 amalloy: the function you pass to map needs to accept an argument

16:47 fliebel: Somelauw: You could use repeatedly

16:47 amalloy: you want (repeatedly num-poly (comp read-string read-line))

16:47 Somelauw: hmm, so should I use for here?

16:48 ,(repeatedly 5 3)

16:48 clojurebot: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn

16:48 Somelauw: ,(repeatedly 5 #3)

16:48 clojurebot: No dispatch macro for: 3

16:49 Somelauw: ok

16:50 ,(#(3))

16:50 clojurebot: java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn

16:51 fliebel: ,(#(do 3))

16:51 clojurebot: 3

16:51 amalloy: Somelauw: you could keep writing nonsense and hoping for the best, or tell someone what your goal is

16:53 fliebel: you're encouraging evil. (constantly 3)

16:55 fliebel: amalloy: Mhpf, maybe. Idk, I'm just going to bed. Good luck, and good night :) Maybe tomorrow will hold less evil.

16:56 amalloy: hah

16:56 Somelauw: thanks for the evilness

16:57 fliebel: amalloy: 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:58 ~xy

16:58 clojurebot: xy is http://mywiki.wooledge.org/XyProblem

16:58 amalloy: fliebel: i will put up with evil from someone trying to deliver a coherent queue

16:59 fliebel: amalloy: haha, I have something that works, but I don;t like the idea of using several queue to coordinate one.

16:59 Somelauw: Well, I want to read numPoly numbers from the commandline.

17:00 fliebel: amalloy: https://gist.github.com/934781

17:00 Somelauw: And I was testing the repeatedly function.

17:18 Because I want to learn clojure, so for a practice I was writing a polynomial solver which needs the read the polynomials from *in*?

17:19 amalloy: Somelauw: my point was you weren't trying out repeatedly; you were just writing anonymous functions that can't be called

17:19 reading polynomials from *in* is great, knock yourself out

17:22 raek: Somelauw: you might be interested in this: http://groups.google.com/group/leiningen/browse_thread/thread/f9f9ed97eb8a2928/ccab95588ef50d05

17:22 oh, (read-line) works fine in lein repl... ignore that...

17:27 Somelauw: What is the best way to debug. When simply running it, it does show exceptions, but no linenumbers.

17:29 raek: if you (re)load the namespace with (requie 'the.namespace) or (require 'the.namespace :reload), line numbers should be there

17:32 if you use emacs, swank-cdt is worth checking out: http://georgejahad.com/clojure/swank-cdt.html

17:32 Somelauw: I don't really understand. I am using cake, but I am running this script standalone.

17:33 i use vim, unfortunately

17:34 But I will remember swank-cdt for when I ever convert.

17:35 But I think cdt can also be ran standalone.

17:40 raek: It'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:20 amalloy: is 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:24 dakrone: amalloy: https://github.com/mmcgrana/ring/wiki/Libraries has some

18:26 amalloy: thanks dakrone

18:46 mec: Is there anything to check if something is Seqable?

18:49 Something like (seq x) that wont throw an exception on (sec 5)

18:52 amalloy: mec: (coll? x) comes close

18:54 mec: im actually kind of surprised seq throws an exception instead of just returning nil

19:00 i guess ill just have to (try (seq x))

19:17 TimMc: ,(empty? 5)

19:17 clojurebot: java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer

19:17 TimMc: fascinating

19:18 dnolen: ,(instance? clojure.lang.Seqable 5)

19:18 clojurebot: false

19:19 dnolen: mec: ^

19:19 ,(instance? clojure.lang.Seqable [])

19:19 clojurebot: true

19:20 mec: ,(instance? clojure.lang.Seqable (to-array [1 2 3]))

19:20 clojurebot: false

19:20 mec: ,(seq (to-array [1 2 3]))

19:20 clojurebot: (1 2 3)

19:25 amalloy: same for String and the other types the runtime secretly makes seqable

19:27 mec: ya thats why it surprises me theres no parallel seq? function

19:28 amalloy: mec: seqable, you mean. seq? exists and doesn't do what you want

19:28 mec: i mean seq? doesnt parallel seq

19:38 dnolen: mec: ah yeah, a thought define a protocol like ISeqable, extend-type on the primitive array types, extend-protocol ISeqable to clojure.lang.Seqable

19:39 mec: did a quick test and it seems to work and would be fast.

19:40 mec: faster than (try (seq x)) ?

19:40 amalloy: mec: for sure

19:40 nothing is slower than try/catch :P

19:40 mec: i thought try/catch was just a label and a goto

19:41 amalloy: no

19:41 mec: maybe thats why my implementation of multiple-value-bind was so slow, binding has a try/finally in there

19:42 amalloy: it 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:42 dnolen: mec: 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:42 amalloy: that too. creating an exception snapshots the stack

19:42 mec: ah

19:56 TimMc: ,(coll? nil)

19:56 clojurebot: false

20:01 TimMc: So, the set of things that it is safe to call seq on: nil, and anything that coll? approves?

20:02 amalloy: TimMc: no. like i said, it only gets you close

20:02 &((juxt coll? seq) "test")

20:02 sexpbot: ⟹ [false (\t \e \s \t)]

20:02 TimMc: blerg, right

20:03 ,(coll? (seq "foo"))

20:03 clojurebot: true

20:05 TimMc: So... there's no seqable? function?

20:06 dnolen: TimMc: mostly likely because it would be a slow test, many things are seqable. Thus my above idea.

20:08 mec: if only seq didnt throw an exception :x

20:10 amalloy: mec: that's a bad idea. having seq be slow would be a lot worse than having a slow seqable? function available

20:10 TimMc: i think there's one in contrib, somewhere

20:16 mec: amalloy: what do you mean seq be slow?

20:16 amalloy: mec: if seq checked for seqable-ness to return nil instead of throwing an exception it would be slow

20:17 mec: not really, its a giant if statement, and if it gets to the end it throws an exception, so just return nil instead

20:17 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L462

20:17 amalloy: hm

20:18 but

20:18 then how could you tell (seq 5) from (seq nil) or (seq [])

20:26 mec: thats the point, right now (seq 5) throws an exception so the only way to check is try/catch

20:29 amalloy: mec: and if you made (seq 5) return nil, there would be no way at all to check

20:30 you'd make your particular use-case more convenient, for sure

20:32 mec: beats having to do this https://gist.github.com/950133

20:32 dnolen: mec: 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:39 amalloy: if 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:50 dnolen: mec: https://gist.github.com/950144

20:51 this test can be run 1e8 times in ~380ms

20:52 needs to extend to the arrays o' course

21:01 mec: how would you extend for arrays?

21:16 ,(clojure.lang.ArraySeq/createFromObject (to-array [1 2 3]))

21:16 clojurebot: java.lang.IllegalArgumentException: No matching method: createFromObject

21:16 mec: ,(show clojure.lang.ArraySeq)

21:16 clojurebot: java.lang.Exception: Unable to resolve symbol: show in this context

21:21 mec: dnolen: wow thats a lot faster than how clojure.core does seq

22:11 cemerick: This 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

Logging service provided by n01se.net