#clojure logs

2010-10-30

00:17itistodayhow does package.el work with respect to updates?
00:17itistodaysave a new version of clojure-mode is released, how does one get it?
00:34replacaUpper: if you're still there: I think you misunderstand what loop does in clojure. That form isn't actually looping at all.
00:36UpperI did other solution, but in clojure can't I force to exit of a loop?
00:37replacaso, if you simply want to pass over a seq, use doseq, like so:
00:37replaca,(doseq [i (range 11)] (print i))
00:37clojurebot012345678910
00:38replacabut if you want a conditional exit, use loop and recur, like this:
00:40replaca,(let [r (rangle 10000000] (loop [i (first r) r r] (when (< r 10) (print r) (recur (first (rest r)) (rest r))))
00:40clojurebotUnmatched delimiter: ]
00:40replaca,(let [r (range 10000000] (loop [i (first r) r r] (when (< r 10) (print r) (recur (first (rest r)) (rest r))))
00:40clojurebotUnmatched delimiter: ]
00:41replaca,(let [r (range 10000000)] (loop [i (first r) r r] (when (< r 10) (print r) (recur (first (rest r)) (rest r))))
00:41clojurebotEOF while reading
00:41replaca,(let [r (range 10000000)] (loop [i (first r) r r] (when (< r 10) (print r) (recur (first (rest r)) (rest r)))))
00:41clojurebotjava.lang.ClassCastException: clojure.lang.LazySeq cannot be cast to java.lang.Number
00:41replaca,(let [r (range 10000000)] (loop [i (first r) r r] (when (< i 10) (print i) (recur (first (rest r)) (rest r)))))
00:41clojurebot0123456789
00:41replacafinally!
00:42replacathe handling of r and i can be cleaner there, but you get the idea maybe
00:42replacaloop only goes around if you have recur in the tail position
00:43lrennyeah, my bad, i was just correcting the binding vector, didn't even thing about what he was trying to do.
00:43replacait's not loop in the sense of CL's loop macro. Clojure doesn't have that
00:43lrenns/thing/think/
00:43sexpbot<lrenn> yeah, my bad, i was just correcting the binding vector, didn't even think about what he was trying to do.
00:45replacabut a lot of times in clojure, we don't use loop to accomplish that at all, but rather first order functions (like some) on lazy sequences
00:45replacathen it's easy to consume (and therefore produce) only that part of the computation that you care about
00:55replacadirs
00:55replacaoops!
01:11Upperyeah, really
01:14ThothHey all, I have a question that seems like it ought to be an FAQ, but I have had no luck with it. I have a clojure-contrib.jar on my classpath, but (use 'clojure.contrib.str-utils) breaks with a FIleNotFoundException. I'm a clojure newbie, so I might be making any number of mistakes. Any idea what might be going on?
01:15ThothI'm on OSX, I tried installing clojure-contrib with ports and by building from the git repository
02:02samxbeginner question.. i'm trying to use pretty printing in my own namespace, but having trouble bringing the functions to my namespace: (ns test (:require clojure.pprint)) (pprint "test") -> Unable to resolve symbol: pprint... What am I doing wrong?
02:04replacasamx: I think you want :use instead of :require
02:04samxthat seemed to do it.. thanks :-)
02:05replacasamx: good idiom is (:use [clojure.pprint :only [pprint]] and then you don't get any other names
02:05replaca(oops, add a trailing paren there!)
02:05samxwhat is the :require actually do then?
02:06replacasamx: require make the namespace available to you. after that you can say (clojure.pprint/pprint foo) and it'll work
02:06replacasamx: a nice for is (:require [clojure.pprint :as pp])
02:07replacathen you can invoke (pp/pprint foo)
02:07replacasome folks prefer that to :use :only
02:08samxok.. that makes sense.. i'll play around with these a bit..
02:08replacasamx: have fun!
02:08samxthanks
02:16ubiiany suggestions on the best way to setup a clojure development environment on Mac OS X?
02:21replacaubii: I'm not a mac guy, but a simple thing to do would be to pull clojure & contrib 1.2 from here: http://clojure.org/downloads
02:22replacaubii: and then look at "getting started" and "REPL and main" on the clojure.org home page
02:22ubiireplaca: thx, ended up going the lein route
02:23replacaEven better!
02:23replacaubii: And that's working OK?
02:23ubiiso far
02:23samxi just downloaded the clojure.jar, and started with it.. and then i got intellij community edition, and installed the clojure plugin for it
02:24replacaone problem is that thare are *too* many ways to do it, each with its own quirks
02:41samxok.. next beginner question.. i'm trying to go through a list/vector/.. using loop and recur.. but instead seem to be creating an infinite loop.. what's wrong here: (loop [myseq (seq [1 2 3])] (if (nil? myseq) true (recur (rest myseq))))
02:47hoecksamx: myseq will be never nil because you call rest on it
02:47hoecksamx: use next instead
02:47hoeck,(rest [1])
02:47clojurebot()
02:47hoeck(nil? (rest [1]))
02:47hoeck,(nil? (rest [1]))
02:47clojurebotfalse
02:47samxoops.. thanks :-)
02:47hoeck,(nil? (next [1]))
02:47clojurebottrue
02:48hoecksamx: or test with empty?
02:48hoeck,(empty? (rest [1]))
02:48clojurebottrue
02:49hoeckwhich is cleaner for collections than nil, plus it works on all kinds of empty collectsion (empty? {}), (empty? []) ...
02:49magicduncanhi all, can anyone recommend the best place to start for streams in clojure?
02:49replacamagicduncan: what do you mean by streams?
02:51magicduncanI guess being able to define something that will produce stuff at unknown times from now into the future, that we can assign to something, filter, transform and create downstreams from
02:51replacamagicduncan: I think that's mostly covered by lazy-seqs in clojure
02:52replacabut you can also use something like fill-queue
02:53magicduncanyeah i reckon they would certainly feel like lazy-seq to work with, but would need to be...how shall I say.....long lived?
02:53replacain which sense
02:53replaca?
02:55replacado you mean they continue producing results forever, slowly? Or the previous results are persistent? Or something else?
02:55magicduncanlets say I could create a stream of clockticks. Done, it is streaming clockticks, in its own thread I think. Then I could come back later and define a stream of filtered clockticks based off of the original, on some arbitrary filtering basis. Done, it would then also be left running
02:55magicduncannot sure if Im making sense even to myself ;)
02:56replacado you want old ones to go away without being consumed when no one was interested?
02:56replacaif you just want the stream, you can just build a lazy seq out of futures
02:57magicduncanI guess Im looking to create some sort of interactive pipeline model. Hmm, Im not sure if old streams should disappear if there no one is listening. I think the definition for the stream should stick around in case anyone wanted such things in the future
02:57replacathough you eventually run out of memory ith that model :)
02:58replacas/ith/with/
02:58sexpbot<replaca> though you eventually run out of memory with that model :)
02:58magicduncanrun out of memory from the definitins or the actual events coming down the streams?
02:59replacawell, if you save the events for arbitrary consumers to consume at a later date
03:00magicduncanah, I see. No I think if you werent listening at the time then too bad for you, you missed the event
03:00replacafor ajaxy systems, i've done streamy things that drop events if you don't keep up
03:01replacaI mean, you can just have a thread banging an atom and consumers read from it
03:02replacabut then you have the problem if the consumers read too fast
03:02replacaso what I've done is have a tuple <serial, value, promise> in a ref.
03:03replacathe consumer keeps the serial as the cookie for the last thing it got
03:04replacaand then checks the ref: if the serial in the ref is newer than the cookie the consumer has, take the value other wise block on the promise.
03:04replacanew values update the ref with a new tuple, and fulfill the promise in the old one
03:05magicduncanhow bout this example. lets say I could define (stream priceticks stock-exchange) and then later come along and define (stream googleShareTicks priceTicks) filtering the original stream. Would probably tho still need to create something that consumed from googleShareTicks if the events werent going to be dropped
03:05replacathat way fast consumers get items as they become ready and slow ones simply miss
03:06replacait'd be pretty easy to chain them together
03:06replacaif you had a main firehose and then derivitive ones
03:06magicduncanIm not sure I understand how consumers would get away from you like that. In Java theres the notion of the blocking queue
03:07replacamagicduncan: right, the problem with a blocking queue is:
03:07replacaif 1 person reads from it, they take the data
03:08replacaif nobody ready from it, it slowly uses all your memory (or with LBQ blocks the producer)
03:08replacawhich is no problem is some situations and a disaster in others
03:08magicduncanright, ok this is more a pub-sub, I see the problem
03:08replacayeah, that's where I'm coming from
03:09magicduncanreally need the stream (publisher) to not have to know if anyone is listening or not, but needs to know if it is to determine whether to hold on to the event at all
03:09replacaI haven't done the thing of defining channels in terms of other channels, but I don't think it would be too hard to build that
03:10replacaright, tht's why the intermediate mechanism is nice
03:10replacait handles both waiters and "idle" cases
03:11replacaif you want, I presented some code in my talk at the conj. The slides are here: flow-preso.heroku.com
03:11replacalook at slide 37 and following
03:12magicduncanhey so, if Im understanding your approach right, each consumer is polling for changes, keeping track of the last one it received to differentiate anything new?
03:12replacayeah, that works best with long wait ajax push consumers
03:13magicduncanok, I need to give that some thought. I'll take a look at your slides. Thanks!
03:13replacabut obviously there are a lot of variations (esp. if you know you're clients aren't going to disappear on you)
03:13replacasure. enjoy!
03:51angermanis clojuredocs.org new?
04:21angermanhow do I create a 2d float array?
04:38jarpiain,(make-array Float/TYPE 10 20)
04:38clojurebot#<float[][] [[F@114f313>
04:40angermanjarpiain: is there an easy way to create one from a seq of seqs?
06:56angerman(byte 254)
06:56angerman,(byte 254)
06:56clojurebotjava.lang.IllegalArgumentException: Value out of range for byte: 254
06:56angermanso what does java make from (byte)(254.0)?
07:02angerman,(byte 0xFF)
07:02clojurebotjava.lang.IllegalArgumentException: Value out of range for byte: 255
08:14noidiwhat's the simplest way to update the nth item in a seq?
08:15noidiif I was using a vector I could use an update-in, but I'm dealing with a lazy seq
08:22noidithere must be a simpler way than this... (defn update-nth [s n f] (concat (take n s) [(apply f [(nth s n)])] (drop (inc n) s)))
08:30noidioh well, I realized I need to convert to a vector anyway for this use case
08:30noidiseq was a bad choice for several reasons
08:32esbenadoes clojuer have any libraries for solving minimum cost maximum flow instances?
08:35noidiesbena, I have no idea what you are asking for, but most of Clojure libraries are quite generic. You'll probably need to use Java libraries for domain-specific things.
08:41esbenanoidi, ok. btw. minimum cost maximum flow instances are a general formulation of a lot of algorithmic problems. ex. freight scheduling.
08:48noidiesbena, maybe this could help you? http://stackoverflow.com/questions/51574/good-java-graph-algorithm-library
08:49esbenanoidi, thx!
08:49noidihttp://www.yworks.com/products/yfiles/doc/api/y/algo/NetworkFlows.html
09:39tonylmorning
10:40angermanis there something like -> that takes a vector of forms and applies -> on them?
10:41angermanjust wondering if there's something like that already
10:44tonylsomething like this (apply -> [:foo str keyword])?
10:44tonylbut that doesnt work, -> is a macro
10:45angermanhmm no, wait, i'll code something up.
10:45angerman-< and -<< are not used yet, right?
10:46tonylnot as far as I know
10:59angermanhow do I get the contents of a list in a macro?
11:01tonylby defering the list, i think. I am barely new to macros
11:01tonyl~@
11:01clojurebot@ , {a b c]
11:03tonylangerman: so you want a fn or macro that takes a vector of forms and applys -> to those forms?
11:03angermankinda
11:03angerman(defmacro -< [e & forms] (for [f forms] `(-> ~e ~@f)))
11:03angermanis pretty close
11:04tonyloh i see, yeah
11:04tonyli don't think you need splicing for f, ~f should work. i thought ~@ was for sequences
11:04angermanit would basically allow to branch
11:05angermanyes f is a sequence
11:05angermane.g. (-< 1 [(+ 1) (+ 1)] [(+ 2) (+ 2)])
11:05angermanshould return (list 3 5)
11:06tonylthen you want the list to be evaluated
11:08angermanwell, as above is already quite good. the only problem is that for returns a list and that list is trying to be evaluated :/
11:15bhenryi need to set an atom in one namespace and get it from another. is this a bad practice?
11:17tonyl,(for [vf [[(+ 1) (+ 1)] [(+ 2) (+ 2)]], f vf] `(f))
11:17clojurebot((sandbox/f) (sandbox/f) (sandbox/f) (sandbox/f))
11:17tonyl,(for [vf [[(+ 1) (+ 1)] [(+ 2) (+ 2)]], f vf] `(~f))
11:17clojurebot((1) (1) (2) (2))
11:17angermanhmm...
11:17angermangot it done
11:17tonylgreat
11:17tonylwhat do you have?
11:17angerman(defmacro -< [e & forms] (apply vector (for [f forms] `(-> ~e ~@f))))
11:18notsonerdysunnyis there a way to find out the number of arguments a given closure is going to take from the repl?
11:18angerman,(defmacro -< [e & forms] (apply vector (for [f forms] `(-> ~e ~@f))))
11:18clojurebotDENIED
11:18angerman:D
11:18tonyl:P macros
11:18angermanwell but this not let's one branch out :D
11:18angermanthreading with branches ... yey
11:18tonylsounds fun
11:19tonylnotsonerdysunny: you can check the meta from the fn for the arity
11:21angerman(-< and (-<< do look somewhat retarded though :D
11:21tonylhaha
11:21tonylhow about inception :P
11:22angermanpardon me?
11:22tonyla cool name would be inception
11:24angermandon't know if that's appropiate though. I'm thinking along thread-splicing
11:25notsonerdysunnytonyl: as I said these are closures returned by some macro other than defn .. so it does not have the :arglists in the meta info.. i tried to do that
11:25angermanit basically allows you to do branches
11:26angermane.g. you want to compute something further with x but you do need x later on again or in a different way.
11:26notsonerdysunnytonyl: however I feel it should be able to some how tell me that info .....
11:26tonylyeah i know, just going with it. that is an interesting name
11:26angermanso just branch it out, compute and merge them back together.
11:26wsimpsont-1000?
11:27wsimpson:P
11:27tonylyeah i like it, that is what r u using it for?
11:27angermanwell doing some image processing. I usually want to keep the image around while computing the histogram.
11:27angermanwas just wondering if there was a threading approach as well
11:27tonylnotsonerdysunny: I also think it should be easy to find
11:28tonylhopefully the image is not that big
11:30angermanno. ~ at most 600 x 150 x 1 byte
11:33tonylnotsonerdysunny: my advice would be to explicitly add the arglists meta to those closures if you can.
11:36tonylangerman: you can get rid of apply if you want
11:36angermanhow?
11:36clojurebotwith style and grace
11:36tonyl(defmacro thread-splicing [e & forms] (vec (for [f forms] `(-> ~e ~@f))))
11:37tonylvec takes a coll
11:37tonyli don't think it changes in perf but just a thought
11:37tonylhow?
11:37clojurebotwith style and grace
11:37tonylthat is funny
11:37tonyl@
11:37tonyl~@
11:37clojurebot@ is splicing unquote
11:38tonyl~~
11:38clojurebot#<ClassCastException java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;>
11:38tonyl~`
11:38clojurebotTitim gan éirí ort.
12:07notsonerdysunnyis there a way to list all the namespaces that are available in all the jar files available in the current *classpath* ?
12:07notsonerdysunnywith having to require all of them....
12:09tonyli would look in clojure.contrib.find-namespaces
12:09tonylprobably the fn find-ns-decls-on-classpath
12:11ThothOn the subject of clojure-contrib, I am having a terrible time finding it on my classpath. I have it at /opt/local/share/java/clojure/lib/clojure-contrib.jar and /opt/local/share/java/clojure/lib is in my classpath, but I keep getting an error "Could not locate clojure/contrib/str_utils__init.class or clojure/contrib/str_utils.clj on classpath"
12:12ThothIt's breaking on the line (use 'clojure.contrib.str-utils)
12:12tonyli think that is a deprecated namespace
12:13tonylno, my bad
12:13Thothstr-utils you were thinking?
12:13tonyldoes the str_utils.clj file exist?
12:14tonyli used to have this problem, can't remember how i fixed it
12:14ThothNo.....I had just installed the jar from ports. Maybe I should go grab it
12:14ThothMaybe I should grab the entire clojure-contrib package as .clj files
12:15tonylthe clojure.contrib.str-utils is deprecated since 1.2
12:15ThothOoohhh.
12:15tonylbut clojure.contrib.str-utils2 is a replacement i thikng
12:15tonyl*think
12:15tonylhttp://clojure.github.com/clojure-contrib/#str-utils
12:15ThothAh hah. :-)
12:16ThothInteresting. Thanks!
12:16ThothI'll give that a try
12:45jaleyHi guys! question about the bean function... the documentation says the returned object is a "read-only implementation of the map abstraction..." - does read-only here mean something different to Clojure's normal persistent datastructures? or is this just to make it clear that what's returned is immutable, unlike the original java object?
12:55ohpauleezjaley: It's just a regular APersistentMap
12:55ohpauleezlike {}
12:55ohpauleezthat is proxying the object
13:17mtopolnikI've been doing some memory measurements on lazy seqs
13:17mtopolnikturns out that on a 64-bit JVM the overhead of lazy seq per node is 120 bytes
13:18mtopolnikcompared to 56 bytes for a PersistentList
13:18mtopolnikseems quite a lot
13:19mtopolnikare there any plans to optimize the structures?
13:19clojurebotI don't understand.
13:20mtopolnikjava.utilLinkedList has 40 bytes per node
13:22mtopolnikfor example, once a lazyseq's node is forced, it basically becomes a cons
13:22mtopolnikmaybe only the cons could be kept around
14:11LauJensenPeople still recovering from the Conj? :)
14:21iveyHey, would any of you use a key/value store abstraction layer? So you could write to it, and have it speak mongo/redis/tokyo/cassandra/ whatever else?
14:29jaleyohpauleez: sorry was afk - thanks a lot, that's what i needed to know! :)
14:53alexykninjudd: awesomest Halloween costume!
14:54alexykhttp://yfrog.com/7e1kqfj
14:55noidibrilliant :D
15:26philjordanhi
15:26philjordanso I've just realised that 2 locally defined functions can't be mutually recursive
15:26jaley(doc trampoline)
15:26clojurebot"([f] [f & args]); trampoline can be used to convert algorithms requiring mutual recursion without stack consumption. Calls f with supplied args, if any. If f returns a fn, calls that fn with no argu...
15:27philjordanyeah, I know about trampoline
15:28jaleyoh. :)
15:28philjordanmy case isn't quite the classic recursion, one of my functions needs to hold on to a reference to the other (as in a closure)
15:29philjordanI'm trying to work out a minimal equivalent case
15:31philjordanhmm, maybe I want letfn
15:34replacaphiljordan: yeah, letfn is designed for that exact situation
15:35philjordanokay, I realise my case is more complicated than letfn will let me do
15:36philjordanone of my functions is actually the result of a higher order function call
15:36philjordanwhich as far as I can tell, letfn won't let me do. hm.
15:39philjordanokay, where the devil is letfn* defined :-/
15:39jarpiainLetFnExpr in Compiler.java, it's a special form
15:40philjordanah.
15:41philjordanthanks, that saves me some searching, but I suspect it also means I can't do what I'm trying to do
15:43philjordani.e. something like this:
15:44philjordan(let [a (h-o-f (fn [x] (fn [] (b x)))) b (fn [y] (a y))] a)
15:45philjordanwhich probably doesn't make it any clearer
15:45replacaphiljordan: you can't just have three fns in your letfn?
15:46replacaso that the fn called by h-o-f is also a neamed fn
15:46philjordanthe problem I see is that letfn requires function *bodies* whereas one of my functions is actually the return value of a higher-order-function
15:47replacaphiljordan: oh, i see. hmmm.
15:47philjordanactually, letfn seems to inject the 'fn' part
15:48philjordanletfn* itself might allow me to do what I want
15:48philjordangoing to try a (pprint (macroexpand on a letfn expression to wrap my head around it
15:52philjordanuser=> (pprint (macroexpand '(letfn [(a [x] (b x)) (b [y] (a y))] a)))
15:52philjordan(letfn*
15:52philjordan [a (clojure.core/fn a [x] (b x)) b (clojure.core/fn b [y] (a y))]
15:52philjordan a)
15:52philjordanthat looks promising
15:53jarpiain,(letfn* [x 1 y 2] (+ x y))
15:53clojurebotjava.lang.ClassCastException: clojure.lang.Compiler$ConstantExpr cannot be cast to clojure.lang.Compiler$ObjExpr
15:53jarpiainit really wants (fn ...) expressions there
15:53philjordandamn
15:54philjordanI guess that kind of makes sense
15:55td123is clojure still getting developed?
15:55philjordanI'll have to think about it some more, maybe I can express it in terms of 2 fns like that
15:55Raynestd123: http://github.com/clojure/clojure
15:55td123I see the git repo hasn't been updated since june
15:56td123oh
15:56td123nvm :)
15:56RaynesI assume you were looking at the told repository.
15:56td123Raynes: you assume correctly
15:56RaynesClojure is more lively than it's ever been. :>
15:57philjordanthanks for the help so far, this needs to bounce around my brain some more. til then I'm using an atom as a level of indirection :-/
16:01jarpiainletfn* initially writes nulls in the new locals and then has to patch the right values in the created closures
16:02Upper, (map #(% %) filter(odd?) (range 1 10))
16:02clojurebotjava.lang.IllegalArgumentException: Wrong number of args (0) passed to: core$odd-QMARK-
16:02td123what do you guys think is the best intro to clojure out there?
16:03RaynesI've heard good things about Stuart Sierra and Luke Vanderhart's Practical Clojure.
16:04jaleydesign/style question: i'm tempted to write a function, "beanify", to iterate through the nest of javabeans i get back from a web service calling bean to convert them to maps. is this bad? will i regret it in a few weeks? :)
16:05Upperhow to print only odd number sequence? I want to print a number of times, example, if the args is 5, it will return 1 3 5 7 9
16:06angerman(range 1 (* 2 5) 2) ?
16:06angerman,(range 1 (* 2 5) 2)
16:06clojurebot(1 3 5 7 9)
16:06Uppertks
16:08td123angerman: what does that comma do?
16:08angermaninvoces clojurebot
16:08quizmeI'm having trouble with leiningen & neo4j. Can somebody explain to me what this means? ---> http://pastie.org/1260692
16:08td123oh neat
16:08Raynes&(range 1 (* 2 5) 2)
16:08sexpbot⟹ (1 3 5 7 9)
16:08td123,(println "hi bot")
16:08clojurebothi bot
16:08td123hehe
16:09Raynessexpbot has a pretty arrow. <3
16:09jaley;; presumably it's protected from things like (iterate inc 1)?
16:09RaynesYes.
16:10RaynesBoth bots are.
16:10angerman,(println "&(println \",(nil)\")")
16:10clojurebot&(println ",(nil)")
16:10sexpbot⟹ ,(nil) nil
16:10RaynesMy pretty arrow prevents botchains.
16:11Upperangerman: is possible print -> 1;3;5; instead of (1 3 5) ?
16:11angermanhmm. backspace?
16:12jaleyUpper: there's a str-join function in contrib/str-utils
16:12Upperright
16:12angermanRaynes: hmm... I guess backspace character eating does not work
16:12replacaUpper: cl-format supports more customization as well
16:12Raynes&(doseq [x (range 1 (* 2 5) 2)] (print (str x ";")))
16:12sexpbot⟹ 1;3;5;7;9;nil
16:13RaynesThat's actual printing though.
16:14LauJensen&(do (println "1") (println "2"))
16:14sexpbot⟹ 1 2 nil
16:15vibrant_how can i join 2 vectors?
16:16Raynes&(into [1 2 3] [4 5 6])
16:16sexpbot⟹ [1 2 3 4 5 6]
16:16vibrant_thanks Raynes
16:17RaynesThere is also concat, but it returns a lazy-seq and not a vector.
16:17Raynes&(concat [1 2 3] [4 5 6])
16:17sexpbot⟹ (1 2 3 4 5 6)
16:18replacaUpper: like this: (cl-format nil "~{~a~^;~}" [1 3 5])
16:18replacafor string output
16:18replacause true or *out* instead of nil if you want it to print
16:19Upperthat doseq from Raynes worked well
16:21Raynes&(println (apply str (interpose ";" (range 1 (* 2 5) 2))))
16:21sexpbot⟹ 1;3;5;7;9 nil
16:21RaynesThat's an option.
16:23Raynescl-format is a beast.
16:24jaleyis there a less ugly way of doing something like... (if (coll? x) x [x])?
16:25jaleyi want to map over x, but sometimes it'll be a single object, not a collection, and i want to treat as a collection of 1 object i guess
16:27chouserreplaca: I know you've told me this before, but what's the easiest way to pprint code?
16:30wdouglasIs there any guide for viewing function definitions in jar files with emacs? (e.g.. M-. jumps to text region of the definition)
16:31jaleywdouglas: I think I saw that demonstrated in the video for CDT (clojure debug toolkit?). I suspect that feature wouldn't have been added if it was already possible? so probably no, but not sure.
16:33arohnerwdouglas: what do you mean? M-. jumps to defintions inside jars for me
16:33wdouglasjaley: thanks I'll take a look at that
16:33wdouglasarohner: It used to work for me too but I switched over to a new vm and now it does not.
16:34vibrantany libs recommended for game programming?
16:34jaleywdouglas: actually yeah... working on openjdk for me
16:34wdouglasarohner: I just figure I'm missing something I normally have configured but my googling hasn't pulled up much.
16:34arohnerwdouglas: vm? JVM? I'm running sun JDK, slime, and the jar is on the classpath, and it Just Works for me
16:34arohnerwdouglas: you're running slime and the jar is accessible in the running classpath?
16:34wdouglasopen-jdk. Lib in the classpath.
16:35arohnerwdouglas: stupid question, but you're connected via slime? Does M-. on a definition in a text file work?
16:35clojurebotslime-installer is deprecated
16:35wdouglasarohner: Will make sure it isn't working on clojure core though as it is another lib in the classpath that I am having issues with
16:36wdouglasarohner: Well it jumps into the jar file (probably to the right place, just binary though)
16:36jaleywdouglas: a whole bunch of slime features broke for me when i upgraded my distro because versions were out of sync with the distro package manager. i stopped using the package manager version of slime as a result.
16:37wdouglasAh I just use the version in elpa
16:37wdouglasarohner: works fine within the text file in SLIME
16:38arohnerwdouglas: when you say 'just binary', what do you mean? did it jump to the jvm byte code for the function?
16:38wdouglasThat's what it looks like to me.
16:38arohnerwdouglas: is there a .clj containing the function in the jar?
16:40wdouglasarohner: Will need to figure out how to take a peek in the jar.
16:40wdouglasarohner: the package is aleph if you know off hand
16:40arohnerwdouglas: just visit the jar in emacs. it will give you a dired window
16:41wdouglasarohner: Yep
16:41wdouglasarohner: ahh I think I get it
16:41wdouglasarohner: When I try to open the file from emacs, it says it can't find unzip
16:41arohnerwdouglas: ah. that sounds like a problem
16:42wdouglasarohner: Yep X(
16:42jaleywdouglas: windows?
16:43angermansometimes I wish clojure had infix notation
16:43wdouglasjaley: No, arch
16:43rdeshpandel
16:43jaleyangerman: it's in incanter, $= macro
16:44angermanjaley: right. too bad that's not available as an external lib
16:44angermanhate to drag incanter with me all the time
16:44jaleywdouglas: ah ok. i use emacs at work and have to install cygwin for half of emacs to function properly :p
16:45jaleyangerman: yeah, it's pretty useful
16:46wdouglasjaley: Same, though I have run into issues with git for windows cygwin and the normal cygwin install playing nice
16:46wdouglasjaley: arohner: Yep, unzip install fixed it. Thanks for your help.
16:48angermanThis: (show (>- thresh-at (-< (scale (load-sample-character 1) :height *H*) [identity] [blur freq-table smooth-hist2 combined-thresh-finder]))) would definitely look better with >- thresh-at at the end.
16:48angerman-< is bascially a parrallel ->
16:49angermanand (>- fn forms) is (apply fn forms) ...
16:49rata_hi
16:59angermanlol
16:59angermanthe threading macro is evil
17:02jcromartieany macro can be evil
17:02jcromartie-> is really nice :)
17:02sexpbotjava.lang.Exception: Unable to resolve symbol: is in this context
17:02angermanhttp://gist.github.com/655742
17:02jcromartie-> "what?"
17:02sexpbot⟹ "what?"
17:03angermanthough it allows for some flow-style programming
17:03jcromartieI think => is a better parallel ->
17:03jcromartiename-wise
17:04jcromartieoh, I thought you meant parallel like threads
17:05angermanno, parallel as in splicing
17:05angermanthough I guess you could easily add parrallel computation semantics
17:06angermanas this perfectly describes parrallel computation flow
17:07jcromartieseriously though, your code *is* evil
17:07angermanif you get used to the macros it is quite readable.
17:07angermanmostly like a flow chart :D
17:07jcromartiehm I guess I get it
17:08angermanthe inc in there is somewhat confusing :D
17:08jcromartieit reminds me of juxt in a macro
17:09jcromartiein fact what does it do that you can't do with juxt?
17:10jcromartienever mind, I see the point
17:10jcromartieneat
17:10jcromartiesaves a few ->'s
17:10jcromartieand fns
17:11angermanyep. there are some things you just cannot do with the default -> threading as it's a single thread.
17:11angerman>- basicaly splices the thread
17:11angermanerr -< splices
17:11angermanand >- recombines it
17:12angermanhttp://skitch.com/angerman/d6y3y/untitled this is what I use it for
17:12angermanI've added the full extended version
17:12angermanhttp://gist.github.com/655742
17:18jcromartieis that some OCR?
17:19angermannot yet. but it's getting there
17:29jcromartieI was surprised to learn that the options out there for open source OCR are really really terrible
17:29jcromartieand haven't advanced at all in years
17:30rata_angerman, are you working on an open-source OCR?
17:31angermanrata_: this is going to be a dead stupid one with very limited functionality
17:31rata_ok
17:31angermanit's basically just a prototype for serial number detection of bank notes
17:37rata_does anybody know the nickname of Justin Kramer (the author of loom) in freenode? I thought it was jkkramer, but "/whowas" says there was no such nickname
17:37technomancythere's a /whowas command‽ nice.
17:38angermanwhoa, interobang
17:39rata_technomancy, yes, there is :)
17:39technomancysweet; my meme is still rolling: http://twitter.com/#!/search?q=%23unicodebandnames
17:44angermantechnomancy: could I get your input on -< and >- ala http://gist.github.com/655742
17:46rata_technomancy: how can I make swank to recognize (some-ns/let-* [...] ...) as a let-like form and indent it accordingly?
17:46technomancyrata_: live indentation inference over swank is only implemented for CL, I think
17:47technomancyangerman: I'm not seeing the motivation; it'd be clearer if you had original vs your new macros side-by-side
17:48rata_mmm... really? but it does recognize (let-* [...] ...)
17:48technomancyrata_: that's just static analysis in clojure-mode; nothing to do with swank
17:48technomancyI think
17:48rata_ok
17:49rata_who's the author of clojure-mode?
17:49technomancyjeffrey chu, who vanished years ago
17:52rata_:(
17:53angermantechnomancy: I'm having a hard time coming up with working clojure code to supply my macros
17:54angermanbasically the idea is that when using (-> ...) you are bound to sequential computation
17:54angermanin my application I have an image. of which I compute the the histogram and use that to compute an optimal thresholding value. Then I stick both together (the image and the compute value)
17:55angermanfrom a flow-diagram this looks semi-sequential. At one point I need to branch ( -< ) and at one point I need to merge ( >- ) the branches again.
17:58angerman(-<) looks to me like information is flowing in on the left and is split into two new threads
17:58angermanwhile (>-) looks like two threads are merged together
17:58hiredmanangerman: http://intensivesystems.net/tutorials/stream_proc.html
18:00angermanhiredman: interesting :D
18:04angermanfor the lightweight use I'll use my macros
18:06quizme(str :a) => ":a" How do you get rid of the colon or not make it show up in the first place?
18:06MayDaniel(name :a)
18:07quizmeMayDaniel awesome thanks
18:52replacachouser: I was off with the kids
18:52replacachouser: try this: (with-pprint-dispatch *code-dispatch* (pprint code))
18:52replacaalso, see here for more info: http://clojure.github.com/clojure/doc/clojure/pprint/PrettyPrinting.html
19:05rata_how can I expose what I :use?
20:07_seanc_Is there no time or timestamp in clojure?
20:07hiredman,(.getTime (java.util.Date.))
20:07clojurebot1288483747917
20:08_seanc_I'm surprised there's no simple (timestamp)
20:08hiredman,(System/nanoTime)
20:08clojurebot1288483810267527000
20:10Raynes_seanc_: Where Java isn't broke, Clojure doesn't fix it.
20:10Raynes&(java.util.Date)
20:10sexpbotjava.lang.ClassCastException: java.lang.Class cannot be cast to clojure.lang.IFn
20:10Raynes&(java.util.Date.)
20:10sexpbot⟹ #<Date Sun Oct 31 00:11:30 UTC 2010>
20:10RaynesThere are already excellent time libraries for Java, such as Joda.
20:10Raynes$google clj-time
20:10sexpbotFirst out of 44400 results is: clj-sys's clj-time at master - GitHub
20:10sexpbothttp://github.com/clj-sys/clj-time
20:11_seanc_Ok
20:11Raynesclj-time is a Clojury Joda wrapper.
20:11_seanc_I just figured that was something simple and might be a part of Clojure I was simply over looking
20:25Ploujkeyboard on the legs: http://www.flickr.com/photos/ghoseb/5120430719/in/set-72157625254615916/ ??
20:28LaPingvino:P
20:38_seanc_Using Atoms, could you create a simple cache of sorts for a web app (Compojure) or am I misunderstanding their purpose? For instance, say the number of users; retrieve, put in atom, everyone else retrieves without hitting the db.
20:39LauJensen_seanc_: You might want to check out memoize, both its purpose and implementation
20:39LauJensen(it uses an atom as its cache)
20:40_seanc_I have, but it appears there is no way to update the values in memorize. I wanted to use atom with a vector containing a timestamp and the value. If it's more than a few days off, get an updated value
20:41LauJensen_seanc_: Reimplement memoize with a different caching strategy. Would be trivial to implement a timestamp check
20:45LauJensenJust to be clear though, you're not using Ring/Compojure to serve static files right?
21:12angerman...
21:13angermanand it's one hour earlier ... timetravel
21:30Lajla,(let [+ + + + + +] (+))
21:30clojurebotLajla: Titim gan éirí ort.
21:30Lajla->(let [+ + + + + +] (+))
21:30sexpbot⟹ 0
21:50somniumhttp://gist.github.com/656004 << anyone think this is interesting? a toy implementation of structural types + pattern matching in Clojure
21:53duck1123Just so I'm sure I'm not missing something, it is not possible to proxy a final method, correct?
21:56duck1123I'm trying to find a good way to mock out a concrete class for my tests. It's a PITA to set up and I only call a handful of methods on it, one of which is final
22:05rata_somnium: interesting :) I like it
22:20quizmehow do you change the way a java instance displays in the repl ?
22:20quizmeright now it looks like: #<NodeProxy Node[2]>
22:21quizmebut i want it to look like: {:id "C12345", :age 30, :name "Bob"} for example
22:26somniumquizme: (defmethod printmethod <javatype> (fn [w x] (.write <representation-of-x>)))
22:26somniumoops, (.write w <rep>) of course, you probably get the idea anyway
22:27somniumrata_: ah cool, someone looked at it :)
22:29rata_somnium, quizme: I think it's print-method
22:30Raynes&(doc print-method)
22:30sexpbot⟹ nil
22:30RaynesIndeed.
22:30alexykhey somnium! what's new in congomongo? are you still hacking at it?
22:31rata_somnium: :) I like that Haskell-like syntax
22:31quizmeoh cool
22:31RaynesHe better be.
22:32somniumalexyk: not so much :( it still scatches the itch when I need it
22:32somniumalexyk: purcell and arohner are helping maintain it though
22:32alexyksomnium: cool
22:33Raynes$max
22:33sexpbotThe most users ever in #clojure is 317
22:34somniumrata_: right now it can't handle nullary types, and makes a deftype for each struct, so they're cumbersome to extend with protocols
22:35somniumbut, that's toys for you, I'll go ahead and put it on github :D
22:35rata_good :)
22:38somniumalexyk: so you implemented your project from back when in haskell and ocaml too, with multiple key-value stores?
22:40somniumrata_: http://github.com/somnium/matchmaker
23:28rata_how can I expose what I :use?
23:36Joshua__If I was to get a Paradigms of AI Programming by Peter Norvig how hard would it be to do the book in Clojure rather than Common Lisp?
23:41rata_Joshua__: if you know CL and Clojure, I imagine it'd be easy
23:41Joshua__Well I don't know CL and I'm a real novice with Clojure.
23:41Raynesrata_: What do you mean by 'expose'?
23:41Joshua__I want to learn Clojure though, but I'm not to keen on learning CL.
23:42greghJoshua__: then it might be sort of like reading about the history of opera in italian, when you don't know italian. :)
23:43_seanc_Question about atoms. Doesn't (let [mem (atom {})]) essentially reset the atom? To retain the value(s), would it be best to check first?
23:43rata_Raynes: I mean that after require'ing that file, I can access the :use'd symbols
23:44rata__seanc_: I don't understand your question
23:44RaynesI'm pretty sure there isn't a way to do that. There was some sort of immigrate macro in compojure to do something similar, but it's generally considered bad juju.
23:45_seanc_rata_: I'm trying to set up a simple cache using atoms. But within the function I'm wondering if I need to do anything to prevent the atom being reset to an empty map.
23:47_seanc_if you call (def mem (atom {})), add some values, and then call def again, mem is empty. How can I prevent that?
23:47rata_Raynes: then how can I expose the symbols of several files in one namespace?
23:47Raynesrata_: That was, if I remember correctly, the exact purpose of immigrate.
23:48rata_mmmm... then there's no way to do it? why is it considered a bad thing?
23:48rata__seanc_: do you want to rebind mem?
23:50Raynesrata_: Probably because then you have no idea where anything comes from. The generally accepted way of doing things is to require namespaces rather than use them, or to only :use what you need from namespaces.
23:50_seanc_rata_: I want to bind it once, then prevent it from accidentally being rebound after it is populated.
23:51Raynesrata_: http://github.com/weavejester/compojure/commit/2fe4f37a15f3bd2fb285192b05a8f270d927e1d8
23:51rata__seanc_: then don't do any (let [mem ...] ...), it's already bound with def
23:52RaynesYou *can* do it, but you might want to consider a different way.
23:52_seanc_rata_: I'm writing an app with compojure, at the top I do the def. What I'm concerned about is if another user hits the site that it might reset the values. Are my concerns irrational?
23:53rata__seanc_: I don't know anything about compojure
23:54_seanc_oh well, I appreciate the help
23:55rata_Raynes: but I have different namespaces just to have manageable files... I want some of their functions in an shorter namespace
23:56Raynes_seanc_: Your files don't get reloaded when a request is made.
23:56clojurebotYou don't have to tell me twice.
23:56_seanc_Raynes: Awesome! :D
23:56Raynes_seanc_: However, there is some developer middleware to do just that, for the purposes of development.