2010-10-14
| 00:05 | amalloy | kmc: hotspot's jit is pretty good, i think. but i'm not a performance expert by any means |
| 00:12 | rplevy | how far can one elaborate on something like this do you think? (defmacro with-turbo [turbo-on & body] `(let [~'map ~(if turbo-on `clojure.core/pmap `clojure.core/map)] ~@body)) |
| 00:12 | rplevy | it's kind of the opposite of the Macintosh turbo button ;) |
| 00:13 | amalloy | rplevy: not sure what you mean by elaborate |
| 00:13 | rplevy | say if you don't know whether your code will be running on a quad core machine or a netbook and you want to provide an option |
| 00:14 | rplevy | amalloy: I mean, add more conditional stuff to take advantage of parallelism for free |
| 00:14 | amalloy | taking advantage of parallelism for free turns out to be a lot more difficult than it looks (cf kmc's efforts a few nights ago) |
| 00:15 | rplevy | amalloy: I'll take a look, sounds interesting |
| 00:15 | amalloy | rplevy: the main issue is that pmap needs to be given a smallish number of large tasks in order to be useful, because it spawns a thread for each task |
| 00:15 | amalloy | (it doesn't run all the threads at once, but it does create a new thread for each task) |
| 00:16 | rplevy | amalloy: what day's log is kmc's experiment in? |
| 00:16 | amalloy | uhhhhh |
| 00:16 | amalloy | sec |
| 00:16 | amalloy | mon oct 11 |
| 00:17 | amalloy | on my computer, anyway, which is pacific time |
| 00:17 | amalloy | :P |
| 00:17 | amalloy | so in greenwich it's probably tuesday morning |
| 00:18 | amalloy | rplevy: search for pmap to find it quickly within the log file |
| 00:18 | rplevy | amalloy: yeah, so of course there is no free lunch, but still useful on occasion to wrapp small things in something like this, using judgment for specific cases |
| 00:19 | amalloy | rplevy: yes, clojure certainly provides a good groundwork for writing sensible parallel tasks |
| 00:22 | chouser | map has defined different semantics when the function you give it has side effects. pmap doesn't, I think. |
| 00:22 | chouser | clojure's got a lot more tools around concurrency at this point than it does around parallelism |
| 00:23 | _rata__ | hi |
| 00:23 | amalloy | chouser: you don't think it's defined as "totally arbitrary and don't rely on it"? |
| 00:23 | amalloy | i mean, that's sorta the same as totally undefined, i guess |
| 00:24 | _rata__ | records are persistent, right? |
| 00:25 | rplevy | chouser: interesting, it seems inevitable then for more high-level abstractions for parallelism to enter the language |
| 00:27 | amalloy | _rata__: yes, they are immutable, if that's what you mean |
| 00:27 | _rata__ | amalloy, i mean, is it ok to use them with STM? |
| 00:28 | amalloy | _rata__: yes, because they are immutable. they implement java.util.map, which has a put() method, but if you actually call it they throw an exception |
| 00:30 | _rata__ | i asked because of the optimization STM can do using persistent vectors/maps/lists |
| 00:30 | amalloy | what optimization is that? |
| 00:30 | _rata__ | STM can do that optimization using any immutable data? |
| 00:30 | amalloy | (records implement IPersistentMap, so whatever they are it seems likely that STM can use them on records) |
| 00:30 | _rata__ | not having to do copies |
| 00:31 | _rata__ | ok |
| 00:31 | _rata__ | *to make copies |
| 00:31 | _rata__ | thanks |
| 00:31 | _rata__ | I was unsure |
| 00:31 | amalloy | _rata__: i can't defrecord on clojurebot, but you can try (supers (class x)), where x is some defrecord'ed object |
| 00:31 | _rata__ | ok |
| 00:34 | _rata__ | good night |
| 00:47 | LauJensen | Good morning all |
| 00:50 | amalloy | morning lau. up early today? |
| 00:51 | amalloy | (note: i don't actually know what time it is where you are, but you're usually not around for two more hours or so) |
| 00:52 | LauJensen | amalloy: Yea I usually get here by 9AM but todays its 6:50AM now |
| 00:54 | notsonerdysunny | how can one create a soft-link in a cake-task? |
| 00:55 | LauJensen | soft link? |
| 00:55 | amalloy | as in the $ ln -s variety? |
| 00:55 | notsonerdysunny | LauJensen: yes soft link |
| 00:55 | LauJensen | amalloy: thats a symlink |
| 00:55 | KirinDave | Anyone here good with enlive? |
| 00:55 | notsonerdysunny | :) yes symlink |
| 00:56 | amalloy | LauJensen: i know, but it was likely to be what he meant |
| 00:56 | KirinDave | Having problems with nth-of-type. |
| 00:56 | LauJensen | (sh "ln" "-s" "src" "dest") |
| 00:56 | amalloy | i think you have to launch the shell; java doesn't have symlink feature |
| 00:56 | LauJensen | amalloy: yea you're just a lot smarter than me it seems :) |
| 00:56 | lancepantz | nah, you should use the ant task |
| 00:56 | amalloy | LauJensen: perhaps a lot dumber! |
| 00:56 | lancepantz | notsonerdysunny: http://ant.apache.org/manual/Tasks/symlink.html |
| 00:56 | lancepantz | so you would use cake's ant helper fn |
| 00:57 | LauJensen | lancepantz: any idea what that does on Windows? |
| 00:58 | amalloy | LauJensen: i wouldn't be surprised if it did what cygwin does |
| 00:58 | LauJensen | Which is? |
| 00:58 | notsonerdysunny | lancepantz: can you please give me the syntax for the cake's ant helper function to create a symlink |
| 00:58 | amalloy | which iirc is create a .lnk (windows shortcut file), with metadata attached to it that lets other cygwin processes treat it as a symlink |
| 00:58 | LauJensen | ah ok |
| 00:58 | notsonerdysunny | I think Windows 7 and vista support link |
| 00:58 | lancepantz | (ant Symlink {:link "foo" :resource "bar"}) |
| 00:59 | notsonerdysunny | thanks lancepantz |
| 00:59 | lancepantz | LauJensen: there's a disclaimer at the end of the above link |
| 01:00 | amalloy | LauJensen: yeah, just checked my windows machine. ln -s creates a .lnk with some kind of special metadata |
| 01:00 | LauJensen | great. |
| 01:01 | amalloy | (on my 5-year-old XP system. sunny seems to think vista/7 are smarter) |
| 01:11 | notsonerdysunny | amalloy: I read about it some-where .. not very positive though |
| 01:13 | Bahman | Hi all! |
| 01:14 | LauJensen | Morning Bahman |
| 01:14 | Bahman | Hi there LauJensen! |
| 01:21 | chouser | NTFS has supported links forever, I think, but the rest of the OS and the applications all get very confused. |
| 01:26 | notsonerdysunny | chouser: so what is the command to create a symlink or hardlink in windows/NTFS then? |
| 01:30 | amalloy | chouser: this seems to be true. my ubuntu system can create a hardlink on the mounted ntfs drive that windows uses. whether or not windows can understand it i haven't tested |
| 01:50 | sandGorgon | is there any way for me to figure out what is the exact java command used by lein when I do "lein repl" in a project ? is there any verbose setting for example |
| 01:52 | LauJensen | sandGorgon: Well, there is an environment variable which you can set, to make it more verbose, it outputs the classpath at least. But I'd just run ps ax |grep java if I wanted to know |
| 01:54 | kmc | you could use strace |
| 01:54 | sandGorgon | kmc, how do I use strace for that ? |
| 01:55 | amalloy | sandGorgon: or jps and then look at /proc/xxxxx/cmdline |
| 01:55 | kmc | strace -f -e execve -s 99999999 lein repl |
| 01:57 | sandGorgon | kmc, wow.. thanks that was great. |
| 01:57 | sandGorgon | LauJensen, thanks.. that worked as well ;) |
| 01:59 | LauJensen | np |
| 02:05 | sandGorgon | has anyone looked at the source code of cake ? it is kinda funky - for e.g. src/cake/tasks/jar.clj:53 why is "(ns cake)" a string, which is written into a file called build/jar/cake.clj when cake is invoked ? |
| 02:09 | notsonerdysunny | does the reader macro #' have a corresponding function |
| 02:09 | lancepantz | sandGorgon: yeah, so cake actually runs in two jvms |
| 02:09 | amalloy | ,(get-var 'clojure.core/first) |
| 02:09 | clojurebot | java.lang.Exception: Unable to resolve symbol: get-var in this context |
| 02:09 | lancepantz | once for your project, and one that processes cake commands |
| 02:09 | amalloy | ,(ns-resolve 'clojure.core 'first) |
| 02:09 | clojurebot | #'clojure.core/first |
| 02:10 | amalloy | notsonerdysunny: there's one that's more convenient than that, lemme go find it |
| 02:10 | lancepantz | then there is a ruby script that sits in front of those two, sending forms over the socket to get evaled in the jvms |
| 02:10 | LauJensen | ,(= (var test) #'test) |
| 02:10 | clojurebot | true |
| 02:10 | notsonerdysunny | ,(doc var) |
| 02:10 | clojurebot | notsonerdysunny: I don't understand. |
| 02:10 | notsonerdysunny | ->(doc var) |
| 02:10 | sexpbot | ⟹ "Special Form: Please see http://clojure.org/special_forms#var" |
| 02:10 | amalloy | ,(var-get 'clojure.core/first) |
| 02:10 | clojurebot | java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Var |
| 02:11 | kmc | what does sexpbot do? |
| 02:11 | notsonerdysunny | ->(doc var-get) |
| 02:11 | sexpbot | java.lang.SecurityException: Code did not pass sandbox guidelines: (#'clojure.core/var-get) |
| 02:11 | LauJensen | ,(-> #'var meta :doc println) |
| 02:11 | clojurebot | java.lang.Exception: Unable to resolve var: var in this context |
| 02:11 | amalloy | roughly the same as clojurebot, with a different codebase |
| 02:12 | notsonerdysunny | var is a special form .. |
| 02:12 | notsonerdysunny | so I guess we can't do #'var |
| 02:12 | sandGorgon | lancepantz, all right, but then why isnt there an inherent cake.clj in the project itself ? I dont think cake can be run from the commandline (using java commandline) because there is no cake.clj |
| 02:12 | notsonerdysunny | LauJensen: * |
| 02:13 | LauJensen | ,(-> #'loop meta :doc println) |
| 02:13 | clojurebot | Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein. Acts as a recur target. |
| 02:13 | LauJensen | -> (doc loop) |
| 02:13 | sexpbot | ⟹ "Special Form: Please see http://clojure.org/special_forms#loop" |
| 02:13 | amalloy | ,(find-var 'clojure.core/first) |
| 02:13 | clojurebot | #'clojure.core/first |
| 02:13 | LauJensen | notsonerdysunny: ^^ |
| 02:14 | amalloy | notsonerdysunny: the functions you probably want are intern, find-var, and ns-resolve |
| 02:15 | notsonerdysunny | thanks amalloy and LauJensen |
| 02:25 | amalloy | ,(zipmap (map (juxt identity -) (range 4))) |
| 02:25 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$zipmap |
| 02:25 | amalloy | ,(apply zipmap (map (juxt identity -) (range 4))) |
| 02:25 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (4) passed to: core$zipmap |
| 02:25 | amalloy | blahhhh |
| 02:26 | amalloy | ,(apply hash-map (map (juxt identity -) (range 4))) |
| 02:26 | clojurebot | {[0 0] [1 -1], [2 -2] [3 -3]} |
| 02:27 | LauJensen | amalloy: let me guess, you used to do a lot of perl ? :) |
| 02:27 | kmc | ,(doc juxt) |
| 02:27 | clojurebot | "([f] [f g] [f g h] [f g h & fs]); Alpha - name subject to change. Takes a set of functions and returns a fn that is the juxtaposition of those fns. The returned fn takes a variable number of args, and returns a vector containing the result of applying each fn to the args (left-to-right). ((juxt a b c) x) => [(a x) (b x) (c x)]" |
| 02:27 | amalloy | LauJensen: hah, not actually very much. why, am i trying to do something like perl? |
| 02:27 | kmc | cool function |
| 02:28 | amalloy | kmc: yes, it's one to keep in mind. it turns out to be useful in a lot of interesting ways |
| 02:28 | LauJensen | amalloy: I once did something like what you just did, ie. tweaking until something working came out. Someone rebuked me saying "You need to understand what you're doing, not just tweak until it works, thats perl development" |
| 02:28 | amalloy | ,(map (juxt inc dec) (range 5)) |
| 02:28 | clojurebot | ([1 -1] [2 0] [3 1] [4 2] [5 3]) |
| 02:28 | kmc | amalloy, yeah, i've used something similar in Haskell |
| 02:29 | amalloy | LauJensen: in perl, tweaking is your only option. clojure gives you the choice to understand what you're doing...or just keep pounding on the keyboard like i was doing |
| 02:29 | kmc | heh |
| 02:29 | LauJensen | amalloy: well, im just gla you're not in charge of marketing |
| 02:29 | kmc | them's fightin' words |
| 02:29 | amalloy | i always have trouble creating a hash-map out of a map |
| 02:29 | LauJensen | kmc: naah, all the fighting words are on my blog :) |
| 02:29 | amalloy | ,(apply hash-map (mapcat (juxt identity -) (range 4))) |
| 02:29 | clojurebot | {0 0, 1 -1, 2 -2, 3 -3} |
| 02:30 | amalloy | there we go |
| 02:30 | amalloy | kmc, what time zone are you in, if you don't mind? |
| 02:30 | kmc | EDT |
| 02:30 | LauJensen | ,(map (juxt (comp inc rand-int) +) (range 10)) |
| 02:30 | kmc | GMT-4 |
| 02:30 | clojurebot | ([1 0] [1 1] [1 2] [1 3] [1 4] [5 5] [2 6] [5 7] [7 8] [8 9]) |
| 02:31 | kmc | comp is function composition? |
| 02:31 | amalloy | yes |
| 02:31 | LauJensen | yes |
| 02:31 | amalloy | blurgh. i used to stay up that late, but now that i have a job i can't stay up past like 1 without killing myself (pacific time) |
| 02:31 | LauJensen | (comp f g) = (f (g x)) |
| 02:31 | LauJensen | amalloy: you're getting older :) |
| 02:31 | amalloy | LauJensen: not so. ((comp f g) x) = (f (g x)) |
| 02:32 | LauJensen | tsk |
| 02:32 | amalloy | LauJensen: and yeah, getting older, but mostly getting up earlier |
| 02:33 | amalloy | (or at least that's what i tell myself) |
| 02:34 | LauJensen | I really would like to know what they eat, the guys who run on 4 hours of sleep every night, that must be great |
| 02:34 | kmc | ,((comp inc *) 5 4) |
| 02:34 | clojurebot | 21 |
| 02:35 | kmc | sweet |
| 02:35 | amalloy | LauJensen: future years of their lives |
| 02:36 | bobo_ | and efficency of the ours they are awake |
| 02:37 | bobo_ | they probably get less done in more time |
| 02:37 | LauJensen | bobo_: Tell that to Obama, Denmarks former Primeminister and Dana White, who all seem to get a lot done |
| 02:37 | amalloy | i get about six hours a night, and ten hours once a week when i realize i'm exhausted :P |
| 02:38 | kmc | ((comp + *) 5 4) |
| 02:38 | kmc | ,((comp + *) 5 4) |
| 02:38 | clojurebot | 20 |
| 02:38 | LauJensen | amalloy: yea I used to do that, if was just 5 and 10 |
| 02:38 | kmc | ,((comp (partial + 1) *) 5 4) |
| 02:38 | clojurebot | 21 |
| 02:38 | amalloy | ,((juxt + *) 5 4) |
| 02:38 | clojurebot | [9 20] |
| 02:44 | notsonerdysunny | can anybody help me figure out why #(-> % second :name) goes through fine while #(-> % second (fn [x] (:name x))) does not .. both seem identical to me... |
| 02:45 | amalloy | ,(macroexpand '(-> % (fn [x] (:name x)))) |
| 02:45 | clojurebot | (fn* % ([x] (:name x))) |
| 02:45 | amalloy | ,(macroexpand '(-> % ((fn [x] (:name x))))) |
| 02:45 | clojurebot | ((fn [x] (:name x)) %) |
| 02:45 | amalloy | notsonerdysunny: you want the second of these |
| 02:47 | amalloy | (though what you *actually* want is (comp :name second)) |
| 02:47 | notsonerdysunny | amalloy: aha .. I think I see what is happening .. thanks .. :) |
| 02:48 | notsonerdysunny | yea you are right comp is a better way of doing it |
| 02:48 | amalloy | ,((comp :name second) [{:name 10} {:name 15}]) |
| 02:48 | clojurebot | 15 |
| 02:51 | LauJensen | ,15 |
| 02:51 | clojurebot | 15 |
| 02:51 | LauJensen | much easier |
| 02:51 | amalloy | LauJensen: you're right. i don't know why i bother writing any programs; i should just figure things out by hand and then write the answer in a clj file |
| 02:51 | notsonerdysunny | LauJensen: :) |
| 02:51 | amalloy | ,(identical? 15 15) |
| 02:51 | clojurebot | true |
| 02:52 | LauJensen | ,(identical? 130 130) |
| 02:52 | clojurebot | false |
| 02:52 | amalloy | that's the result i would have expected |
| 02:52 | amalloy | why did i get true? |
| 02:52 | kmc | haha |
| 02:52 | kmc | interning of small integers? |
| 02:52 | kmc | ,(doc identical?) |
| 02:52 | LauJensen | amalloy: The first 128 integers are hardcoded in the jvm |
| 02:52 | clojurebot | "([x y]); Tests if 2 arguments are the same object" |
| 02:52 | amalloy | ,(identical? -5 -5) |
| 02:52 | clojurebot | true |
| 02:53 | kmc | ,(let [x 130] (identical? x x)) |
| 02:53 | clojurebot | true |
| 02:53 | amalloy | LauJensen: the first 256 :P |
| 02:53 | kmc | the first 127 and the last 128 |
| 02:53 | LauJensen | sure |
| 02:53 | LauJensen | punks |
| 02:53 | LauJensen | :) |
| 02:53 | amalloy | kmc: that adds up to 255. you have to include 0 in one of the two sets |
| 02:54 | LauJensen | ,(true? (Boolean. "true")) |
| 02:54 | clojurebot | false |
| 02:54 | kmc | that constructs a Java Boolean from the string "true"? |
| 02:54 | kmc | is there a better way to write #(identical? % %) ? |
| 02:54 | LauJensen | ,(Boolean. "true") |
| 02:54 | clojurebot | true |
| 02:54 | kmc | ,(Boolean.) |
| 02:54 | clojurebot | java.lang.IllegalArgumentException: No matching ctor found for class java.lang.Boolean |
| 02:54 | amalloy | kmc: identical? |
| 02:54 | amalloy | oh |
| 02:54 | kmc | ,(new Boolean) |
| 02:54 | clojurebot | java.lang.IllegalArgumentException: No matching ctor found for class java.lang.Boolean |
| 02:55 | kmc | ,(new Boolean "true") |
| 02:55 | clojurebot | true |
| 02:55 | kmc | in general, is there a better way to write #(f % %) |
| 02:55 | lypanov | ,(new Boolean TRUE) |
| 02:55 | clojurebot | java.lang.Exception: Unable to resolve symbol: TRUE in this context |
| 02:55 | LauJensen | (new Boolean "true") == (Boolean. "true") |
| 02:55 | LauJensen | lypanov: You're thinking of Boolean/TRUE |
| 02:55 | lypanov | ah, thats the one. forgot the syntax. |
| 02:55 | kmc | ,Boolean/TRUE |
| 02:55 | clojurebot | true |
| 02:55 | kmc | and that's a static field of the Boolean Java class? |
| 02:55 | kmc | ,(Integer. 3) |
| 02:55 | clojurebot | 3 |
| 02:56 | amalloy | kmc: i'm not sure, about (f x x). there must be an easy way |
| 02:56 | LauJensen | ,(set (range 32)) |
| 02:56 | clojurebot | #{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} |
| 02:56 | LauJensen | ,(set (range 33)) |
| 02:56 | clojurebot | #{0 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} |
| 02:56 | kmc | heh |
| 02:56 | lypanov | cute |
| 02:56 | kmc | ,(class 5) |
| 02:56 | clojurebot | java.lang.Integer |
| 02:56 | kmc | ,(class 5000000000000000000000000) |
| 02:56 | clojurebot | java.lang.ExceptionInInitializerError |
| 02:57 | amalloy | ! |
| 02:57 | kmc | ;P |
| 02:57 | lypanov | huh |
| 02:57 | LauJensen | This is almost better than PHP :) |
| 02:57 | amalloy | oh |
| 02:57 | kmc | ,(Bignum. 500000 500000) |
| 02:57 | clojurebot | java.lang.IllegalArgumentException: Unable to resolve classname: Bignum |
| 02:57 | kmc | ,(java.lang/Bignum. 500000 500000) |
| 02:57 | clojurebot | java.lang.ClassNotFoundException: java.lang |
| 02:57 | kmc | hrm |
| 02:57 | LauJensen | kmc: in 1.3 you can to (class 5000000000000000000N) |
| 02:57 | amalloy | ,(class 500000000000000000L) |
| 02:57 | clojurebot | Invalid number: 500000000000000000L |
| 02:57 | amalloy | ,(class 500000000000000000M) |
| 02:57 | clojurebot | java.math.BigDecimal |
| 02:58 | kmc | cool |
| 02:58 | LauJensen | ,(class (bigint 5000000000000000000000000)) |
| 02:58 | clojurebot | java.lang.ExceptionInInitializerError |
| 02:58 | LauJensen | eh? |
| 02:58 | LauJensen | ,(clojure-version) |
| 02:58 | clojurebot | "1.2.0-master-SNAPSHOT" |
| 02:58 | LauJensen | -> (class (bigint 5000000000000000000000000)) |
| 02:58 | amalloy | ,(doc bigint) |
| 02:58 | sexpbot | java.lang.Exception: EvalReader not allowed when *read-eval* is false. |
| 02:58 | clojurebot | "([x]); Coerce to BigInteger" |
| 02:58 | LauJensen | ,*read-eval* |
| 02:58 | clojurebot | false |
| 02:58 | amalloy | LauJensen: (bigint) doesn't get called until 50000000000000 is evaluated, and it's an illegal integer literal |
| 02:59 | LauJensen | anyway, I should really do some work |
| 02:59 | amalloy | ,100N |
| 02:59 | lypanov | hehe |
| 02:59 | clojurebot | Invalid number: 100N |
| 02:59 | LauJensen | amalloy: works in the repl here though |
| 02:59 | amalloy | hm |
| 02:59 | LauJensen | same clojure version |
| 03:00 | kryft | Does this just destructure the value of the function neighbors? ([size yx] (neighbors [[-1 0] [1 0] [0 -1] [0 1]] size yx)) |
| 03:00 | kryft | (Looking at listing 5.1 in JoC) |
| 03:01 | amalloy | kryft: no, that code is doing no destructuring |
| 03:01 | amalloy | it is treating the vector [size yx] as a function, and calling it with the result of (neighbors ...) |
| 03:01 | amalloy | when vectors are called as functions, they treat their argument as an index |
| 03:02 | amalloy | ,([\a '- "qqq"] 1) |
| 03:02 | clojurebot | - |
| 03:02 | Chousuke | that looks more like a variadic function definition for the [size yx] parameter vector |
| 03:02 | Chousuke | taken out of context :P |
| 03:02 | amalloy | however, if there's a (fn) lurking around near the code that you didn't show us... |
| 03:03 | amalloy | (and i agree with Chousuke, it looks like it is) |
| 03:06 | kryft | amalloy: http://pastebin.com/YTPJ8iUq (Listing 5.1 in Joy of Clojure) |
| 03:06 | amalloy | kryft: Chousuke is correct |
| 03:06 | Chousuke | yeah. it calls the 3-arg version of neighbor from the 2-arg version |
| 03:06 | amalloy | it's saying that neighbors can take 2 or 3 arguments. the 2-argument version calls the 3-arg version |
| 03:06 | Chousuke | the first arg is just a vector of vectors. |
| 03:07 | kryft | Ah, ok, I don't think that was covered in the book yet. :) |
| 03:08 | kryft | I forgot about that syntax for indexing vectors even though I just read about it. :P |
| 03:10 | amalloy | kryft: see 2.3.2 |
| 03:10 | amalloy | discussing variadic args |
| 03:14 | tomoj | anyone using octobot in clojure yet? |
| 03:22 | amalloy | ah, kryft, he does mention using vectors as functions in chapter 5, but it's hidden so well i had to reread the whole damn chapter to find it |
| 03:22 | amalloy | it's in 5.2.2 |
| 03:30 | bartj | ,([1 2 3] 0) |
| 03:30 | clojurebot | 1 |
| 03:33 | tomoj | ztellman is my hero |
| 03:33 | amalloy | ,([1 2 3] -1) |
| 03:33 | clojurebot | java.lang.IndexOutOfBoundsException |
| 03:33 | amalloy | :( |
| 03:33 | LauJensen | tomoj: why? |
| 03:35 | tomoj | http://github.com/ztellman/gloss |
| 03:35 | tomoj | not to mention aleph |
| 03:36 | zkim | and penumbra |
| 03:38 | LauJensen | Yea he's a cool and crafty guy, no doubt |
| 03:42 | kmc | cool |
| 03:42 | kmc | embedded gpgpu programming for clojure |
| 03:42 | kmc | i like that a lot |
| 03:42 | LauJensen | kmc: Yea he's done 2 amazing ports of my blogposts to Penumbra |
| 03:43 | LauJensen | First Brians Brain, when in optimized Clojure it does a 160x160 board in 1.6ms, Zach kept it at 1.6ms per iteration, but on a 2000x2000 board. My Fluid sim ran about 35 fps (I think) on a 80x80 board, Zach had it on 55 fps on a 800x600 board. |
| 03:43 | kmc | nice |
| 03:43 | kmc | i love GPU programming |
| 03:43 | kmc | need to get back into it |
| 03:44 | kmc | i was doing fractal video feedback loops at 4096 x 4096 x 60fps, in 2007, without particularly optimizing my code |
| 03:44 | kmc | there's just so much power there |
| 03:44 | kmc | that card is probably in every midrange machine now |
| 03:44 | LauJensen | I read that the largest supercomputer in 1998 had the same power as a 500$ graphics card today |
| 03:44 | kmc | hehe |
| 03:45 | hiredman | thats a hell of a screensaver |
| 03:45 | kmc | well, i'd bet that supercomputer had more ability to do *different* things at once |
| 03:45 | LauJensen | no |
| 03:45 | LauJensen | it would only solve solitaire puzzles |
| 03:45 | kmc | haha |
| 03:45 | LauJensen | j/k ofc :) |
| 03:46 | kmc | http://en.wikipedia.org/wiki/Semi_Automatic_Ground_Environment ← the largest computer, ever |
| 04:37 | jjido | no clojurebot today |
| 04:37 | LauJensen | jjido: ? |
| 04:38 | jjido | ,true |
| 04:38 | LauJensen | clojurebot: where are you ? |
| 04:38 | LauJensen | -> true |
| 04:38 | sexpbot | ⟹ true |
| 04:38 | LauJensen | Well, there are alternatives |
| 04:46 | jjido | -> (:foo nil) |
| 04:46 | sexpbot | ⟹ nil |
| 04:52 | jjido | killall -s java | wc -l --> 6 |
| 04:52 | jjido | killall java |
| 04:52 | jjido | how many stray processes do I have? |
| 04:57 | jjido | Is there a string representation of Clojure objects which is resilient to structural loops (with an atom)? |
| 05:01 | notsonerdysunny | thanks raek |
| 05:01 | notsonerdysunny | that actually highlights the use of atom |
| 05:01 | notsonerdysunny | :) |
| 05:02 | raek | sorry for being offensive about the def thing... I should have mentioned what "the right way" was, rather than just saying "you're doing it wrong" |
| 05:04 | bmh | dear #clojure -- I love clojure so much. The Java interop makes me so happy |
| 05:04 | jjido | -> (take 10 (.toString first)) |
| 05:04 | sexpbot | java.lang.SecurityException: Tried to call: toString on clojure.core$first@137e670 which is not allowed. |
| 05:06 | notsonerdysunny | raek: no problem ... being critical is what makes this fun.. :) |
| 05:06 | esj | bmh: absolutely, playing with libraries like JFreeChart from a repl makes me uncommonly happy |
| 05:07 | bmh | esj: I found a C++ library that did the things I wanted it to do, but bugger, it's written in C++. I found a Java library that did some of the things I want to do, so bam. I can use the Java bits to port the C++ code I need! |
| 05:07 | bmh | (sorry if that was incoherent) |
| 05:07 | esj | bmh: not at all |
| 05:07 | raek | notsonerdysunny: actually, thing the counter example would be a good example to have on clojuredocs. it very clearly shows how the function is applied to the data structure |
| 05:09 | jjido | -> (take 10 (str first)) |
| 05:09 | sexpbot | ⟹ (\c \l \o \j \u \r \e \. \c \o) |
| 05:10 | jjido | but I guess that won't prevent a stack overflow. |
| 05:12 | raek | jjido: what are you trying to do? :) |
| 05:13 | jjido | raek: I want to find out what I did wrong (error), so I want to print out objects. But that goes in infinite loop because of an atom. |
| 05:14 | raek | jjido: does the data structure in the atom have a reference to the atom itself? |
| 05:14 | jjido | yes |
| 05:15 | raek | then it might be a good thing to wrap the printing code in a (binding [*print-level* 10] ...) |
| 05:16 | raek | when an atom is printed/stringified, it will turn its contents into a string first |
| 05:16 | raek | at the repl, you can also do a (set! *print-level* 10) |
| 05:16 | jjido | is that the depth or the string length? |
| 05:17 | raek | form depth |
| 05:17 | raek | there is a *print-length* too |
| 05:20 | notsonerdysunny | can somebody help me with an example for apply-macro from clojure.contrib.apply-macro |
| 05:24 | notsonerdysunny | (defmacro hello [x] |
| 05:24 | notsonerdysunny | `(sayhello ~x)) |
| 05:24 | notsonerdysunny | (macroexpand-1 (apply-macro hello '(10))) |
| 05:25 | notsonerdysunny | http://gist.github.com/625927 is my example .. but I keep getting a stack overflow .. |
| 05:34 | jjido | raek: ok, I inadvertently shared an atom :( |
| 05:52 | jjido | I see no effect of using the *print-length* binding. *print-level* works great though. |
| 06:20 | raek | ,(binding [*print-length* 3] (println ["one" "two" "three" "four"])) |
| 06:20 | clojurebot | [one two three ...] |
| 06:21 | raek | it inly restricts the number of element printed from collections |
| 06:21 | raek | ,(binding [*print-level* 3] (println ["one" ["two" ["three" ["four"]]]])) |
| 06:21 | clojurebot | [one [two [three #]]] |
| 06:23 | raek | *print-length* is useful when dealing with infinite or very long sequences and *print-level* when dealing with circular structures or deep trees |
| 06:26 | jjido | raek: thanks |
| 06:34 | rfgpfeiffer | how can i give a function a fixed time to return or kill it? |
| 06:36 | raek | rfgpfeiffer: I know that clj-sandbox (http://github.com/Licenser/clj-sandbox) does something like that |
| 06:37 | raek | http://github.com/Licenser/clj-sandbox/blob/master/src/net/licenser/sandbox.clj#L35 |
| 06:38 | LauJensen | rfgpfeiffer: http://gist.github.com/626002 |
| 06:38 | rfgpfeiffer | thanks |
| 06:38 | LauJensen | np |
| 06:41 | raek | ,(class (future 1)) |
| 06:41 | clojurebot | clojure.core$future_call$reify__5492 |
| 06:43 | raek | hrm, what happens with the running code if a timeout occurs? |
| 06:43 | LauJensen | it gets barged |
| 07:56 | tobiasraeder | anyone ever done anything with wings and clojure? |
| 08:06 | carkh | wew that wing thing is ugly |
| 08:09 | LauJensen | carkh: ? |
| 08:11 | carkh | i was reacting to tobiasraeder's query |
| 08:11 | bmh | I'm trying to use penumbra and the universe is exploding on me when I run 'lein test' |
| 08:13 | bmh | hurumph, looks like a case of a broken test |
| 08:16 | LauJensen | carkh: Yea, just wondering what you were looking at |
| 08:16 | LauJensen | ie. link |
| 08:17 | carkh | http://wingsframework.org/wingset/WingSet/ |
| 08:17 | LauJensen | bmh: just start a project vm and run the examples |
| 08:17 | bmh | LauJensen: I just spotted it on the bug tracker |
| 08:17 | bmh | thanks |
| 08:23 | kumarshantanu | I have a question on Java interop |
| 08:23 | kumarshantanu | ,(. "Hello" :toLowerCase) ; this works |
| 08:23 | clojurebot | "hello" |
| 08:24 | kumarshantanu | ,(. "Hello" :substring 3 4) ; but this doesn't |
| 08:24 | clojurebot | java.lang.IllegalArgumentException: Malformed member expression |
| 08:24 | kumarshantanu | can anyone help me understand this? |
| 08:24 | carkh | ,(. "hello" substring 3 4) |
| 08:24 | clojurebot | "l" |
| 08:25 | carkh | don't know why using a keyword should work on the first example |
| 08:25 | carkh | you're supposed to use simple symbols |
| 08:25 | kumarshantanu | carkh: I want to be able to compose the method name at runtime (I don't know them in advance) |
| 08:25 | LauJensen | kumarshantanu: The first example shouldnt work, thats just a result of how keywords are implemented |
| 08:25 | carkh | kumarshantanu: what's your use case ? |
| 08:26 | kumarshantanu | LauJensen: I see |
| 08:26 | kumarshantanu | carkh: I have a bunch of setter methods to be called, so want to create a helper function to call them |
| 08:26 | kumarshantanu | but I don't know them in advance |
| 08:27 | carkh | you might have to use reflection |
| 08:27 | carkh | there is a helper function somewhere in clojure (java side) |
| 08:27 | carkh | clojrue.lang.Reflector has it i think |
| 08:28 | kumarshantanu | example: (setter! some-obj {:method1 [m1-value1] :method2 [m2-value1 m2-value2]}) --> (doto some-obj ((.method1 m1-value1) (.method2 m2-value1 m2-value2)) |
| 08:28 | carkh | (clojure.lang.Reflector/invokeInstanceMethod instance method-name-as-string array-of-args) |
| 08:28 | kumarshantanu | okay *looking* |
| 08:29 | carkh | note that args are an array, not a vector |
| 08:29 | carkh | http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Reflector.java |
| 08:31 | kumarshantanu | carkh: there seems to be a c.c.reflect too -- http://richhickey.github.com/clojure-contrib/reflect-api.html |
| 08:31 | carkh | ahyes indeed ! |
| 08:33 | carkh | yes that would help tremendously |
| 08:38 | LauJensen | You guys should use emacs, fuzzy completions expands c.c to clojure.contrib |
| 08:40 | carkh | i do but fuzzy completion is not perfect for namespaces |
| 08:40 | carkh | maybe some setup problem |
| 08:40 | carkh | i walways end up with clojure.contrib.sql/<space> |
| 08:43 | kumarshantanu | ,(clojure.contrib.reflect/call-method java.lang.String :substring [] "hello" 3 4) |
| 08:43 | clojurebot | java.lang.ClassNotFoundException: clojure.contrib.reflect |
| 08:45 | kumarshantanu | I am still getting this error on my local REPL: java.lang.NoSuchMethodException: java.lang.String.substring() |
| 08:46 | carkh | the vector should have classes inside it |
| 08:47 | carkh | [java.lang.String java.lang.Integer java.lang.Integer] i guess |
| 08:47 | carkh | i think it's easier to use (clojure.lang.Reflector/invokeInstanceMethod instance method-name-as-string array-of-args) |
| 08:48 | jk_ | are there any old-time common lispers here who resent the mixture of messy, stateful java into lisp? i've been really interested in the controversy and when most old-timers go with clojure, it seems like it's with a shrug like it's the lesser of 2 evils (using only java, for example) |
| 08:48 | jk_ | probably a bad question in this forum :) |
| 08:49 | kumarshantanu | carkh: I am passing [Integer Integer] too, but the signature accepts primitives |
| 08:49 | kumarshantanu | not working....I guess that might be the reason |
| 08:50 | carkh | jk_: well common lisp is very imperative as well |
| 08:51 | carkh | kumarshantanu: really you should try c.l.reflector/invokeInstanceMethod, i had success using it |
| 08:52 | kumarshantanu | carkh: I will use Reflector, I was just wondering the clojure.contrib version may be better supported |
| 08:52 | carkh | kumarshantanu: clojure itself uses reflector so i guess it's here to stay =P |
| 08:53 | jk_ | carkh: what about exceptions? does that seriously detract? |
| 08:54 | carkh | jk_: conditions sure are way better, but exceptions are good enough in most cases |
| 08:54 | carkh | and we have a library for condition-like behaviour |
| 08:54 | carkh | though i never used it |
| 08:54 | kumarshantanu | ,(clojure.lang.Reflector/invokeInstanceMethod "Hello World" "substring" (into-array [3 4])) |
| 08:54 | clojurebot | "l" |
| 08:55 | carkh | kumarshantanu: yay ! |
| 08:56 | kumarshantanu | carkh: invokeInstanceMethod should be promoted to c.c (!) |
| 08:56 | jk_ | carkh: ok, one last question... do you think seq is a big win over the predominance on cons cells? as a newcomer, that shift in focus looks like an advantage |
| 08:56 | carkh | yes i beleive so |
| 08:57 | carkh | most of the time you'll be working with vectors instead of lists |
| 08:57 | carkh | it's very handy to be able to use seq abstraction on these |
| 08:57 | carkh | and vector are _fast_ |
| 08:57 | carkh | vectors* |
| 08:58 | jk_ | thanks :) |
| 08:58 | carkh | also they grow at the end, so you can avoid most of this reverse non-sense |
| 09:00 | jk_ | carkh: i was watching some online lectures where they are teaching with scheme and i was wondering if lispers thought something was lost or radically different with clojure because they always had such a strong link to the cons cell data structure before |
| 09:00 | carkh | well we still have cons cells |
| 09:00 | carkh | kinda |
| 09:01 | carkh | we have single linked lists anyways, for a cons cell we use a simple vector |
| 09:01 | carkh | but really i think it's a plus to have the right data structure for the right job |
| 09:02 | carkh | sure the jvm has its drawbacks, but it has many good features |
| 09:03 | carkh | and clojure is way above CL for functional purity (though not to the haskell level) |
| 09:04 | carkh | take CL's hash tables for instance |
| 09:04 | carkh | very imperative |
| 09:05 | carkh | we have fully immutable and persistent maps in clojure for that |
| 09:11 | pdk` | i recall some article once whining about clojure wasnt lisp all the way down and how evil this was cause it was on the jvm |
| 09:11 | pdk` | though on the other hand |
| 09:11 | pdk` | the same person who wrote that still thought his efforts to make a multi ghz lisp machine for today's world were remotely practical |
| 09:11 | carkh | there is strong opposition to clojure in the CL community |
| 09:12 | _fogus_ | jk_: Common Lisp is not necessarily centered around the cons cell. It has a powerful sequence abstraction. |
| 09:13 | carkh | _fogus_: though the sequence abstraction doesn't go as far as in clojrue |
| 09:13 | _fogus_ | carkh: I haven't noticed a very strong opposition at all. |
| 09:13 | jk_ | pdk`: http://www.loper-os.org/?p=46 probably this guy :) |
| 09:13 | carkh | i guess it withered down with time, they're mostly ignoring clojure |
| 09:13 | pdk` | oh yeah i was just about to look for that jk |
| 09:13 | _fogus_ | carkh: It's not as pervasive no. But the point is that the Common Lisp world does not revolve around the cons cell. |
| 09:14 | pdk` | but the tl;dr of it is it boiled down to whining from an ivory tower |
| 09:14 | carkh | _fogus_: anyways i can see their point, CL has been there for decades, clojure is but a blip on their radar |
| 09:15 | Bahman | Hi all! |
| 09:16 | jk_ | pdk`: well i was reading through a lot of this blogs and i don't think it's really ivory tower whining. he's claiming that something truly valuable was lost when lisp machines went away because the same abstractions when all the way down giving crystal clarity to the whole structure (that's how i read it anyway, in a nutshell) |
| 09:16 | _fogus_ | carkh: If you're a long-time Common Lisp programmer then you're probably happy with what you have. Plus, you've seen "other Lisps" come and go numerous times. ;-) |
| 09:16 | djpowell | where should i report a clojure-clr issue? |
| 09:17 | carkh | _fogus_: i never was fully happy with CL, the multi-processing issues (under windows) and the impertive nature of it were always a drawback |
| 09:17 | jk_ | _fogus_: thanks for the input. i guess i was getting that feeling (re cons cell) from some of R.H.'s comments and from the SICP lectures i'm viewing |
| 09:18 | pdk` | are these lectures recent |
| 09:18 | _fogus_ | jk_: Those SICP lectures are like 20 years old no? |
| 09:18 | jk_ | pdk`: mid-80's i think |
| 09:18 | jk_ | and it's scheme, not CL |
| 09:20 | _fogus_ | That's not to say that cons cells are not used in CL, they are an incredibly robust structure. Only, that they are not used exclusively. |
| 09:21 | jk_ | gotta go to work. thanks for the insightful comments, guys. |
| 09:21 | djpowell | ,(with-out-str (pprint {:a {:b "c"}})) |
| 09:21 | clojurebot | java.lang.Exception: Unable to resolve symbol: pprint in this context |
| 09:21 | djpowell | ,(with-out-str (clojure-version)) |
| 09:21 | clojurebot | "" |
| 09:21 | djpowell | ,(clojure-version) |
| 09:21 | clojurebot | "1.2.0-master-SNAPSHOT" |
| 09:22 | carkh | ,(with-out-str (clojure.contrib.pprint/pprint {:a {:b "c"}})) |
| 09:22 | clojurebot | java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.ClassNotFoundException: clojure.contrib.pprint |
| 09:22 | carkh | =/ |
| 09:22 | carkh | ,(require 'clojure.contrib.pprint) |
| 09:22 | clojurebot | java.io.FileNotFoundException: Could not locate clojure/contrib/pprint__init.class or clojure/contrib/pprint.clj on classpath: |
| 09:22 | djpowell | hmm, anyway pprint in clojure-clr totally mangles that expression |
| 09:23 | djpowell | as: {:a "c"{:b }} |
| 09:23 | _fogus_ | ,(with-out-str (clojure.pprint/pprint {:a {:b "c"}})) |
| 09:23 | clojurebot | "{:a {:b \"c\"}}\n" |
| 09:26 | carkh | ah i'm still with good old 1.1 =P |
| 10:08 | bmh | well this seems to be an energetic channel. Any penumbra users about, I'm trying to make sense of ztellman's marble vertex shader |
| 10:22 | cemerick | bmh: quiet just means work is getting done :-) |
| 10:26 | hircus | has anyone tried this snippet? http://gist.github.com/624638 |
| 10:26 | hircus | I tried it with Clojure 1.2.0 on Linux x64 -- both JDK 1.6.0u22 from Sun and IcedTea from Fedora |
| 10:27 | hircus | and the Clojure REPL freezes at (defprotocol...) -- it returns nil but never prompts for the next command |
| 10:36 | _fogus_ | hircus: Hrm. That' |
| 10:36 | _fogus_ | s odd |
| 10:37 | _fogus_ | hircus: Does it do that for every defprotocol ever? |
| 10:39 | cemerick | hircus: funky; works fine in both direct and ccw repls. |
| 10:40 | hircus | _fogus_: |
| 10:41 | hircus | _fogus_: I updated my comment in the gist. as it turns out it's just that the prompt is not printed after defprotocol. If I enter a simple expression (e.g. a number) then it's evaluated and the prompt is then printed |
| 10:41 | hircus | and it does not always happened -- I *sometimes* get the prompt back after defprotocol. odd eh |
| 10:45 | kryft | #(< -1 % size) <- Hmm, what does the % do? |
| 10:46 | MayDaniel_ | ,(#(- 10 %) 15) |
| 10:46 | clojurebot | -5 |
| 10:47 | kryft | MayDaniel_: Duh, of course :P |
| 10:58 | raek | kryft: #(< -1 % size) is the same as (fn [%] (< -1 % size)) |
| 11:00 | kryft | raek: Yeah, thanks. :) I did remember that #() was literal syntax for anonymous functions, but for some reason I didn't remember (and couldn't figure out) that naturally % must be an argument for the function. |
| 11:03 | kryft | There are no stupid questions, but some days I manage to get pretty close! |
| 11:05 | bhenry | is there any utility that will tell you all the namespaces on the classpath in which a given function is called? |
| 11:09 | raek | bhenry: with emacs and swank-clojure, there is "C-c C-w c: List all callers of a given function" |
| 11:10 | bhenry | awesome! |
| 11:12 | bhenry | raek i get error in process filter: Wrong type argument: char-or-string-p, nil |
| 11:12 | bhenry | i'm leaving the argument as is after the command |
| 11:15 | _rata_ | hi |
| 11:16 | dpritchett | does the newest vimclojure integrate with lein-nailgun? |
| 11:17 | dpritchett | I really want to like vimclojure but I haven't gotten used to classpaths... it's so nice to let leiningen deal with them for me. |
| 11:19 | _rata_ | is there a function like tree-seq but for graphs? (i.e., the children function can give nodes already visited by the function) |
| 11:21 | jkkramer | _rata_: http://github.com/jkk/loom or clojure.contrib.graph |
| 11:21 | _rata_ | clojure.contrib.graph doesn't have anything like that... I've already checked |
| 11:22 | jkkramer | lazy-walk does if you use ccg's graph structure |
| 11:23 | jkkramer | loom has loom.alg-generic/bf-traverse and others for general-purpose traversal |
| 11:24 | _rata_ | to use a ccg's graph structure I'd need a function like the one I'm asking for |
| 11:25 | _rata_ | I have my own data structure and I want to walk over it |
| 11:26 | jkkramer | then loom would be a better fit. it's alpha though so the API isn't concrete |
| 11:35 | fliebel | Hey |
| 11:35 | jkkramer | _rata_: if you do end up using loom, i'm interested in any feedback |
| 11:36 | fliebel | chouser or _fogus_: You probably know this, but the index of Joy of Clojure(which I just bought) says 'firehos', missing the 'e'. |
| 11:37 | _rata_ | jkkramer, I think my team wouldn't be happy to include another library dep, but I can see bf-traverse is self-contained, so I'd like to copy it right into my code... don't you mind? |
| 11:39 | dpritchett | firehoss |
| 11:39 | jkkramer | _rata_: sure, go for it. just pass along changes if you make any |
| 11:40 | _rata_ | ok... I think that lazy-seq should go at the beginning of the step function |
| 11:41 | jkkramer | my reasoning for not is that the first node is always available in the queue |
| 11:41 | jkkramer | and subsequent nodes require some work to find |
| 11:43 | jkkramer | but i'm not an expert in the subtleties of lazy-seq |
| 11:44 | _rata_ | I think it's preferable to have a complete lazy seq than a seq that's mixed |
| 11:45 | jkkramer | opinions from the #clojure sages? is the form (cons x (lazy-seq ...)) discouraged? |
| 11:46 | Chousuke | why would it be? |
| 11:46 | _rata_ | also I've always seen (lazy-seq (cons x ...)) in the functions returning lazy seqs |
| 11:46 | Chousuke | well the latter is lazier |
| 11:48 | Chousuke | If you do (defn foo [] (cons 1 (lazy-seq (foo)))) and call it it realizes the first element immediately. |
| 11:49 | jkkramer | right. when you have the first element in-hand that's not bad, is it? |
| 11:49 | Chousuke | Well, the recommendation is to make sequences as lazy as possible |
| 11:50 | jkkramer | if you did (member:defn foo [] (lazy-seq (cons 1 (foo)))) and (foo) takes some time to process, the first element would take longer to return |
| 11:50 | KirinDave | Because of chunking, right? It's already going to do sequences in blocks. |
| 11:50 | jkkramer | oops, scratch "member:"...colloquey weirdness |
| 11:51 | Chousuke | KirinDave: Chunking doesn't really matter here. |
| 11:51 | KirinDave | Chousuke: Right, but realizing the first several elements probably doesn't offer efficiency gains unless they're terribly expensive. |
| 11:52 | jkkramer | in the case of a graph traversal, finding neighbors not yet visited could be a less-than-fast task |
| 11:54 | jkkramer | and you'd be doing work for a step one farther than the consumer asked for |
| 11:55 | _rata_ | I don't think so |
| 11:57 | _rata_ | every function that returns a lazy-seq I've seen use the lazy-seq macro at the beginning of the function and they don't realize more elements than the ones asked for (except for chunking) |
| 11:57 | Chousuke | That's what we're saying |
| 11:57 | jkkramer | taking pre-traverse as an example: http://github.com/jkk/loom/blob/master/src/loom/alg_generic.clj#L30 if you request the one item, no work is done -- the start node is returned. if lazy-seq was moved before cons, it would find the neighbors of the starting node but still only return the starting node. right? i fully acknowledge i mgiht be misunderstanding lazy-seq |
| 11:59 | _rata_ | what's the difference between pre-traverse and bf-traverse? just DFS vs BFS? |
| 11:59 | jkkramer | yes. pre-traverse is preorder |
| 11:59 | jkkramer | and bfs right now has more options for filtering neighbors, depth, etc |
| 12:00 | jkkramer | still messing with the API |
| 12:00 | _rata_ | ok |
| 12:00 | _rata_ | why preorder = DFS? |
| 12:01 | _rata_ | it'd be more consistent to call it df-traverse |
| 12:01 | jkkramer | because dfs can be preorder or postorder |
| 12:03 | _rata_ | ah ok |
| 12:08 | dpritchett | Does anyone know how to use the vimclojure/server jar on clojars? Meikel suggests there should be a `lein run` task to start it up but that doesn't seem to be the case. |
| 12:08 | dpritchett | (http://groups.google.com/group/vimclojure/browse_thread/thread/69abeea9f57cb73b) |
| 12:11 | _rata_ | jkkramer, I've tried both versions of pre-traverse, your and the one with lazy-seq at the beginning, and the later is faster when I (take 1 ...) |
| 12:12 | jkkramer | _rata_: how are you benchmarking? |
| 12:12 | _rata_ | nothing serious, just (time ...) a couple of times |
| 12:13 | _rata_ | maybe the graph I'm giving to the function is too small |
| 12:14 | _rata_ | I'm calling it like (take 1 (pre-traverse {:a [:b :c], :b [:c], :c []} :a)) |
| 12:21 | jkkramer | (dotimes [_ 10] (time (doall (take 1 (pre-traverse {:a [:b :c], :b [:c], :c []} :a))))) is consistently faster for me with my version -- note the doall to realize the first element |
| 12:23 | jkkramer | also, (dotimes [_ 10] (time (doall (take 1 (pre-traverse #(do (Thread/sleep 100) ({:a [:b :c], :b [:c], :c []} %)) :a))))) demonstrates when the 'neighbors' function takes a long time to execute. with lazy-seq before cons, requesting the first element does the work for the second element |
| 12:25 | jkkramer | _rata_: ^ |
| 12:25 | dpritchett | woo, i figured it out! |
| 12:25 | @rhickey | -XX:MaxInlineSize=100 seems to help Clojure perf a good bit |
| 12:25 | @rhickey | interested in feedback from others if it helps you |
| 12:25 | dpritchett | add the vimclojure/server jar to lein's dev dependencies |
| 12:26 | dpritchett | then start the server with a quick alias including lein classpath |
| 12:26 | dpritchett | alias nailgun='java -cp "`lein classpath`" vimclojure.nailgun.NGServer 127.0.0.1' |
| 12:27 | _rata_ | jkkramer, ok |
| 12:28 | _rata_ | but normally no one will ask for just the first element... they already have that element |
| 12:29 | jkkramer | _rata_: it applies to any node. with lazy-seq before cons, work is done for nodes subsequent to the one requested |
| 12:30 | _rata_ | that's weird... it should be lazier, but it's the other way around then? |
| 12:32 | jkkramer | basically it's lazy for the nodes that require work to find |
| 12:33 | jkkramer | if there's a better way to do arbitrary-sized lazy graph traversal pre/post/bf, i'm very interested to know |
| 12:35 | jkkramer | lazy-walk from clojure.contrib.graph, which uses concat, dies on 100,000+ node graphs |
| 12:35 | _rata_ | I've tried it and you're completely right... putting lazy-seq before cons realizes always one more than needed |
| 14:00 | fliebel | I'm reading Joy of Clojure, and in some of the examples some collections from java.util are used instead of clojure.lang. Why is this and what are the differences? |
| 14:00 | d0m_ | fliebel: The goal is to be able to use both depending of when you need them |
| 14:01 | nishant | test message |
| 14:02 | fliebel | d0m_: I see… But what are the differences? Why might you prefer one over the other? |
| 14:03 | d0m_ | Well suppose you need to call a method on an existing Java object, but what you have available right now is a clojure list |
| 14:03 | d0m_ | You can call directly the java method with the clojure list.. without conversion |
| 14:04 | nishant | hey everyone, I'm new to clojure, I've a question about java interop. I am trying to create an object of a java class using the (new Class args) form, but I get an InvocationTargetException, even after fully qualifying the name of the class, any ideas? I also verified that the constructor is visible using the show function available in repl-utils. Please help! |
| 14:05 | d0m_ | fliebel: The list in clojure and in java are different implementations, even if they share some interfaces. So, if you're coding only in clojure, you can use only the clojure one if you like.. but then, if you have to use some java methods, it's nice to be able to convert java list to clojure list. |
| 14:06 | fliebel | Right :) |
| 14:06 | d0m_ | so because of the interface they share, you can use java implementation of list in your high level function in clojure |
| 14:06 | d0m_ | that's awesome :) |
| 14:07 | hiredman | ping? |
| 14:07 | clojurebot | PONG! |
| 14:10 | raek | nishant: can you paste the full stack trace somewhere? |
| 14:11 | raek | also, which class do you try to instanciate |
| 14:11 | nishant | @raek should I paste it here? |
| 14:12 | nishant | @raek it's a class that I wrote and I'm importing it through lein |
| 14:12 | raek | nishant: put it in gist.github.com and paste the link here |
| 14:12 | raek | nishant: you can check whether clojure can find the class by just trying to evaluate the class name |
| 14:12 | raek | ,java.util.ArrayList |
| 14:12 | clojurebot | java.util.ArrayList |
| 14:13 | nishant | yeah it can find the class |
| 14:13 | raek | ,java.util.Something |
| 14:13 | clojurebot | java.lang.ClassNotFoundException: java.util.Something |
| 14:13 | raek | great |
| 14:13 | nishant | okay here's the stack trace git://gist.github.com/626696.git |
| 14:14 | raek | ok, I tried http://gist.github.com/626696 |
| 14:14 | raek | (you pasted the git url) |
| 14:14 | nishant | oops |
| 14:14 | raek | hrm, looks like it can't figure out the constructor in some way |
| 14:15 | raek | ,(java.util.ArrayList.) |
| 14:15 | clojurebot | #<ArrayList []> |
| 14:15 | raek | ,(java.util.ArrayList. "foo" "bar") |
| 14:15 | clojurebot | java.lang.IllegalArgumentException: No matching ctor found for class java.util.ArrayList |
| 14:15 | raek | hrm, but it's not that exception.. |
| 14:16 | raek | nishant: if you press 1 in the exception buffer (goes to the cause) what do you get? |
| 14:16 | raek | my current theory is that the constructor throws an exception |
| 14:16 | nishant | I get No message [Thrown class.java.NullPointerException] |
| 14:17 | nishant | umm, let me try to see if I can use the constructor in Java |
| 14:17 | raek | nishant: does the class have multiple constructors that take the same number of arguments |
| 14:17 | raek | ? |
| 14:17 | nishant | @raek yeah the same number, but different types |
| 14:18 | raek | what types? |
| 14:19 | nishant | well there are two that take 1 argument, one of them takes a string, and the other one takes a JSON object (it's a java JSON implementation) |
| 14:19 | _rata_ | why can't I use ^ instead of (meta ...) in a place that meta has no problems? like in ^(:a b) |
| 14:19 | _rata_ | isn't ^ just a reader macro? |
| 14:20 | raek | _rata_: ^ as a shortcut for 'meta' is deprecated |
| 14:20 | raek | it worked up to 1.1 |
| 14:20 | _rata_ | raek, really?? |
| 14:20 | _rata_ | and what's ^ for now? |
| 14:20 | raek | in 1.2 ^ is the new #^ |
| 14:20 | raek | so, use the more verbose (meta ...) for getting the metadata |
| 14:21 | raek | and since 1.2, you can use ^ to attach metadata and type hints |
| 14:21 | _rata_ | mmmm... I don't get it yet |
| 14:21 | raek | ,(meta ^{:a 1} :foo) |
| 14:21 | clojurebot | Metadata can only be applied to IMetas |
| 14:22 | _rata_ | is there no shortcut for (meta ...) then? |
| 14:22 | raek | _rata_: not anymore... |
| 14:22 | _rata_ | :( |
| 14:22 | raek | attaching meta is probably much more common |
| 14:22 | nishant | @raek the ctor works from Java |
| 14:23 | raek | nishant: can you post the stack trace of the cause? |
| 14:23 | _rata_ | than retrieving it?? how can that be? everytime you attach metadata there will be one or more times you get it |
| 14:24 | nishant | @raek http://gist.github.com/626720 |
| 14:25 | raek | _rata_: a very common usage is type hints for the compiler |
| 14:25 | raek | which only the compiler looks at |
| 14:26 | raek | _rata_: anyway, ^ (or #^ in 1.1) only works for literals |
| 14:26 | raek | if you have some data *in* your program that you want to attach metadata to, you must use with-meta |
| 14:26 | _rata_ | mmmmm... so metadata isn't used that much.... that's a pity |
| 14:27 | _rata_ | yeah, I'm using with-meta |
| 14:27 | _rata_ | but the (meta ...) thing is annoying... with ^ the code would be much clearer |
| 14:27 | raek | when interfacing with clojure.core, you more often declare it than use it yes... |
| 14:28 | raek | ,(meta (with-meta [1 2 3] {:a 1})) |
| 14:28 | clojurebot | {:a 1} |
| 14:28 | _rata_ | the old shortcut could have been replaced by another one |
| 14:30 | _rata_ | and one that could be used everywhere, not just with literals |
| 14:31 | raek | meta is the "opposite" of with-meta |
| 14:31 | raek | nishant: is com.complabs.Annotators.EntityAnnotator the class you try to make an instance of? |
| 14:31 | nishant | yeah |
| 14:32 | _rata_ | so (:changed? (meta (:volume c))) could be written as (:changed? &(:volume c)) or something similar... the later is much more readable I think, no boilerplate |
| 14:35 | nishant | ping |
| 14:35 | KirinDave | Okay, something that's been bugging me... |
| 14:36 | KirinDave | Due ot profound mental deficiency, I don't know how to (require ...) a single namespace with an as without nesting. Is it possible? |
| 14:36 | KirinDave | I want to say (require '([clothesline.service :as service])) |
| 14:36 | KirinDave | Obviously that doesn't work. |
| 14:36 | KirinDave | and I know I could say (require '([clothesline [service :as service]])) |
| 14:37 | raek | nishant: is com.complabs.Annotators.EntityAnnotator the class you try to make an instance of? |
| 14:37 | nishant | @raek yes |
| 14:37 | raek | KirinDave: (require '[clothesline.service :as service]) |
| 14:38 | KirinDave | raek: Oh weird. |
| 14:38 | raek | the extra parens introduce a "prefix list" |
| 14:38 | KirinDave | raek: I thought require just wanted seqs. |
| 14:38 | KirinDave | But I guess lists vs vectors actually matter? |
| 14:38 | raek | KirinDave: it is recommended to use vectors and lists as they are used at clojure.org/libs |
| 14:39 | raek | other variants might work, but those are not documented |
| 14:39 | raek | and could be an implementation detail |
| 14:39 | raek | the general syntax is: |
| 14:39 | raek | foo.a |
| 14:39 | raek | [foo.a ... options ...] |
| 14:40 | raek | foo.a foo.b foo.c --> (foo a b c) |
| 14:40 | raek | or combinded: |
| 14:40 | KirinDave | raek: Thanks. I didn't realize the type was significant. |
| 14:40 | raek | [foo.a ..opts..] [foo.b ..opts..] [foo.c ..opts..] --> (foo [a ..opts..] [b ..opts..] [c ..opts..]) |
| 14:40 | KirinDave | raek: (btw notice I was saying (require ...) not (:require ...) |
| 14:41 | KirinDave | raek: I write the way recommended by libs in ns statements because it looks good and some things parse it |
| 14:41 | KirinDave | But it felt strange to do it in an actual require statement. I should get over it. |
| 14:41 | raek | the only difference between require and :require in a ns, is that the former requires you to quote the form |
| 14:41 | raek | (foo) is actually the degenerate case of the prefix list |
| 14:41 | raek | meaning, require *nothing* with the prefix foo |
| 14:42 | raek | how ever, a vector in that position simply means "no options" |
| 14:42 | nishant | raek: Yes I am trying to instantiate the EntityAnnotator class |
| 14:43 | raek | I think that is about the only case where vectors and lists are treated differently in the current implementation |
| 14:43 | raek | nishant: what do you pass to the constructor? |
| 14:43 | jarpiain | nishant: do you use the internal class name com.complabs.Annotators$EntityAnnotator ? |
| 14:43 | raek | is there any docs for the clas online? |
| 14:43 | nishant | raek: a string |
| 14:44 | nishant | raek: no there are no docs |
| 14:44 | raek | what jarpiain said looks interesting |
| 14:44 | nishant | raek: the constructor I'm trying to invoke takes a string, I tried creating an object through java code using the same ctor, and it works |
| 14:45 | nishant | jarplain: no I haven't tried that |
| 14:45 | nishant | :jarplain I get a ClassNotFound when I try that |
| 14:46 | raek | I think I am out of ideas... |
| 14:47 | raek | but maybe one could type hint the param |
| 14:47 | raek | (fn [^String s] (com.complabs.Annotators$EntityAnnotator. s)) |
| 14:47 | raek | nishant: have you tried passing a literal string or something? |
| 14:48 | raek | what value does the calling code pass? |
| 14:50 | nishant | I am getting a slightly different behavior when I pass a literal string (the string is supposed to be a file path) |
| 14:50 | raek | the same exception? |
| 14:51 | nishant | the same exception, but when I try to debug the cause I get a filenotfound exception |
| 14:52 | raek | nishant: can you double-check that the code you used previously used to generate the string doesn't give nil? |
| 14:53 | nishant | raek : I've hardcoded the string for testing |
| 14:55 | raek | so there is a difference whether the string is a literal or not? |
| 14:56 | raek | if so, could you try it with the type hint code I wrote before? |
| 14:57 | nishant | raek: yeah let me try that |
| 14:59 | nishant | raek: the behavior is same for literals and variables |
| 15:00 | raek | and if the file whose path is in the string exists, you get NullPointerException, otherwise FileNotFoundException? |
| 15:01 | nishant | raek: yes, it's weird |
| 15:01 | raek | should the file contain some data in a specific format? |
| 15:02 | nishant | raek: the file contains a json formatted string |
| 15:03 | raek | I think clojure finds the correct contsructor, since you get a FileNotFoundException |
| 15:04 | raek | it seems unlikely that it tries to open a file using a JSON object (or whatever the other type was) |
| 15:05 | nishant | yeah, I think it's calling the right ctor |
| 15:05 | LauJensen | /whois nishant |
| 15:06 | LauJensen | nishant: You're not the guy who used to write a ton of C# tutorials on codeproject are you? |
| 15:06 | nishant | LauJensen: no :) |
| 15:06 | LauJensen | ok :( |
| 15:07 | hiredman | ,(* 16 3) |
| 15:07 | clojurebot | 48 |
| 15:08 | nishant | :raek I just noticed that there might be multiple jars which contain this class, you think that could result in this behavior? |
| 15:09 | raek | possibly |
| 15:09 | raek | I don't know, but I guess that could be worth investigating |
| 15:09 | raek | it can cause weird things, for sure |
| 15:10 | nishant | okay let me try that, thanks for your help! |
| 15:18 | nishant | raek: the jar was old :) |
| 15:18 | nishant | sorry for wasting your time |
| 15:24 | raek | nishant: no worries :) |
| 15:25 | nishant | thanks |
| 15:49 | _rata_ | if I have a map from objects to their weights, how do I randomly choose one of those objects based on the given distribution? is make-distribution from clojure.contrib.probabilities.finite-distributions the best way? |
| 15:56 | _rata_ | why are there two math libs in clojure.contrib? |
| 16:15 | amalloy | _rata_: finite-distributions, as far as i can tell, defines a way to create pdfs, but not a way to select from them, so there must be some other lib that uses them |
| 16:16 | amalloy | if you |
| 16:16 | amalloy | re interested, http://rosettacode.org/wiki/Probabilistic_choice#Clojure is an implementation of what you're doing from scratch |
| 16:17 | _rata_ | can't I use the monad that make-distribution returns directly? (I don't know anything about monads... any reference to understand them would be appreciated :) ) |
| 16:17 | amalloy | i don't either :P |
| 16:18 | raek | _rata_: rhickey's ants.clj example contains the 'wrand' function, which seems to do something similat to what you are trying to obtain: http://raek.se/ants.clj |
| 16:21 | _rata_ | raek, oh thanks. that's something very similar to what I'm looking for |
| 16:22 | _rata_ | "=" for refs is the same as "identical?"? |
| 16:25 | amalloy | ,(let [[a b :as c] (repeatedly (atom 0))] (map (juxt = identical?) c)) |
| 16:25 | clojurebot | java.lang.RuntimeException: java.lang.ClassCastException: clojure.lang.Atom cannot be cast to clojure.lang.IFn |
| 16:25 | amalloy | ,(let [[a b :as c] (repeatedly #(atom 0))] (map (juxt = identical?) c)) |
| 16:25 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$identical-QMARK- |
| 16:25 | amalloy | bleh |
| 16:26 | amalloy | ,(let [[a b] (repeatedly #(atom 0))] ((juxt = identical?) a b)) |
| 16:26 | clojurebot | [false false] |
| 16:27 | _rata_ | ,(for [a (repeatedly 5 #(atom 0))] (map (juxt = identical?) a)) |
| 16:27 | clojurebot | java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Atom |
| 16:27 | amalloy | _rata_: looks like yes |
| 16:27 | _rata_ | ,(for [a (repeatedly 5 #(atom 0))] ((juxt = identical?) a)) |
| 16:27 | clojurebot | java.lang.IllegalArgumentException: Wrong number of args (1) passed to: core$identical-QMARK- |
| 16:28 | amalloy | _rata_: you can't possibly do it with just a for. only one a is in scope at a time |
| 16:28 | _rata_ | mmm ok |
| 16:29 | amalloy | but since 0 is identical to 0, and two refs to it are neither equal nor identical, it looks like equal and identical are the same for refs |
| 16:29 | _rata_ | but anybody knows if that result is an implementation detail or I can relay on that behaviour? |
| 16:30 | raek | _rata_: for clojure types, = means value equality for immutables and indentity equality for mutable things (atoms/refs/agents/vars, etcs) |
| 16:30 | _rata_ | ah ok :) |
| 16:30 | raek | ,(= [1 2 3] '(1 2 3)) |
| 16:30 | clojurebot | true |
| 16:30 | _rata_ | thank you amalloy and raek |
| 16:40 | ztellman | bmh: still have questions about penumbra? |
| 16:41 | BufferUnderpants | Hi |
| 16:42 | BufferUnderpants | I'm trying to use the ZK web framework from within Clojure and I'm having trouble with a proxy class. |
| 16:43 | nishant | does repl-utils/source not work on functions I define in the user namespace? |
| 16:44 | BufferUnderpants | The method I'm invoking receives an instance of an instance of an interface, very much like Swing. |
| 16:44 | raek | nishant: no, but their definitions needs to be loaded through a require |
| 16:44 | raek | or C-c C-k in emacs |
| 16:45 | raek | if you load then in the repl or with C-x C-e or C-M-x file and line metadata is not stored for them |
| 16:45 | amalloy | oh neat, raek, i didn't realize source worked for C-c C-k. i just knew it didn't work if you put them into the repl so i never tried |
| 16:47 | nishant | raek:thanks |
| 16:48 | colinsteele | hey folks how do I turn a string into a java.io.Reader or a java.io.InputStream?? |
| 16:48 | colinsteele | <---- java noob, pardon my cluelessness :) |
| 16:50 | lpetit | ,(java.io.StringReader. "a string") |
| 16:50 | clojurebot | #<StringReader java.io.StringReader@6d9e14> |
| 16:50 | lpetit | colinstee: ^^ |
| 16:50 | colinsteele | ahhhh |
| 16:50 | colinsteele | voila, thanks |
| 17:07 | hsuh | hello folks... i wrote this (http://pastie.org/1221883) and thought it was too slow, what am i doing wrong ? |
| 17:09 | Chousuke | hsuh: 7ms per database connection & query doesn't sound too bad. |
| 17:09 | Chousuke | well, 8ms |
| 17:10 | Chousuke | hsuh: it opens a new connection to the database for every query, you hopefully won't be doing that in production code. |
| 17:11 | arkh | how do I :use namespaces from multiple files (of my own making)? |
| 17:11 | hsuh | Chousuke: not anymore... so what should i be doing ? (RTFM is a valid answer) |
| 17:12 | Chousuke | hsuh: I think you'll want to open a connection and use that for all your queries. (You'll have to read the docs to find out how, though) |
| 17:13 | raek | arkh: other than (ns my.ns.one (:use the-ns)) (ns my.ns.two (:use the-ns)) etc, for each file that wants to use it? |
| 17:14 | Chousuke | it's a good habit to avoid :use though |
| 17:14 | arete | hsuh: you'll want to use a connection pooling ds and the :ds option for clojure.contrib.sql |
| 17:14 | Chousuke | at least without :only |
| 17:14 | arete | http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/ds/PGConnectionPoolDataSource.html |
| 17:14 | arkh | raek: how do namespaces work with the class path? i.e., how does clojure know where to find namespaces in the files I make / want to load |
| 17:14 | raek | (I interpreted your question as that you wanted to use "the-ns" from "my.ns.one" and "my.ns.to" |
| 17:14 | hsuh | arete: tks |
| 17:15 | raek | arkh: yes. (ns foo.bar.some-thing ...) corresponds to foo/bar/some_thing.clj |
| 17:15 | arkh | raek: cool - that's what I didn't know. Thank you |
| 17:15 | raek | where the foo/ directory should be in a directory on the class path (presumably src/) |
| 17:15 | arete | hsuh: actually there's an even better example here: http://en.wikibooks.org/wiki/Clojure_Programming/Examples/JDBC_Examples |
| 17:15 | dpritchett | how long has leiningen had the "lein classpath" task anyway? |
| 17:15 | raek | note that hyphens in namespace names correspond to underscores in file names |
| 17:16 | arkh | k |
| 17:16 | hsuh | arete: otoh the datasource - postgresql example there says "Note that this is not recommended for production. Use c3p0 or similar instead." |
| 17:17 | bmh | ztellman: missed you message an hour back. Can pixel shaders be written in java/clojure or am I tied into using C/C++? |
| 17:17 | ztellman | bmh: pixel shaders have to be written in GLSL, which is a C-99 derivative |
| 17:18 | arete | yeah dunno why it says that, perhaps there are/were issues with the connection pooling |
| 17:18 | ztellman | but there's a Clojure DSL that offers some of the same functionality |
| 17:18 | ztellman | under the covers, it just translates into GLSL |
| 17:18 | bmh | ztellman: hrm. Do you know a good simplex noise/fBM implementation? |
| 17:19 | bmh | I'm playing around with some algorithmic terrain stuff and figured I could try generating everything in the pixel shader |
| 17:19 | ztellman | bmh: you were looking at the marble program, right? |
| 17:19 | ztellman | that uses perlin nosie |
| 17:19 | bmh | ztellman: I saw. Perlin fBM. Perlin has dimensionality issues, though |
| 17:19 | hsuh | arete: there is also http://github.com/briancarper/postgres-pool |
| 17:20 | ztellman | bmh: well, it's generally difficult to use pre-existing GLSL code |
| 17:21 | ztellman | perlin noise is pretty friendly to the hardware |
| 17:21 | ztellman | I'm not sure about simplex noise, but it shouldn't be too hard to create your own version |
| 17:22 | bmh | ztellman: Have you read any of the papers analyzing Perlin? It actually has some terrible characteristics |
| 17:23 | ztellman | bmh: I haven't, but I'm really not an expert |
| 17:23 | bmh | For example, the hash function that Perlin used is highly correlated |
| 17:24 | bmh | If I was an expert I wouldn't be lurking on irc picking the brains of people more in the know than I ;-) |
| 17:24 | ztellman | ha, well I don't think the difference between terrains generated by perlin noise and simplex noise are all that obvious |
| 17:25 | ztellman | but if you want to pursue another fractal generator and need any pointers on using Penumbra, I'm available |
| 17:26 | bmh | Thanks. Have you ever looked at turbulence? It works by perturbing you x,y,z coordinates with... wait for it... coherent noise |
| 17:26 | edoloughlin | Hi, I'm trying to remove nil values from a map (I'm new to Clojure). I'm using |
| 17:26 | edoloughlin | (def record {:a 1 :b 2 :c nil}) |
| 17:26 | edoloughlin | (merge (for [[k v] record :when (not (nil? v))] {k v}) |
| 17:26 | edoloughlin | but this gives: |
| 17:26 | edoloughlin | ({:a 1} {:b 2}) |
| 17:26 | edoloughlin | Whereas I would like: |
| 17:26 | ztellman | bmh: I haven't but that seems very GPU friendly |
| 17:26 | edoloughlin | {:a 1, :b 2} |
| 17:27 | bmh | edoloughlin: why don't you use remove |
| 17:27 | edoloughlin | Wow. Thanks. Will look it up! |
| 17:27 | bmh | (remove (fn [k v] (nil? v)) collection) |
| 17:27 | bmh | http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/remove |
| 17:27 | edoloughlin | Thanks. |
| 17:28 | bmh | rich & co. did a great job of getting all the functional stuff right. |
| 17:28 | dpritchett | what's the latest in clojure on AppEngine hand-holding libs? |
| 17:28 | raek | ,(apply merge (for [[k v] {:a 1, :b 2, :c nil} :when (not (nil? v))] {k v})) |
| 17:28 | clojurebot | {:b 2, :a 1} |
| 17:28 | raek | (into {} (for [[k v] {:a 1, :b 2, :c nil} :when (not (nil? v))] [k v])) |
| 17:29 | dnolen | ,(into {} (remove (fn [[k v]] (nil? v)) {:a 1 :b 2 :c nil})) |
| 17:29 | clojurebot | {:a 1, :b 2} |
| 17:29 | bmh | ztellman: Is there any reading you could suggest for GPU programming? I'm a bioinformatician by trade, so graphics is a big, magical world to me |
| 17:29 | ztellman | bmh: I haven't found a good conceptual book yet |
| 17:30 | ztellman | bmh: but the orange GLSL guide isn't all that bad as a reference |
| 17:30 | edoloughlin | Thanks everyone. |
| 17:30 | ordnungswidrig | is there something like zip for multiple seqs? [[1 2 3] [:a :b :c] ["!" "§" "$"]] -> [[1 :a "!"] [2 :b "§"] [3 :c "$"]] |
| 17:31 | raek | ,(map vector [1 2 3] [:a :b :c] ["!" "§" "$"]) |
| 17:31 | clojurebot | ([1 :a "!"] [2 :b "§"] [3 :c "$"]) |
| 17:32 | raek | map hase the useful property of "taking one thing from each seq" |
| 17:32 | bmh | raek: I had an interview earlier this week. I solved one of the problems they gave me with a few applications of map, filter, and reduce. |
| 17:33 | bmh | We spent the remainder of the interview discussing the finer points of roguelikes... |
| 17:34 | ordnungswidrig | ah, cool, I didn't know this one. |
| 17:34 | ordnungswidrig | ,(doc map) |
| 17:34 | clojurebot | "([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]); Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments." |
| 17:35 | ordnungswidrig | ,(map vector [1 2] [:a :b :c]) |
| 17:35 | clojurebot | ([1 :a] [2 :b]) |
| 17:36 | hsuh | arete: 10x improvement with postgres-pool |
| 17:37 | ztellman | bmh: I'm heading out, but hit me up on the penumbra mailing list with any questions you have |
| 17:38 | bmh | ztellman: thanks. I'll subscribe. |
| 17:39 | arete | hsuh: sounds speedy |
| 17:44 | _rata_ | has anybody problems with the debugger of swank-clojure and clojure 1.3? |
| 17:45 | lancepantz | so i was just playing around with tuning my jvm a little |
| 17:45 | lancepantz | i took 100m off of my Xmx, which dropped my virtual memory usage by 160m |
| 17:46 | lancepantz | anyone have any ideas where the extra 60 is coming from? |
| 17:50 | amalloy | lancepantz: what was your Xmx to begin with? |
| 17:51 | lancepantz | took it from 500 down to 400 in this case |
| 17:52 | amalloy | my guess, at any rate, would be some magic mumbo-jumbo to do with powers of two |
| 17:52 | _rata_ | has anybody experienced problems with the debugger of swank-clojure and clojure 1.3? |
| 17:58 | nishant | does clojure have something like for-each? |
| 17:58 | nishant | bold question |
| 17:59 | AWizzArd | map, doseq, for |
| 17:59 | AWizzArd | ,(map inc [10 20 30]) |
| 17:59 | clojurebot | (11 21 31) |
| 17:59 | nishant | okay, I was looking for something that only side effects |
| 17:59 | AWizzArd | ,(doseq [n [10 20]] (println n)) |
| 17:59 | clojurebot | 10 20 |
| 18:01 | kmc | heh, clojurebot captures output? |
| 18:05 | nishant | thanks! |
| 18:08 | gfrlog | is there a faster way to create a map from a list of pairs aside from (apply hash-map (reduce concat pairs))? |
| 18:08 | dnolen | gfrlog: into is your friend |
| 18:09 | dnolen | ,(into {} [[1 2] [3 4]]) |
| 18:09 | clojurebot | {1 2, 3 4} |
| 18:09 | gfrlog | ,(into {} [[1 2] [3 4]]) |
| 18:09 | clojurebot | {1 2, 3 4} |
| 18:09 | gfrlog | awesome, thanks |
| 18:11 | kmc | ,(doc into) |
| 18:11 | clojurebot | "([to from]); Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." |
| 18:11 | kmc | ,(into [1 2] [3 4]) |
| 18:11 | clojurebot | [1 2 3 4] |
| 18:12 | kmc | ,(conj [1 2] 3) |
| 18:12 | clojurebot | [1 2 3] |
| 18:13 | gfrlog | (into #{} {:a 2 :c 5}) |
| 18:13 | gfrlog | ,(into #{} {:a 2 :c 5}) |
| 18:13 | clojurebot | #{[:a 2] [:c 5]} |
| 18:19 | gfrlog | ,(defrecord Tom [jill tim]) |
| 18:19 | clojurebot | DENIED |
| 18:23 | gfrlog | hmm. I do a (defrecord Graph [order edges]) in a certain namespace, (use) that namespace from the repl, but then Graph doesn't resolve |
| 18:25 | KirinDave | So |
| 18:25 | Chousuke | gfrlog: you need to import records |
| 18:25 | Chousuke | gfrlog: they become classes |
| 18:25 | gfrlog | oooh |
| 18:26 | gfrlog | very good |
| 18:26 | KirinDave | It's not possible to use the extend+merge technique to simulate inheritance with (reify ...), unless you want to use a macro and promise compile-time support. Right? |
| 18:27 | KirinDave | With (extend ...) you can merge two maps together |
| 18:28 | KirinDave | But extend requires a specific type to extend. |
| 18:28 | KirinDave | If you want anonymous types to fit a protocol, you have to have the entire proposition be static, right? |
| 18:28 | KirinDave | (unless, of course, you want to eval a form) |
| 18:28 | KirinDave | There's no way to provide default/inherited behavior to reified objects. |
| 18:29 | Chousuke | I suppose you could use reflection but it'd be fragile |
| 18:30 | KirinDave | Chousuke: I mean, a macro is easy enough to turn {:name (fn...) ...} into a '(name (fn...)) |
| 18:30 | KirinDave | Chousuke: But... |
| 18:30 | KirinDave | That's purely static. |
| 18:37 | AWizzArd | How can I declare a deftype field as :unsynchronized-mutable and ^int at the same time? |
| 18:43 | _rata_ | I don't get what make-distribution does |
| 19:03 | gfrlog | does (first #{2 3 4}) require the axiom of choice? |
| 19:04 | amalloy | AWizzArd: i think it looks something like this: (deftype a [^{:volatile-mutable true :tag int} h]) |
| 19:05 | amalloy | that creates for me an A class, with a 1-arg int constructor. i'm not sure if it's mutable since i don't do deftypes very often, but it seems like if the tag works the mutability probly does too |
| 19:07 | AWizzArd | I will try that, thanks for the idea |
| 19:15 | gfrlog | ,#{4 4 5} |
| 19:15 | clojurebot | Duplicate key: 4 |
| 19:19 | jashmenn | hey, im wondering if someone can help me figure out a macro problem: https://gist.github.com/fdd8b7b902b1ab8170f7 |
| 19:20 | jashmenn | i realize that macros don't evaluate their operands |
| 19:20 | jashmenn | but i'm wondering how i can evaluate them if i want to |
| 19:21 | gfrlog | jashmenn: I think you can only set them up to be evaluated |
| 19:22 | gfrlog | it looks like you're trying to call the function twice? |
| 19:22 | jashmenn | i want to use the var x as an argument to defining the output of the macro |
| 19:22 | jweiss | anyone know how to switch slime from clojure back to lisp? when i run slime it tries to load clojure |
| 19:23 | jweiss | or better yet, be able run either one :) |
| 19:23 | technomancy | jweiss: getting rid of swank-clojure should help |
| 19:23 | gfrlog | jashmenn: could you make foo a function? maybe one that calls another macro? |
| 19:24 | technomancy | I don't use CL myself though, I could use some help making swank more Cl-frinedly |
| 19:24 | jweiss | technomancy: so once swank-clojure is installed, it assumes you're only using clojure as inferior-lisp? |
| 19:24 | dnolen | jashmeen: there are two hidden params handed to macros &env and &form |
| 19:24 | jweiss | i don't know CL much myself. i learned a bit briefly before finding clojure. |
| 19:24 | technomancy | jweiss: maybe? getting rid of swank-clojure.el is a good idea even if you don't use CL. it's just got some heinous hacks that were necessary when lein didn't exist, but don't make sense any more. |
| 19:25 | technomancy | it just complicates things |
| 19:25 | jashmenn | dnolen: this sounds interesting. let me look that up |
| 19:25 | jweiss | technomancy: so it is not necessary to run lein swank, and then slime-connect? |
| 19:25 | jweiss | it meaning swank-clojure.el |
| 19:25 | technomancy | correct |
| 19:26 | jweiss | excellent, that's most likely the problem then, i set up clojure dev here before lein came along (or maybe just before i discovered it) |
| 19:27 | jweiss | technomancy: i have swank-clojure and clojure-mode elpa packages - do i need those? |
| 19:28 | technomancy | just clojure-mode and slime-repl |
| 19:28 | jashmenn | dnolen: okay, so i've got &env and it shows the LocalBinding. now im not exactly sure how to safely get the value of `g` out of it |
| 19:29 | dnolen | jashmenn: ah sorry you led you astray, &env is just so you can the surrounding context from w/in a macro |
| 19:29 | jashmenn | dnolen: ah okay |
| 19:30 | dnolen | jashmenn: the only way to get at the value of something is eval, but what exactly are you trying to do? |
| 19:31 | jashmenn | dnolen: i want to pass an argument into a macro and use the value of it (unquoted) to help build the sexp within the macro |
| 19:33 | jashmenn | but, like gfrlog was saying, i think i need to just set it up to be evaluated, not evaluate it early |
| 19:35 | gfrlog | jashmenn: can you use eval? |
| 19:35 | dnolen | jashmenn: curious as to the end goal, why do you need the actual value of a literal to influence the macro expansion? |
| 19:36 | dnolen | jashmenn: sometimes it is indeed useful to eval in a macro, but usually unnecessary. |
| 19:36 | gfrlog | I've never done it |
| 19:37 | dnolen | I've only needed once, because I was using the contents of files on disk to generate code. |
| 19:41 | amalloy | jashmenn: why is the value being passed in a variable instead of a literal? (not just asking to tell you you're wrong; i think you can probably make this happen) |
| 19:49 | rplevy | using clojure contrib 1.1.0, I am trying out contrib.condition. it doesn't do quite what I would expect. it certainly responds to the raised condition as specified but the exception goes uncaught delivering the message in tomcat. what I need it to do and what I think the semantics of it is, is for handler-case to be like try and for handle to be like catch in the sense that I can do something with the result. Am I doing it wrong or was it jus |
| 19:50 | technomancy | rplevy: support for catching regular exceptions in handler-case just got committed last week IIRC |
| 19:50 | technomancy | might be able to backport it to 1.1, but it might be tricky; easier to just upgrade to 1.3 =) |
| 19:53 | jashmenn | dnolen: well when i try to eval it says "can't eval a local" |
| 19:53 | dnolen | jashmenn: heh, yeah I forgot about that. |
| 19:53 | jashmenn | amalloy: right, if i pass in the value as a literal it works fine |
| 19:53 | jashmenn | but, obviously this is just extracted from a much larger macro |
| 19:53 | jashmenn | and `x` in this case "has to" be a variable |
| 19:54 | jashmenn | i don't mind passing it in as a literal in the `let` if you have advice on the best way to do that |
| 19:55 | amalloy | is this a macro embedded within another macro? |
| 19:55 | amalloy | or called from another, whatever |
| 19:55 | jashmenn | amalloy: yes |
| 19:55 | amalloy | okay. usually you don't need to do that |
| 19:56 | amalloy | write your inner macro as a *function*, not a macro |
| 19:56 | jashmenn | but what if i need both inner and outer to do list destructuring like ~@body ? |
| 19:57 | amalloy | eg (defn foo [x] `(prn ~x)) |
| 19:57 | amalloy | backtick is legal in functions too; the only special thing about macros is that their arguments aren't evaluated |
| 19:57 | jashmenn | i didnt think that was possible with just a plain defn but i guess im wrong |
| 19:57 | jashmenn | hmmm |
| 19:58 | jashmenn | ah ha |
| 19:58 | jashmenn | okay |
| 19:58 | jashmenn | thanks |
| 19:58 | amalloy | ,(let [x (fn [] `(prn 1))] (x)) |
| 19:58 | clojurebot | (clojure.core/prn 1) |
| 19:59 | jashmenn | okay, this is very helpful. thanks amalloy (and everyone else) |
| 19:59 | amalloy | welcome jashmenn |
| 19:59 | amalloy | this is a macro "trick" that is widely applicable: don't use macros :) |
| 20:06 | tomoj | haha |
| 20:08 | kmc | i see a few libraries for continuations in Clojure, implemented by performing a continuation-passing-style transform |
| 20:08 | kmc | but it seems to me that CPS is fatally limited without TCO |
| 20:08 | kmc | is this a problem for using continuations in Clojure, or do they manage to insert trampolines cleverly to get TCO? |
| 20:11 | tomoj | kmc: http://intensivesystems.net/tutorials/cont_m.html |
| 20:12 | tomoj | does it look like that approach is limited by lack of TCO? |
| 20:15 | kmc | yes |
| 20:15 | kmc | most of those functions end in a tail call |
| 20:15 | kmc | in CPS you replace "return to parent, which does something else" with "tail-call a continuation" |
| 20:15 | kmc | this is going to use more stack, unless you have TCO |
| 20:16 | kmc | however i bet that some clever CPS macros for Clojure could replace calls with returns and use trampoline |
| 20:16 | kmc | which is what i was asking about |
| 20:17 | amalloy | You know we have trampoline, right? |
| 20:18 | kmc | yeah i mentioned it twice |
| 20:18 | amalloy | Haha, just checking that you didn't mean to implement it first |
| 20:19 | tomoj | would you just have to add a trampoline at every tail call site? |
| 20:19 | amalloy | On my mobile atm, apologies if I miss some context |
| 20:20 | kmc | tomoj, i'm not really sure |
| 20:20 | tomoj | I don't understand CPS yet :( |
| 20:20 | kmc | other languages implemented on systems without TCO sometimes wrap the whole program in one trampoline |
| 20:20 | kmc | and my understanding is that Clojure could have done this to get transparent TCO |
| 20:20 | kmc | but it would slow down everything |
| 20:20 | tomoj | ah, right |
| 20:22 | kmc | tomoj, in CPS every function takes an extra argument (the continuation) and, instead of returning, calls that |
| 20:22 | kmc | so (fn [x] (+ x 2)) becomes (fn [x k] (k (+ x 2))) |
| 20:22 | kmc | except that in a full CPS transform, we'd CPS-transform (+) too, and eliminate every non-tail call |
| 20:23 | kmc | (fn [x k] (+ x 2 k)) |
| 20:24 | kmc | and (fn [x] (* (+ x 2) 3)) becomes (fn [x k] (+ x 2 #(* % 3 k))) or some such |
| 20:27 | kmc | and if you carry this to its conclusion, your big nested expressions get unfolded to a linear sequence of small steps |
| 20:27 | kmc | which is why CPS transform is useful as a stage in a compiler |
| 20:28 | kmc | and indeed is close to the SSA form used in lots of compilers for languages not traditionally called "functional" |
| 20:29 | tomoj | kmc: actually, doesn't the article there explain it? |
| 20:29 | tomoj | search for "But why?" |
| 20:29 | kmc | yeah |
| 20:29 | kmc | that's kind of orthogonal to what i said above |
| 20:30 | tomoj | oh |
| 20:30 | kmc | that's answering why you as the programmer should care about CPS |
| 20:30 | kmc | what extra power it gives you |
| 20:30 | kmc | not why a compiler should use it internally, or mechanically how it's carried out |
| 20:31 | tomoj | well, doesn't that article show a way to do the trampolining to get around lack of TCO? |
| 20:31 | kmc | yeah i see it now |
| 20:32 | tomoj | by placing bounces you can control which parts of the chain avoid function call overhead at the expense of stack space, I guess? |
| 20:32 | kmc | yeah |
| 20:33 | kmc | and if you baked the bounce into your monadic bind, you'd have full TCO at the expense of slower function calls |
| 20:34 | tomoj | unrelatedly, have you seen aleph? |
| 20:34 | kmc | no |
| 20:34 | tomoj | http://github.com/ztellman/aleph/wiki |
| 20:34 | tomoj | bells are going off in my head but I'm too stupid to tell whether it's a false alarm |
| 20:35 | kmc | ding |
| 20:44 | kmc | so how expensive are threads in Clojure? |
| 20:45 | kmc | are they 1:1 with Java threads or something more lightweight? |
| 21:20 | amalloy | i don't remember if it was tomoj or kmc who linked the intensivesystems monad tutorial, but thanks. so far i'm finding it a lot more understandable than the others i've looked at |
| 21:21 | amalloy | anyway, have to run, but just wanted to mention that |
| 21:30 | gfrlog | does anyone else think that c.c.sql could use an ensure-connection macro? |
| 21:30 | lancepantz | cc.sql could use alot of things |
| 21:31 | gfrlog | ,(defn alot-of-things [& args]) |
| 21:31 | clojurebot | DENIED |
| 21:31 | ninjudd | like a way to load huge datasets without bringing the whole thing into memory!!! |
| 21:31 | ninjudd | ;) |
| 21:33 | lancepantz | gfrlog: there is a clj-sql project that addresses alot of the shortcoming, but i don't actually use it |
| 21:34 | lancepantz | i usually end up calling the jdbc methods directly |
| 21:36 | gfrlog | lancepantz: clj-sql doesn't have it -- are you suggesting that project might be easier to contribute to than cc? |
| 21:36 | lancepantz | gfrlog: yep |
| 23:57 | yayitswei | any pointers for setting up log4j with clojure.contrib.logging? just want a simple way to append-to-file |