#clojure log - Jan 16 2012

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

0:13 sritchie: amalloy: I finally snuck a macro-writing-macro into my code

0:13 https://github.com/sritchie/midje-cascalog/blob/develop/src/midje/cascalog.clj#L98

0:32 amalloy: heh. why directed at me specifically, sritchie?

0:33 sritchie: amalloy: you gave me the smackdown months ago on that crazy pallet threading macro I kept fighting with

0:33 amalloy: haha oh yeah

0:34 devn: simplest way to drop a map whose key's value is the lowest of all the maps in the set?

0:34 since my set is sorted i am currently using difference

0:35 against #{(last @set)}

0:35 amalloy: disj?

0:36 devn: thanks amalloy

2:43 raek: devn: you can also use (first (rseq the-set)) to get the last element in constant time

2:44 &(let [s (into (sorted-set) "abcde")] (disj s (first (rseq s))))

2:44 lazybot: ⇒ #{\a \b \c \d}

2:48 mindbender: I'm having trouble with my clojurescript repl. I'm able to (do (def env (brwoser/repl-env) (repl/repl env)) and get a clojurescript prompt. I type an expression say (+ 1 1) then I connect with the browser but no evaluation happens. Firefox crashes after sometimes and still no evaluation. And I have no source of log for the connection so I can't really figure out what might be wrong. How do I debug this?

3:24 amalloy: raek: well, log2(n) time, anyway

3:31 Licenser: morning

3:31 raek: yeah. sorry. you're right. of course it should be log2(n).

3:54 Blkt: good morning everyone

5:22 clj_newb: is it just me, or do others also find clojure code easier to read when all arguments are prepended with a keyword?

5:28 bsteuber: clj_newb: depends I guess - the longer the argument list, the more appealing keywords are

5:40 clj_newb: bsteuber: experience so far: a little annoying to write, but I thikn much easier to read

5:40 I like it; the context it provides.

5:54 in clojure, is it bad practice to have Animal/Cat.clj Animal/Dog.clj Animal.clj ?

5:54 where Animal.clj does various imports from Cat/Dog and then exports parts of them?

5:54 ambrosebs: there's no need to, namespace != class

5:55 I would have animals.clj

5:55 (defprotocol Animal ...) (deftype Cat ...) (deftype Dog)

5:55 all in one ns

5:55 clj_newb: I'm sorry, I screwd up the above example; I currently have something like: animal/cat.clj animal/dog.clj animal.clj

5:56 what is concerning me is that I have both x.clj and x as a directory

5:56 is this fear irrational and mispalced?

5:56 ambrosebs: that's perfectly valid

5:56 kral: 'morning

5:57 clj_newb: lastly, is there a way to tell clojure: namespace animal is defined in animal/main.clj ?

5:58 ambrosebs: why not just put everything in animal.clj?

5:58 clj_newb: I like shorter files; easier for me to read

6:00 ambrosebs: why do you want to do something like that with namespaces?

6:01 (your original question)

6:02 there's probably a better way to do what you want

6:03 clj_newb: so I want a single :use line

6:03 that imports all the functions I care about relating to animals

6:03 this includes things in animals/cat.clj animals/dog.clj animals/camel.clj, etc ...; but I dont' want to import all of them (since those files also contains helper functions I don't wnat)

6:04 so basically, there's a subset of animals/*.clj that I commonly use; I want to list them all in an animal.clj, and then just :use animal all over the place

6:04 What is the right pattern that I should be using?

6:04 ambrosebs: you could make the helper functions ^:private

6:04 Chousuke: clj_newb: there's a way to migrate stuff from one namespace to another but it's a hack

6:04 and generally frowned upon

6:05 ambrosebs: generally it's "bad practice" to use an unqualified :use

6:05 clj_newb: Chousuke: oh; I'm just generally using wrappers

6:05 babilen: clj_newb: Look at defn- and ^:private

6:05 clj_newb: Chousuke , ambrosebs , babilen : noted; thanks

6:06 ambrosebs: see (:use animal :only [make-Cat make-Dog])

6:06 Chousuke: honestly though it sounds a lot like you're going for some sort of OOP-ish design :P might be fine in your case though

6:06 ambrosebs: and (:require [animal :as a])

6:07 clj_newb: Chousuke: given my proficiency of clojure; you should tkae whatever you are assuming, choose something a few orders of magnitude worse, and that's probably what I'm doing :-)

6:07 Chousuke: it shouldn't really matter whether your things are cats or dogs or whatnot. You should think more in terms of functions and data.

6:07 clj_newb: it's only recently that i've gotten used to the purity (compared to scheme) of clojure; I feel like I'm still fighting it's namespace tooth and nail

7:56 fullets: Is there a better way to stop slime submitting incomplete expressions that start with { than hacking slime-input-complete-p?

8:37 methods: clojure wiki says to run `mvn package` on clojure-contrib checkout but it seems to fail complaining about missing artifacts

8:41 ambrosebs: methods: contrib is deprecated

8:41 http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go

8:42 methods: oh i was following this http://en.wikibooks.org/wiki/Clojure_Programming/Getting_Started

8:43 ambrosebs: that looks pretty old, but I don't have a better resource handy

8:43 you should start by installing leiningen

8:44 if you find yourself doing "java -jar clojure.jar", then you should be using leiningen

8:45 IMO

8:45 methods: idk i just built from source

8:45 ambrosebs: sure, that works

8:46 methods: then i went through that wiki and installed rlwrap and stuff

8:47 clgv: method: rlwrap ftw. but now its probably time for leiningen. even more if you want to setup projects

8:47 ambrosebs: "lein repl" brings up a repl with rlwrap

8:47 clgv: methods: leiningen uses rlwrap if installed

8:47 methods: ftw ?

8:47 clgv: ftw=for the win ;)

8:58 RazWelles_: Question: This year I want to learn a lisp, and I want to use it for AI. I'll be using a neural network approach, and I'll probably be crunching a great deal of neurons. Speed-wise, would Clojure-CLR be up to this task, or should I employ SBCL?

9:01 I ask CLR because the main library I'll need to interface to is .NET

9:01 other than that, I don't need any other libraries

9:17 clgv: RazWelles_: the answer depends which part will be implemented with clojure? the neuron evaluation and updates?

9:18 RazWelles_: clgv, yes, neuron eval and updates, the .Net just passes the data to it

9:20 clgv: RazWelles_: thats almost only multiplication and addition of values. I guess even in .Net one would consider an attempt to use unsafe code for maximum speedup

9:21 RazWelles_: the interesting question is, how would your project benefit from lisp/clojure?

9:23 RazWelles_: clgv, well I've wanted to cut my teeth on lisp for a while, so I'm using this project as an excuse. As I'm not going to be purely connectionist, I may take other approaches where I feel the code would be easier to read and still do the job-- but mostly, I wanted to learn a lisp, and drop to C when I need to

9:24 clgv: RazWelles_: Clojure 1.3 improves a lot on 1.2 by introducing a better handling of primitive values like doubles which you'll need

9:25 RazWelles_: clgv, oh that'll be nice. Is it possible to use unsafe code from clojure-clr?

9:25 clgv: RazWelles_: for representing your neurons the immutable data structures would be a speed killer, so you cant benefit from using them for this aspect.

9:25 RazWelles_: I see

9:27 clgv: afair you can call any C# method from Clojure CLR similar to the JVM implementation

9:27 lets rephrase that to CLI method ;)

9:27 * RazWelles_ nods

9:28 RazWelles_: So perhaps I should look into SBCL and P/Invoke again?

9:28 Kototama: hi, how can I deploy a compojure web app to allow the one who deploy the webapp to edit the css files?

9:29 clgv: RazWelles_: you should try to get a comparison between both languages related to the characteristics you are interested in and decide then

9:30 RazWelles_: clgv, understood, thank you for your help :)

9:31 clgv: RazWelles_: afair you can integrate Clojure CLR seamlessly with other .Net libs the same as clojure with the java libs

9:31 so that would be one advantage on your list.

9:32 RazWelles_: clgv, yeah, that's was the main reason I wanted to use Clojure, it had ready-to-use .Net access. With SBCL I would have to resort to interfacing myself, wihch is sort of daunting if you're still learning

9:32 *which

9:34 clgv: RazWelles_: maybe you should set up a benchmark to see if clojure 1.3 using primitives is fast enough for you

9:34 RazWelles_: clgv, I guess that means I'll start by learning clojure- I was going to pick up "The Joy of Clojure" today

9:35 babilen: Good choice

9:35 clgv: good book. you have some previous knowledge about lisp?

9:36 RazWelles_: Only a little, I was trying to work through SICP but classes got in the way, I now finally have some time to dedicate to learning a new programming language

9:37 Well, sicp is scheme but.. close? lol

9:51 clgv: RazWelles_: I dont know. I had a lecture on CLOS and am using clojure since almost 1.5 years now

10:31 jonasen: Is there a function to turn a keyword into a namespace qualified keyword? e.g., :bar -> :foo/bar

10:31 noidi_: ::bar

10:32 ,::foo

10:32 clojurebot: :sandbox/foo

10:33 jonasen: noidi_: Yeah, but I need a function. e.g., (ns-qualify 'sandbox :foo) -> :sandbox/foo

10:33 raek: jonasen: you could do something like (symbol "the-namespace" (name some-symbol))

10:33 sorry, replace symbol with keyword... :-)

10:34 jonasen: (defn ns-qualify [ns-name-symbol kw] (keyword (name ns-name-symbol) (name kw)))

10:35 jonasen: ,(keyword "foo" "bar")

10:35 clojurebot: :foo/bar

10:35 jonasen: raek: Thanks!

10:35 raek: but to answer the original question: no, there isn't a function that does exactly that in clojure.core.

10:39 clgv: is there an update-in! for transient maps?

10:40 &(apropos "update-")

10:40 humm no lazybot :/

10:40 Scriptor: ,(apropros "update-")

10:40 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: apropros in this context, compiling:(NO_SOURCE_PATH:0)>

10:40 Scriptor: ,(apropos "update-")

10:40 clojurebot: (update-in update-proxy)

10:41 clgv: guess not

11:17 cch1: Looking for help extending midje to segregate facts into unit and integration facts... anybody got an idea of how to structure such an effort?

12:10 TimMc: clgv: The problem with update-in! is that it wouldn't know whether the contained collections were transient or persistent, and would have to ask each one.

12:14 benares_98: is there a difference between the functions mod and div?

12:15 TimMc: benares_98: You've read their docs, yes?

12:16 benares_98: TimMc: I did but didn't understand the 'truncates towards negative infinity'

12:17 tmciver: What's div? According to clojuredocs, it's an incanter function . . .

12:17 benares_98: sorry I meant Mod and rem

12:17 TimMc: &((juxt unchecked-divide-int mod quot rem /) 20 -6)

12:17 Oops, lazybot is down.

12:17 ,((juxt unchecked-divide-int mod quot rem /) 20 -6)

12:17 clojurebot: [-3 -4 -3 2 -10/3]

12:19 TimMc: Oops, bad example.

12:19 * clgv mourn about lazybot.

12:19 TimMc: ,((juxt unchecked-divide-int mod quot rem /) -20 6)

12:19 clojurebot: [-3 4 -3 -2 -10/3]

12:20 TimMc: benares_98: quot and rem are the same as / and % from Java -- integer division operators providing quotient and remainder.

12:20 benares_98: thanks

12:21 TimMc: benares_98: mod, however, always gives the positive modulo for a positive modulus. (and vice versa)

12:21 benares_98: It didn't dawn on me until I started testing with negative numbers

12:21 tmciver: ,(mod 20 -6)

12:21 clojurebot: -4

12:23 tmciver: TimMc: hmm, I thought I understood mod, but I guess I don't

12:24 ,(mod -20 6)

12:24 clojurebot: 4

12:24 tmciver: I expected those last two to both be -4

12:24 TimMc: ,(map (juxt #(mod (- %1) (- %2)) #(- (mod %1 %2))) [20 20 -20 -20] [6 -6 -6 6])

12:24 clojurebot: ([-2 -2] [4 4] [2 2] [-4 -4])

12:25 TimMc: ^ That's a bit confusing, but what it says is, if you negate both arguments to mod, it is the same as negating the output. (mod distributes -)

12:26 tmciver: With (mod -20 6), you start with -20 and keep adding 6 until you reach a non-negative number.

12:27 tmciver: TimMc: Really? Now I'm really confused. I've always thought that mod was 'remainder after division' so

12:27 ,(mod 20 6)

12:27 clojurebot: 2

12:27 tmciver: make sense to me

12:28 but I guess I haven't used mod with negative numbers before.

12:28 jamiltron: rem = quot - floor (quot / number) * num

12:28 TimMc: tmciver: It can have various definitions, but this one is "The smallest non-negative number reachable by adding a multiple of the modulus to the... modulend?"

12:29 clgv: is there something with the capabilities of 'for and the sideeffect semantic of 'doseq? e.g. dofor? ;)

12:31 TimMc: tmciver: In other words, the residue of the mod operation with n will always be from [0,n) -- that range is backwards for negative n, of course.

12:34 tmciver: TimMc: so you've got -20 and you keep adding 6 (4 times) to get +4.

12:34 TimMc: yup

12:35 tmciver: TimMc: In (mod 20 -6) you start with 20 and subtract 6 (4 times) to get -4.

12:35 TimMc: right

12:35 rplevy: is clojurescript one intended to be used as a library, or is lib-ish stuff going to be broken into its own project?

12:35 tmciver: Very enlightening.

12:36 TimMc: tmciver: and in -20 -6, -6 is subtracted 3 times to get down (up) to -2.

12:37 tmciver: ,(mod -20 -6)

12:37 clojurebot: -2

12:38 tmciver: TimMc: Hmm, why -2? I would have naively expected -6 to be subracted 4 times (to get above zero?).

12:39 TimMc: tmciver: mod (or at least this one) will always preserve the sign of the modulus. quot/rem preserve information about the magnitude of the modulus and modulend (?).

12:40 tmciver: TimMc: In (mod 20 -6) the modulul is -6, yes?

12:40 TimMc: right

12:40 so the result will be between -6 and 0.

12:40 tmciver: s/modulul/modulus

12:41 TimMc: this is good stuff to know. This definitely would have been a future bug for me (and might still be!)

12:41 TimMc: tmciver: Just watch out in other languages... mod has different meanings. >_<

12:42 tmciver: >_< indeed

12:43 TimMc: I don't think Java even *has* a modulo in its stdlib.

12:43 joegallo: clgv: what do you want from for that is missing on doseq?

12:44 tmciver: TimMc: isn't it just %?

12:44 clgv: joegallo: is iterating over multiple seq possible? maybe I should recheck the docs...

12:44 rplevy: I just noticed my question earlier is kind of unclear, I'm asking about ClojureScriptOne

12:44 TimMc: tmciver: That's rem.

12:44 joegallo: clgv: pretty sure the answer is yes

12:44 clgv: ;(doc doseq)

12:45 ,(doc doseq)

12:45 clojurebot: "([seq-exprs & body]); Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil."

12:45 tmciver: TimMc: yes, I was going to say that rem is probably what I'm going to want, generally.

12:45 clgv: oh. like 'for - I always saw doseq only similar to (doseq [item seq] ...)

12:45 tmciver: TimMc: Thanks. You're a fountain of wisdom as usual.

12:48 TimMc: yay

12:49 joegallo: clgv: what i miss sometimes is the doseq version of map, but it's not like typing doall is that hard ;)

12:49 clgv: joegallo: well doall has some performance disadvantages in that case. but a domap can be easily implemented

12:50 joegallo: i guess i meant dorun, you're right

12:50 clgv: joegallo: if I remember correctly it was about 1/4 in my application specific context

13:38 AWizzArd: $seen fogus

13:44 TimMc: AWizzArd: That's not his nick.

13:45 also, lazybot is down

13:47 AWizzArd: Oh okay, what is his nick?

13:48 TimMc: `fogus, I think.

13:54 bobhope: Is there an easy way to compute with complex numbers in clojure?

14:00 jsabeaudry: Is aleph still the best bet for asynchronous http?

14:00 AWizzArd: jsabeaudry: client or server?

14:00 jsabeaudry: AWizzArd: Both

14:01 AWizzArd: Mainly server in the short term

14:01 AWizzArd: I think there is not yet a comfortable layer over Jetty, so yes, Aleph then.

14:03 jsabeaudry: AWizzArd: Altighty, thanks for the info! Aleph it is

14:23 AWizzArd: ,*clojure-version*

14:23 clojurebot: {:major 1, :minor 3, :incremental 0, :qualifier nil}

14:23 AWizzArd: ,(instance? Long/TYPE 4)

14:23 clojurebot: false

14:23 AWizzArd: why is this false?

14:24 joegallo: ,(instance java.lang.Long 4)

14:24 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: instance in this context, compiling:(NO_SOURCE_PATH:0)>

14:24 joegallo: ,(instance? java.lang.Long 4)

14:24 clojurebot: true

14:24 joegallo: Long != long

14:24 AWizzArd: Yes, it is a Long, but shouldn’t it be a long?

14:24 joegallo: Long/Type == long

14:24 AWizzArd: In 1.3

14:25 I tried this with (long 4), or I had a (defn foo [^long x] (instance? Long/TYPE x)), but they all return 'false'.

14:26 joegallo: Shot in the dark, but hiredman remains my authoritative source on such things: your long is getting upcasted to Long when you ask what its type is, because you can't ask what type a primitive is, only Objects. So your primitive becomes an object, and happily tells you it is a Long.

14:27 hiredman: ,(doc instance?)

14:27 clojurebot: "([c x]); Evaluates x and tests if it is an instance of the class c. Returns true or false"

14:27 hiredman: primitives are not an instance of any class

14:28 AWizzArd: I thought in 1.2 one could use `instance?` to check for primitive types.

14:28 hiredman: ,(instance? Long 4)

14:28 clojurebot: true

14:28 AWizzArd: But probably 1.3 ensures that when I do (defn foo [^long n] …) that n indeed will be a long.

14:29 hiredman: AWizzArd: most likely instance? was not getting inlined, so you were checking the boxed type

14:30 it is possible you might get different behaviour evaled code vs. compiled code because of some interaction of boxing + inlining

14:30 ,((fn [^long x] (instance Long x)) 4)

14:30 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: instance in this context, compiling:(NO_SOURCE_PATH:0)>

14:31 hiredman: ,((fn [^long x] (instance? Long x)) 4)

14:31 clojurebot: true

14:31 hiredman: ,(metadata #'clojure.core/instance?)

14:31 clojurebot: #<CompilerException java.lang.RuntimeException: Unable to resolve symbol: metadata in this context, compiling:(NO_SOURCE_PATH:0)>

14:31 hiredman: ,(meta #'clojure.core/instance?)

14:31 clojurebot: {:ns #<Namespace clojure.core>, :name instance?, :arglists ([c x]), :added "1.0", :doc "Evaluates x and tests if it is an instance of the class\n c. Returns true or false", ...}

14:31 hiredman: ,(keys (meta #'clojure.core/instance?))

14:31 clojurebot: (:ns :name :arglists :added :doc ...)

14:31 hiredman: clojurebot: jerk

14:31 clojurebot: you cut me deep, man.

14:33 k9quaint-wk: does anyone have a suggestion for a framework for user roles written in clojure that can run on GAE?

14:45 RazWelles: Someone in here mentioned earlier clojure has immutable lists- does that mean it can't self-modify?

14:46 amalloy: RazWelles: self-modifying code (at runtime) is not a thing you really want in any language. it's a thing where you say "OMG if I could do this then I could solve all problems instantly", but if you actually try it you just wind up sad and confused

14:47 RazWelles: amalloy, so... that's a no? :P

14:47 technomancy: "It takes twice as much brainpower to debug something as to initially write it. Therefore if you write code that is as clever as you can, by definition you are not smart enough to debug it."

14:48 joegallo: i'm going to replace "self-modify" in your question with "be modified" and then answer that yes, it means that they can't be modified

14:49 like strings in java, or the simple wrapper objects (Boolean, Long, etc.)

14:49 technomancy: It's possible to write a function that compiles a replacement for itself.

14:50 it could be fun as an experiment, but if you did that in code that had to be maintained it would be grounds for a severe flogging.

14:51 RazWelles: Well, I'm looking into learning lisp for ai research, I thought clojure might be a good option

14:51 but I'm also weighing in SBCL

14:51 amalloy: technomancy: "possible". more like trivial, right? (def modifying-fn eval). BAM, pass it a different list

14:51 technomancy: amalloy: ssshhh

14:52 RazWelles: I'm at the beginning here so I'm just looking for the right road to dedicate my initial time to

14:52 joegallo: RazWelles: i bet we're probably a little biased toward Clojure in this channel

14:53 amalloy: RazWelles: seriously, code that modifies itself at runtime is a disaster for SBCL and AI as well. try asking in #lisp, they'll tell you not to try that either. focus on other criteria for choosing a language

15:14 semperos: something simple is eluding me; I have this namespace declaration: https://gist.github.com/1622752

15:14 and it throw a compilation error; anyone care to look?

15:14 (it's extremely simple)

15:15 amalloy: semperos: your problem is elsewhere

15:15 * semperos wipes forehead

15:15 semperos: thought I was losing it...

15:15 amalloy: presumably in attempting to compile the code you're including

15:15 joegallo: check red.models.document

15:15 semperos: understood

15:15 and I see my error now, thx amalloy joegallo

15:26 k9quaint-wk: does anyone have a suggestion for a framework for user roles written in clojure that can run on GAE?

15:27 appengine's roles are, shall we say, a bit limited in scope

15:44 peregrine81: is there a reason a simple ORM or HRM doesn't exist for closure?

15:45 like I define a model for a hash and perhaps relationships and I can do things like

15:45 (filter filterFunc Model) => Vector of Hashs of the model

15:46 the filter is really just creates the select statement for me

15:46 filter func may just be a vector of keys and values

15:47 or does this exist and Im blind

15:52 joegallo: like this? http://sqlkorma.com/

16:28 peregrine81: yes thank you!

16:56 ABS: hi all, I spent quite some time reading congomongo's source and I couldn't find any support for mongo's $or in the :where conditions. can someone confirm it's not supported or I'm just blind? :-)

17:01 ABS_: sorry, lost connection

17:06 guns: ls

17:12 TimMc: $seen `fogus

17:12 lazybot: `fogus was last seen quitting 2 days and 20 hours ago.

17:12 TimMc: Yay, lazybot is back!

17:28 argvu: hi =)

17:28 Devlol: Hello. Just a little question, if reify is used many times, can it causes permgen space oom exceptions ?

17:28 jsabeaudry: I'm completely puzzled. I'm playing with aleph and if I put my data ByteBuffer in little-endian the http response fails to get decompressed by gzip. Anyone has a clue what could be the problem? http://pastebin.com/uuSRNdRm

17:28 TimMc: Devlol: A (reify ...) statement only creates the class once -- on compile (whether AOT or JIT).

17:29 hiredman: jsabeaudry: fails how?

17:29 jsabeaudry: hiredman: Wireshark fails to decompress it and firefox says it cannot read the response

17:30 hiredman: maybe your content type header should say the content is gzipped?

17:30 jsabeaudry: (which is probably the same error but firefox is less explicit I would guess)

17:30 argvu: i'm new with clojure and i'm trying to code a sudoku solver with backtracking, right now this code http://pastebin.com/MF0RBWvC is able to solve grids but it's really slow (take lots a secs to solve just one hard grid), it's probably really wrong but i cannot figure out where is the mistake. someone can help me ? =)

17:31 TimMc: argvu: "lots of seconds" -- how many?

17:31 argvu: it depends, from 7/8 to 20

17:31 dnolen: argvu: also slow compared tow hat?

17:32 to what, I mean

17:32 argvu: compared to .. for example http://attractivechaos.github.com/plb/kudoku.html

17:33 ztellman: jsabeaudry: the response headers say it's gripped?

17:33 Devlol: TimMc: ok thanks for the clarification, because it looks like http://bit.ly/wu3y9g causes me some problems

17:33 ztellman: gzipped*

17:33 dnolen: argvu: did you port the code?

17:34 argvu: no, i haven't

17:34 jsabeaudry: ztellman: Wireshark says they do

17:35 ztellman: jsabeaudry: that's probably netty assuming the byte buffer is big-endian, then

17:36 since that's the standard java and network traffic ordering

17:39 argvu: l

17:43 TimMc: argvu: You could try profiling it.

17:43 I don't think I'm going to spend a half-hour understanding your undocumented code. :-/

17:44 argvu: i understand =)

17:44 what do you mean with profiling ? how exactly ?

17:44 jsabeaudry: ztellman: That is a pity, not being able to transfer bytes in the order I please. I'll try to find a hack around it I guess

17:45 ztellman, hiredman: Thanks for your help

17:45 dnolen: argvu: what are you comparing against then? it's hard to improve the performance without knowing that.

17:45 ztellman: jsabeaudry: keep in mind that's just a guess on my part, but there's nothing in aleph proper that touches the contents of the body

17:47 argvu: dnolen: againt any of these https://github.com/attractivechaos/plb/tree/master/sudoku

17:47 isak_: how can i convert a bunch of vectors to sets? I'm trying (apply set [1 2 3] [4 5]), but i get an ArityException

17:47 dnolen: argvu: but did you port one of those?

17:47 argvu: dnolen: no i didn't

17:48 raek: isak_: you want to get (#{1 2 3} #{4 5}) as the output?

17:48 dnolen: argvu: so it's going to difficult to say, no? since it may be your approach.

17:49 isak_: yeah raek

17:49 raek: isak_: then 'map' is the function you are looking for: ##(map set [[1 2 3] [4 5]])

17:49 lazybot: ⇒ (#{1 2 3} #{4 5})

17:50 tolstoy: Anyone using core.cache? Is it not meant to be mutable in any way?

17:50 I'd like a simple-cache where you put values in and they fade out after TTL.

17:50 argvu: dnolen: it's my approach for sure, because i understand that it' woule be to long to try to understand my code and fix it, i'll ask another question ... what's the best way to do backtrakcing in clojure ? =)

17:50 isak_: thanks raek. so do you know why apply gives an arityexception?

17:51 ztellman: isak_ (set …) only takes a single argument

17:51 isak_: i see

17:52 raek: isak_: (apply set [1 2 3] [4 5]) doesn't make sense if you want it to get (#{1 2 3} #{4 5})

17:52 dnolen: argvu: there's no best way, probably many of the appraoches in that repo will work

17:53 raek: first, (apply f a b c [d e f]) is a shortcut for (apply f [a b c [d e f]])

17:53 which means (f a b c [d e f])

17:53 amalloy: raek: whoa, that is not true

17:53 TimMc: yeah

17:54 argvu: dnolen: the issue here is that i'm so stupid that i cannot even understand it ... however i was talking about backtracking in general

17:54 TimMc: (apply a b c [d e f]) is (f a b c d e f)

17:54 amalloy: shorthand for (apply f [a b c d e f]), which is the same as (f a b c d e f)

17:54 raek: amalloy: er. yeah.

17:54 sorry folks... :-)

17:54 argvu: dnolen: *understand the approach in that repo

17:54 amalloy: you meant: (apply f [a b c] [d e]) is (f [a b c] d e)

17:54 TimMc: and mine is wrong by one important letter

17:54 jsabeaudry: ztellman: Found a way around it, I enqueue (.array buf) instead of buf and it goes through perfectly.

17:54 raek: so

17:55 tolstoy: Ah, maybe core.memoize is what I want (on top of core.cache).

17:55 raek: (apply set [1 2 3] [4 5]) is the same as (apply set [[1 2 3] 4 5]) and (set [1 2 3] 4 5)

17:55 ztellman: jsabeaudry, yeah, because that will wrap the array in a big-endian buffer again

17:55 if you reverse the order after the encode-to-buffer, does that work too?

17:56 isak_: ok i get it, so apply is only for when you dont know the arguments at compile time

17:57 jsabeaudry: ztellman: surprisingly it does not :S

17:58 ztellman: jsabeaudry: remember that (.order buf …) returns a new byte-buffer, it's not a side-effect

17:59 or wait, according to the javadoc it is, never mind

17:59 no idea, then

17:59 jsabeaudry: ztellman: Ah nevermind it does work to rereverse it. I had forgotten the .rewind

18:00 ztellman: jsabeaudry: cool, that's at least a little sane, then

18:00 I'll make a note to look if it's always right to reverse it before handing it over to netty

18:01 jsabeaudry: ztellman: Might be related to this bug https://issues.jboss.org/browse/NETTY-158

18:01 ztellman: jsabeaudry: shouldn't effect the encoder, I'd expect

18:01 MenTaLguY: hmm

18:02 does clojure have an equivalent of bit-shift-right that doesn't do sign extension?

18:02 i.e. Java's >>> ?

18:05 amalloy: ,(require 'clojure.repl)

18:05 clojurebot: nil

18:05 amalloy: ,(repl/apropos "shift")

18:05 clojurebot: #<CompilerException java.lang.RuntimeException: No such namespace: repl, compiling:(NO_SOURCE_PATH:0)>

18:05 amalloy: ,(clojure.repl/apropos "shift")

18:05 clojurebot: (bit-shift-left bit-shift-right)

18:06 MenTaLguY: so that's a no?

18:06 TimMc: Nothing obvious.

18:07 Checking logs...

18:09 clojure.lang.Numbers doesn't have anything

18:11 06:08 < mikera> Is now: (defn >>> [v bits] (bit-shift-right (bit-and 0xFFFFFFFF v) bits))

18:11 *shrug*

18:11 amalloy: at least twice i've seen someone implement this and desire to add it to lang or core

18:11 MenTaLguY: I guess I'll just drop down into Java for this code

18:12 amalloy: never seems to take off

18:12 MenTaLguY: it probably really should be there

18:13 TimMc: amalloy: Open a ticket... -.-

18:13 hiredman: http://dev.clojure.org/jira/browse/CLJ-827

18:15 http://dev.clojure.org/jira/browse/CLJ-899 this is so bad

18:15 jesus, fogus upvoted it?

18:16 TimMc: pretty terrible

18:16 technomancy: ~guards

18:16 clojurebot: SEIZE HIM!

18:18 amalloy: hiredman: how can you tell who voted?

18:18 alexbaranosky: can you downvote on Jira?

18:18 hiredman: amalloy: if you click on the number next to vote

18:18 amalloy: maybe you have more privs, but for me there's nothing clickable, and nothing happens if i try anyway

18:19 hiredman: it says Vote (2)

18:19 if you click on the 2

18:19 alexbaranosky: the number isn't clickable, but the thumbs-up is clickable

18:19 amalloy: yep, i recognize what "click on the number" means. i'm saying it doesn't do anything

18:19 hiredman: whatever you do, don't click on the thumbs up

18:19 alexbaranosky: I'm afraid that I might accidentally upvote it ...

18:20 hiredman: dunno

18:20 alexbaranosky: I guess I don't have downvote priveleges.

18:20 amalloy: alexbaranosky: i don't think there is a downvote

18:20 hiredman: I don't think you can downvote

18:20 which is too bad

18:20 amalloy: you can rescind an upvote, though, iirc

18:20 alexbaranosky: wonder if I can alter the http params

18:21 amalloy: alexbaranosky: yeah, if you accidentally upvote you can just take it back

18:21 alexbaranosky: amalloy: good to know

18:22 hiredman: "Stuart Halloway created CLJ-899 - Allow colon as whitespace in map literals"

18:22 ugh

18:23 alexbaranosky: I don't get how this is even in discussion

18:23 hiredman: right

18:24 hammer_: Hi, I'm Dan, first time on here. I am trying to convert a logistic classifier from Python to Clojure, and it's running *very* slow - much slower than the Python version. Here's the gist: https://gist.github.com/1623542 Any help would be greatly appreciated.

18:24 alexbaranosky: next we'll have an alternate syntax that looks like this: `f(g(x))`

18:24 amalloy: alexbaranosky: "Guys wouldn't it be cool if". "Oh man that'd be awesome, make an issue"

18:24 alexbaranosky: that you can use interchangeably with (f (g x))

18:25 use them together like this: `(f g(x))`

18:25 amalloy: it doesn't look like a discussion so much as a (bad) idea stu had and threw up on jira to remember/survey on

18:26 hammer_: This is the function call I use: (logistic-beta-vector (label-vec 100000) (feature-vec 100000) 0.00000001) https://gist.github.com/1623542

18:26 technomancy: amalloy: the best part is IIRC it happened right after stu shut some other issue down for "you need a concrete problem statement"

18:27 amalloy: see, he was careful not to say "one needs..."

18:27 hiredman: I don't know that clojure.math.numeric-tower is performant at all

18:28 hammer_: hiredman: sorry, I don't even use that library -- I'll remove it

18:28 hiredman: although, it actually doesn't look like you are using it

18:29 math operations like + and * are faster if you treat them as binary

18:29 (two arguments)

18:30 I think apply + is actually faster than reduce +

18:30 hammer_: also, one iteration takes about 800 seconds

18:30 hiredman: thanks, I'm profiling the change

18:30 amalloy: hiredman: really? i think apply is just calling reduce, isn't it?

18:30 hiredman: I would check out visualvm if you haven't yet

18:31 amalloy: or rather, the many-arg clause of + calls reduce

18:31 technomancy: amalloy: normally it would; + is kind of special in this case

18:31 hiredman: amalloy: yes, but I seem to recall it being faster that way

18:32 actually, I could have it reversed, reduce may be faster

18:32 ,(time (apply + (range 1e6)))

18:32 clojurebot: "Elapsed time: 729.371 msecs"

18:32 499999500000

18:32 hiredman: ,(time (reduce + (range 1e6)))

18:32 clojurebot: "Elapsed time: 623.267 msecs"

18:32 499999500000

18:33 sritchie: I'm working with hammer_ on this one in person, actually

18:33 hiredman: hammer_: if the python code infact just calls a c extension it may be hard to beat

18:33 sritchie: it's bizarre, the clojure code's something like 2 orders of magnitude slower than python

18:33 I had thought it was fast because it was cheating and taking some view on the data

18:34 hiredman: but it actually runs everything each time

18:34 amalloy: ,(time (loop [acc 0, coll (range 1e6)] (if-let [[x & xs] (seq coll)] (recur (+ acc x) xs) acc)))

18:34 clojurebot: "Elapsed time: 1497.646 msecs"

18:34 499999500000

18:34 hiredman: sritchie: what do you mean?

18:35 sritchie: hiredman: in numpy, if you run some operation on a matrix and look at one corner, I think the operation acts lazily and only applies itself to the piece you're looking at

18:35 I wonder if it's worth shelling out to python

18:36 hiredman: is it a fairly direct port of the python? I doubt it, since it is using map and filter

18:36 sritchie: hammer_: can you post the python?

18:36 hammer_: sure one second

18:36 * hiredman doesn't actually want to read python

18:37 hiredman: it also looks like maybe you are missing a set of parens in your code

18:37 line 87

18:37 robinkraft: sritchie: I'm pretty sure Numpy calculations generally aren't lazy

18:38 hiredman: is this clojure 1.2 or 1.3?

18:38 sritchie: 1.3

18:40 hammer_: Here is the Python gist: https://gist.github.com/1623646

18:41 I fixed the parens problem; but that would just screw up the actual values, not the amount of time. rerunning now.

18:42 TimMc: How do I call the int version of a Java method that is overloaded for both int and long? (Working on a better patch for bit-shift-right-logical)

18:43 amalloy: TimMc: you can certainly do it by (.foo obj (Integer. x)). you might also get away with hinting it somewhere instead

18:44 TimMc: Hmm, OK -- that's what I tried.

18:44 I'll have to check the bytecode to confirm this is the right call...

18:47 AWizzArd: Does ^:const only work for primitives?

18:48 hiredman: AWizzArd: they are not evaled

18:48 so effectively it only works for readable things

18:48 TimMc: amalloy: Oops, no -- the method is overloaded for int, long, and Object!

18:51 _carlos_: hi!

18:51 TimMc: ...and that's wrong too, never mind.

18:52 _carlos_: is it idiomatic in any case to use mutually recursive functions? I was always taught that wanting to do it implied a bad design. clojure enables it with a forward declaration and a special function call

18:54 clj_newb: is there a shorter way of writing: (map (fn [data env] (my_eval :data data :env env)) lst) ?

18:55 i wnat to shorten the (fn [data env] (my_eval :data data :env env)) part

18:55 hiredman: -

18:55 technomancy: clj_newb: any map call with a nontrivial literal fn is probably better off as for

18:55 clj_newb: the fn is trivial

18:55 it's just it takes named arguments

18:55 technomancy: that won't even work for arity reasons

18:56 clj_newb: you're ab oslutely right

18:58 oakwise: _carlos_: check out the trampoline function

18:58 _carlos_: oakwise: I know, I just wondering why such a feature

18:59 technomancy: what does it mean nontrivial literal fn?

18:59 clj_newb: unrelated question: is there a way in clojure to auto-require an entire directory tree? i.e. I want to auto-require ~/my-clojure-helper-functions/**/*.clj

18:59 (it seems like this is possible since all of java.* appears to be auto required)

19:00 technomancy: _carlos_: any (fn []) call more than 10-15 chars I guess?

19:00 clj_newb: import != require

19:00 TimMc: clj_newb: Just java.lang.*

19:00 clj_newb: I'm looking for :require, not :use

19:00 oakwise: _carlos_: clojure doesn't have full tail call optimization, so if two functions keep calling each other recursively, they'll keep building up the call stack unnecessarily

19:01 clj_newb: I just wantt o be refer to sthigns like my_util.****/foo w/o having to add :requires all over the place

19:01 technomancy: clj_newb: there's no built-in way to do that, but there is nstools.

19:02 _carlos_: oakwise: I know. my question is "why should one even consider to build mutually recursive functions"

19:02 TimMc: MenTaLguY: I've submitted a patch for bit-shift-right-logical, but who knows.

19:04 emezeske: _carlos_: mutual recursion can be used in place of complex state machines sometimes

19:05 _carlos_: without a central dispatch loop thing

19:05 _carlos_: it can be cleaner to just call another function than to set some new state value and recur

19:05 TimMc: technomancy: You haven't mentioned slamhound to clj_newb yet?

19:06 oakwise: _carlos_: Ah I see. State machines are the classic case I think.

19:06 technomancy: oh yeah, there's that too

19:06 TimMc: a small ns form can be better than an autogenerated large one though

19:06 clj_newb: slamhound/README.md is very informative

19:07 MenTaLguY: with state machines, you can potentially model the state machine as a lazy stream over its inputs

19:07 which solves your stack depth problem

19:07 while still allowing a mutually-recursive style

19:11 _carlos_: I see. thank you emezeske, oakwise, MenTaLguY .

19:11 MenTaLguY: laziness ftw

19:36 clj_newb: is there a shorter way to write (list 'a (list 'b 'c) 'd) ? Writing '(a (b c) d) causes the a/b/c/d to be namespace-quantified, which I donm't want

19:37 TimMc: clj_newb: '(a (b c) d)

19:37 not `(a (b c) d)

19:38 clj_newb: crap, I actuallly need `

19:38 since I use ~ elsewhere

19:39 amalloy: then consider using keywords instead of symbols to represent your data items. if they're not supposed to be recognizable vars, symbols are often just confusing

19:41 clj_newb: amalloy: so this almost works; except all of my functions also use keywords since I pass arguments by name

19:41 as a result, it becomes iffy figuring out which keywords should be looked up in the environment, and which should not

19:42 okay, using ` with ~' appears to make it work

19:42 TimMc: "which keywords should be looked up in the environment" means you're using keywords wrong.

19:43 clj_newb: i'm using code is data / datat is code as a way to represent nested GUIs as lists

19:43 then to build them, I "eval" the list, by looking at the first element, to know what gui element to construct

19:43 right now, this is a symbol; but if I use a keyword instead; then I need to "oookup the keyword in the environment"

19:48 wtf

19:48 why is (type `(1 2)) = Cons ? rather than PersistentList ?

19:49 hiredman: what made you think it would be PersistentList?

19:49 technomancy: clj_newb: because the classes aren't what matters

19:50 clj_newb: when writing a metacicular evaluator

19:50 how do you test if somethign is listy ?

19:50 seq?

19:50 clojurebot: seq is what

19:50 technomancy: yeah, it's seq?

19:50 don't trust the list? predicate; it is 95% useless.

19:51 clj_newb: woot

19:51 it works now

19:51 thanks

19:51 hiredman: well, if you want to check for an IPersistentList it works great

19:51 clj_newb: I feel like my IQ has risen 10 points back to 80/100

19:51 hiredman: which is exactly what the doc string says it does

20:03 clj_newb: is there a way to tell clojure: when a named param is not passed, don't assume value of nil; complain! ?

20:04 technomancy: you can use preconditions for that

20:14 TimMc: technomancy: The surprise is really that syntax-quote returns seqs, not lists.

20:15 * technomancy continues to fail to see a reason anyone should ever care

20:17 amalloy: TimMc: you don't really want it to return lists anyway, right? it wouldn't be as versatile

20:18 TimMc: I guess with seqs it can be streaming.

20:18 amalloy: `(~start ~@middle ~end)

20:19 this doesn't have to be part of a macro - it's way more descriptive than (concat [start] middle [end])

20:19 and allows for the possibility that middle is infinite, or or just way longer than you need (the streaming point you made)

20:20 i suspect it also saves the time of walking over the whole things twice - once to build a list, then again later when you want to use it

20:20 sritchie: hiredman: really odd about that clojure function --

20:21 from hammer_ before

20:21 I found that it was extremely fast for 100,000

20:21 run over and over

20:21 but when I tried to run this particular code with 1,000,000 iterations, the first four or so were very fast, then the whole computation started to bog down, until by 7 or so it was interminable

20:21 then running 100,000 again took 17 seconds

20:22 amalloy: on an unrelated note: i find i never want to write (with-meta expr meta). i always end up writing (-> expr (with-meta meta)), to make it easier to separate/parse mentally. am i the only one?

20:22 sritchie: do you guys know which memory setting I need to jack up to deal with issues like this?

20:23 technomancy: amalloy: I always forget the argument order too

20:24 joegallo: yup, every time

20:24 amalloy: technomancy: i actually remember it, these days. maybe using -> helped me with that

20:24 technomancy: amalloy: with-meta is the only with-* call in clojure.core that doesn't introduce dynamic scope

20:24 amalloy: yeah, i remember chouser's riddle

20:24 technomancy: making it a certifiable odd duck

20:27 amalloy: it's a little arguable whether with-open actually introduces dynamic scope

20:27 sritchie: more concisely -- does anyone know how to deal with a case of bogged-down garbage collector?

20:27 amalloy: like, the values are lexically scoped. but they don't *work* outside of the apparent dynamic scope

20:27 technomancy: amalloy: never thought of it that way

20:27 amalloy: depends what's bogging it down, really, sritchie

20:28 sritchie: I do have a concise example, I believe

20:36 boom, examplified: https://gist.github.com/1624010

20:37 amalloy: I'm running this log-likelihood function a bunch of times -- I had thought that dorun would prevent clojure from holding on to the head of a sequence

20:37 I'm guessing that I'm just getting slammed with garbage collection issues here?

20:37 (profiling at the bottom)

20:43 amalloy: sritchie: have you tried profiling and watching the heap size over time? this kinda looks like some of your objects are piling up on the heap and becoming uncollectable

20:44 sritchie: I'm off to download yourkit now

20:45 amalloy: i don't see anything in the code that looks like it should behave that way, unless there's an error in locals-clearing and labels/features aren't being cleared when you start your loop

20:45 hiredman: I suggested visualvm above

20:45 comes with the jdk

20:45 sritchie: ah, got it

20:47 amalloy: we had symptoms like this once, and what was happening was each iteration of the algorithm generated X amount of trash, and Y amount of stuff that couldn't be GCed because it wound up in a memoization cache. eventually, there was only X + epsilon amount of space left in the heap, and every couple allocations triggered another GC run, barely cleaning up anything

20:50 sritchie: that sounds like a pretty fine description of what's going on here

20:50 I'll try out visualvm and see if I can target what's generating the garbage

20:53 hmm, I think I fixed it

20:53 https://gist.github.com/1624059

20:53 I started by taking off of a stream this time

20:53 oh

20:54 it was this:

20:54 (def X-rand (feature-vec 10000000))

20:54 (def y-rand (label-vec 10000000))

20:54 X-rand and y-rand were holding on to the heads of those lazy sequences

20:54 and as the code walked toward 1,000,000, more was getting realized

20:58 amalloy: ah, right

21:00 devth: if i have a symbol "println" - how do i resolve that to the function in clojure core? my syntax-quote-fu is weak.

21:03 oh. it's just (resolve 'println)

21:16 bitops: hi all, I'm getting confused trying to require in my ns.

21:16 code: (ns foo.core (:require [clojure.string :as str]))

21:16 but I get an error message about periods?

21:16 in the repl my require works fine.

21:19 sorry, the error message is "Don't know how to create ISeq from: clojure.lang.SymbolDon't know how to create ISeq from: clojure.lang.Symbol"

21:24 ah, my apologies. the actual error message that confounds me is: lib names inside prefix lists must not contain periods

21:32 TimMc: $findfn 'println println

21:32 Argh, lazybot is deadbot.

21:34 bitops: That looks fine... did you copy that code verbatim, or retype it?

21:35 bitops: TimMc: that is a verbatim copy and paste from my code

21:35 I am quite perplexed.

21:37 TimMc: bitops: Check for outside problems like wrong version of Clojure, not having saved file to disk, etc.

21:37 sanity checks

21:38 bitops: TimMc: checking...

21:39 TimMc: Works here.

21:40 I once got some weird-ass errors when I accidentally nabbed an unstable clojure.core. (Tip: Version ranges in dependencies are not very reliable.)

21:40 bitops: TimMc: I'm re-starting my swank server, project.clj looks good.

21:41 TimMc: hrm. Still explodes.

21:41 Don't know how to create ISeq from: clojure.lang.Symbol

21:44 TimMc: I may just try to re-create my project. I had just gotten off the ground. Maybe I'm missing something that will become obvious when I re-init.

21:45 TimMc: What happens when you lein run it?

21:47 bitops: TimMc: I hadn't tried that, let me see.

21:47 no :main namespace specified in project.clj

21:47 I'm building a test webapp

21:47 for heroku deployment

21:48 but maybe I'm missing something?

21:49 TimMc: it's all good actually. I'm about to head home, so no biggie.

21:49 thank you for the help!

21:49 TimMc: Ah, lein run wouldn't help then!

21:49 adiabatic: stupid question of the week: can't noir use clojure 1.3? I did the `lein plugin install lein-noir 1.2.1` dance, and it pulled clojure 1.2.1

21:50 seancorfield: that's just for the lein plugin i think

21:50 once you create a noir project with the plugin, i think you'll find it uses clojure 1.3.0

21:50 (all lein plugins have to use clojure 1.2.1 to run)

21:52 adiabatic: why? that bit of lein hasn't been updated yet?

21:52 seancorfield: lots of plugins out there aren't compatible with 1.3.0 yet i suspect

21:52 so leiningen can't run plugins in 1.3.0 because many will break

21:52 benares_98: can anyone explain how the for function is used? I don't understand what [seq-expr body-expr] in the doc means.

21:52 adiabatic: benares_98: are you familar with list comprehensions in other languages?

21:53 seancorfield: (for [i (range 10) j (range 10)] (* i j)) ;; does that help?

21:53 benares_98: adiabatic: This is my first venture in lisp dialect

21:53 adiabatic: benares_98: I'm familar with 'em from Python, so…

21:54 seancorfield: ,(for [i (range 3) j (range 3) :when (not= i j)] [i j (* i j)])

21:54 clojurebot: ([0 1 0] [0 2 0] [1 0 0] [1 2 2] [2 0 0] ...)

21:55 seancorfield: i can't remember what other qualifiers you can specify in there but it's pretty flexible / powerful

21:55 amalloy: :while, :let

21:55 adiabatic: (doc for) doesn't even mention :let

21:55 clojurebot: "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test. (

21:55 benares_98: I see examples of for with :when and :while in brackets but where do theses fit in the [seq-expr body-expr] of the doc?

21:55 amalloy: adiabatic: guess again

21:56 rlb: In 1.2 I was reading a 64-bit unsigned int like this: (bit-and (.readLong data-stream) 0xFFFFFFFFFFFFFFFF). What's the best way in 1.3?

21:56 * adiabatic squints again

21:56 seancorfield: adiabatic: "Supported modifiers are: :let ..."

21:56 adiabatic: right. my bad.

21:56 amalloy: benares_98: (for (comment THIS IS THE seq-expr) [x (range) :when (even? x)] (comment THIS IS THE body-expr) (/ x 2))

21:57 seancorfield: benares_98: see the examples i posted? do those help

21:58 benares_98: seancorfield: so :when, :while, :let are support modifiers for the 'for' function?

21:58 seancorfield: they do I'll look at them again.

21:58 seancorfield: they control how the sequences are iterated over

21:59 ,(for [i (range 1 10) :let [s (* i i)]] (str i " squared is " s))

21:59 clojurebot: ("1 squared is 1" "2 squared is 4" "3 squared is 9" "4 squared is 16" "5 squared is 25" ...)

22:00 rlb: (I know I can use (.and (BigInteger/valueOf ...) ...), just wanted to see if there was anything more appropriate.)

22:00 seancorfield: ,(clojure-version)

22:00 clojurebot: "1.3.0"

22:00 seancorfield: ,0xFFFFFFFFFFFFFFFF

22:00 clojurebot: 18446744073709551615N

22:01 amalloy: ,(for [c (range 100) :let [c2 (* c c)], b (range c) :let [b2 (* b b)], a (range b) :when (= c2 (+ b2 (* a a)))] [a b c])

22:01 clojurebot: ([3 4 5] [6 8 10] [5 12 13] [9 12 15] [8 15 17] ...)

22:01 benares_98: thanks, I believe I understand it now.

22:01 adiabatic: (for [cake cakes] [(put-cherry-on-top cake)])

22:02 amalloy: benares_98: a somewhat more involved example to compute pythagorean triples

22:02 devn: So, I'm doing a fresh installation of OSX on this machine and I'm looking to set up a modern clojure environment. My old config uses slime-connect, paredit fixes for the slime buffer, and on and on. What is the modern guide for having a sane clojure environment in emacs? Anyone here use el-get?

22:03 seancorfield: devn: I went with Emacs 24.0.90, the init.el mods to add marmalade, clojure-mode, lein swank-clojure and clojure-jack-in - seemed to be the easiest setup i could find documented...

22:04 rlb: seancorfield: ?

22:04 seancorfield: but i haven't done much customization... what's the "paredit fixes for the slime buffer"? sounds like i could use those :)

22:04 rlb: ,(bit-and 4 0xFFFFFFFFFFFFFFFF)

22:04 clojurebot: #<IllegalArgumentException java.lang.IllegalArgumentException: bit operation not supported for: class clojure.lang.BigInt>

22:04 adiabatic: benares_98: also: :when keeps evaluating every single thing that it can in the seq-exprs — :while, on the other hand, stops the for on first failure

22:04 devn: seancorfield: matching {}'s, highlighting, etc.

22:04 adiabatic: IIRC

22:05 devn: seancorfield: honestly my emacs.d is such a mess that I'm sort of amazed any of it works.

22:05 seancorfield: rlb: ah, i wasn't sure why your existing code wasn't sufficient... now i get it

22:05 devn: seancorfield: but I do have a really nice clojure environment from what I've seen

22:06 seancorfield: devn: sounds like nice fixes... where do i get those? :)

22:06 devn: seancorfield: I can show you what I have -- hopefully it helps -- give me a moment and I'll gist it.

22:06 benares_98: why is :when, :let, :while not in the (doc for)? Is there another doc that is more concise?

22:06 rlb: Hmm, and the obvious thing won't work because the reader makes 0xFF... into a bigint, so you can't use valueOf.

22:07 adiabatic: benares_98: look again

22:07 rlb: Is there a way to turn a bigint into a BigInteger?

22:07 adiabatic: it's all in there, but the difference between :when and :while is underdocumented

22:07 (I need to file a bug report if not a patch against that…)

22:08 seancorfield: ,(doc for)

22:08 clojurebot: "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], ...

22:09 seancorfield: benares_98: I see :let there

22:09 benares_98: rlb: you're right, it's in the doc but it has no explanation on how the modifiers are used.

22:09 seancorfield: (doc for)

22:09 clojurebot: "([seq-exprs body-expr]); List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test. (

22:09 rlb: Ahh -- (.toBigInteger ...)

22:09 seancorfield: and there is :while and :when

22:09 devn: seancorfield: https://gist.github.com/1624324

22:10 seancorfield: thanx devn

22:10 adiabatic: seancorfield: right, but I had to ask in here what the difference between :while and :when was

22:10 devn: seancorfield: hopefully it can be of some use -- I honestly don't remember where half of that stuff came from, it's just been snowballing

22:10 benares_98: thanks for the help everyone!

22:10 adiabatic: (ok, you're probably answering two different questions, but…)

22:10 rlb: Not, the prettiest, but...

22:10 (.and (BigInteger/valueOf (.readLong data-stream))

22:10 (.toBigInteger 0xFFFFFFFFFFFFFFFF)))


22:10 benares_98: I'll play with the modifiers to understand furhter

22:10 rlb: works

22:11 Of course, I should probably cache the .toBigInteger conversion...

22:11 (I'm assuming that the compiler won't do that for me.)

22:12 seancorfield: devn: some of that's pretty scary looking stuff! :)

22:13 adiabatic: i guess i thought :while was intuitive... and :when too based on the (when cond expr)

22:13 but you're right it's underdocumented

22:14 adiabatic: if you're familiar with [keep|drop]while, sure. If you're not…

22:17 devn: seancorfield: agreed. this is why I'm asking for suggestions. I've built a cathedral

22:49 amalloy: seancorfield: you might be surprised about :while. i learned a bit about it from stackoverflow recently

22:50 seancorf: oh? do tell... now i'm curious! :)

22:50 alexbaranosky: is it the spiritual cousin of take-while, but in for expressions?

22:53 amalloy: seancorf: http://stackoverflow.com/q/8816464/625403 - looking back at the docs it should be clear it behaves this way, but i had sorta imagined :while as magically guessing whether i mean "end the current iteration of this inner-most variable" vs "end the result of the for expression"

22:56 alexbaranosky: amalloy, nice. I've yet to use :while - but good to learn more about it for future reference

22:57 amalloy: yeah, it's applicable a lot less often than when/let

22:58 adiabatic: hunh, weir

22:58 d

23:31 seancorfield`: if i missed anything, blame comcast :(

23:40 amalloy: seancorfield`: not much, if anything: http://lazybot.org/logs/#clojure/2012-01-16

23:40 TimMc: lazybot *dot org*?

23:40 Since when did bots get domains?

23:41 amalloy: you didn't get yours? check your mailbox again

23:41 TimMc: haha

23:42 seancorfield`: appreciated amalloy - i really didn't miss much, eh? :)

23:42 interesting about :while... i hadn't thought about it in that much detail...

Logging service provided by n01se.net