#clojure logs

2009-07-31

00:15Chouser(def q (fill-queue #(loop [] (% (rand-int 100)) (recur))))
00:15Chouser(take 10 q) ==> (40 53 75 66 52 8 63 73 72 8)
00:26ChouserWork nicely if you're not in control of the loop -- somebody else is looping and wants to call your callback, but you want all that as a lazy seq.
00:26Chouserclojure.contrib.seq-utils/fill-queue
01:01Drakesonhow can I access/save/restore a memoized function's "cache"?
01:05bradfordis there some clever way to fn-ify macros for composition such as passing them intop higher order functions?
01:29bradfordoh..i just quote them :-)
01:29bradford,(#(%1 %2 %3) 'and true false)
01:29clojurebotfalse
01:29bradfordcan't believe i did not realize that :-(
01:31Fossi,(#(%1 %2 %3) 'or true false)
01:31clojurebotfalse
01:32Fossi:o ;)
01:34durka42,('or true false)
01:34clojurebotfalse
01:34durka42,(#(%1 %2 %3) 'fandango true false)
01:34clojurebotfalse
01:34bradfordso that's not valid?
01:34wtetzner,('or false true)
01:34clojurebottrue
01:35durka42well you are calling the symbol
01:35durka42not the var which the symbol identifies
01:35wtetzner,('x 'y 'z)
01:35clojurebotz
01:35wtetznerit just returns the value of the last thing in the list
01:35bradfordindeed :-)
01:37bradfordso no such trickery?
01:37durka42,#'and
01:37clojurebot#'clojure.core/and
01:37wtetzner,(#(eval '(%1 %2 %3)) 'or true false)
01:37clojurebotDENIED
01:37wtetznerhmm
01:38durka42not without eval, yeah
01:38durka42user=> (eval (#(%1 %2 %3) #'or true false))
01:38durka42true
01:38wtetznerwhat is #'or ?
01:39wtetzner,#'or
01:39clojurebot#'clojure.core/or
01:39durka42,(var or)
01:39clojurebot#'clojure.core/or
01:39durka42(type #'or)
01:39durka42,(type #'or)
01:39clojurebotclojure.lang.Var
01:39wtetzneroh
01:39durka42(doc var)
01:39clojurebot"/;nil; "
01:39durka42,(doc var)
01:39clojurebot"/;nil; "
01:40durka42interesting
01:40durka42informative, that
01:45bradfordnow suppose that little example's lambda takes x & xs where x is the var represetning a macro. would there be some equivalent to apply for the macro?
03:13Drakesonhow can I dump and restore some data (e.g., nested maps) into a binary format (binary, in order to keep numerical data intact)
03:13hiredman,(doc prn)
03:13clojurebot"([& more]); Same as pr followed by (newline). Observes *flush-on-newline*"
03:13hiredman,(doc pr)
03:13clojurebot"([] [x] [x & more]); Prints the object(s) to the output stream that is the current value of *out*. Prints the object(s), separated by spaces if there is more than one. By default, pr and prn print in a way that objects can be read by the reader"
03:14hiredman,(doc *print-dup*)
03:14clojurebot"; When set to logical true, objects will be printed in a way that preserves their type when read in later. Defaults to false."
03:15Drakesonthanks :)
03:20Drakesonummm, binding *print-dup* and then pr'ing doesn't seem to print in a binary format. How can I pick the output format? does this depend on the output stream?
03:21lbjTop of the morning gents
03:21hiredman,(binding [*print-dup* true] (prn-str '(1 2 3)))
03:21clojurebot"(1 2 3)\n"
03:21hiredman,(binding [*print-dup* true] (pr-str '(1 2 3)))
03:21clojurebot"(1 2 3)"
03:21hiredman,(.getBytes (binding [*print-dup* true] (pr-str '(1 2 3))))
03:21clojurebot#<byte[] [B@1f4cdd2>
03:21hiredman*tada*
03:23hiredman,(doc print-method)
03:23clojurebot"; "
03:23lbjWhat did you just accomplish hiredman ?
03:23hiredmanbah
03:23hiredmanlbj: Drakeson wanted "a binary format"
03:23lbjaha
03:24hiredmanactually, if you really want a binary format
03:24hiredman,(apply str (map (comp #(Integer/toBinaryString %) int) (.getBytes (binding [*print-dup* true] (pr-str '(1 2 3))))))
03:24clojurebot"101000110001100000110010100000110011101001"
03:25lbjDo we have anything like emacs-lisps (md5 "") in Clojure?
03:25hiredmanthe problem with that is toBinaryString doesn't pad the bits
03:25lbjHaving which consequences?
03:26hiredmanvariable length binary figures are hard to read
03:29lbjk
03:35lbj,(let [msg "foo bar baz"]
03:35lbj (.update (java.security.MessageDigest/getInstance "MD5")
03:35lbj (.getBytes msg) 0 (.length msg)))
03:35clojurebotEOF while reading
03:35lbjWhy does that return nil ?
03:44hiredman,,(let [msg "foo bar baz" foo (java.security.MessageDigest/getInstance "MD5")] (.update foo (.getBytes msg) 0 (.length msg)) (.digest foo))
03:44clojurebot#<byte[] [B@8d5a91>
03:44hiredmanit returns nil because the update method on MessageDigest returns void
03:44lbjAh, thanks
04:08AWizzArdWhat was the name of the function that takes a collection and lazily returns all elements, but each two elements from that returnd seq are pairwise different.
04:09AWizzArdlike putting all elements of a coll into a set, just lazily
04:10AWizzArdmaybe it was in contrib somewhere?
04:21Drakeson,distinct
04:21clojurebot#<core$distinct__5417 clojure.core$distinct__5417@1484a8a>
04:21Drakeson~distinct
04:21clojurebotIt's greek to me.
04:22Drakesonanyways, AWizzArd: that would be `DISTINCT'
04:22Drakeson,(doc distinct)
04:22clojurebot"([coll]); Returns a lazy sequence of the elements of coll with duplicates removed"
04:28AWizzArdDrakeson: yup that was it, thanks
04:29DrakesonAWizzArd: well, I just loaded all of contrib and used find-doc.
04:31AWizzArdDrakeson: i also used find-doc, but I had the word "unique" in mind.
04:32AWizzArdI used distinct several times, just forgot its name :p
06:48ChousukeAnyone looked at the new Pro Git book yet? http://progit.org/book/
07:15jdz,(do (defstruct bar :data) (read-string (binding [*print-dup* true] (with-out-str (pr (struct-map bar :data 42))))))
07:15clojurebotDENIED
07:16jdz,(do (defstruct bar :data) (read-string (binding [*print-dup* true] (pr-str (struct-map bar :data 42)))))
07:16clojurebotDENIED
07:16Fossiit would be interesting to know what the bot doesn't like about a statement
07:18jdzmy point is that there is no print method for clojure.lang.PersistentStructMap
07:18jdzi think i should go and learn how to open tickets
07:23rhickeyjdz: all changes to structmaps are on hold
07:23RaynesIf Clojurebot ever asks me to do something for it, I'm just going to reply: DENIED
07:24jdzrhickey: ok, nvm then.
07:25rhickeyjdz: I want to reevaluate their implementation in light of new new, but I understand the use cases for print/read, and constants of struct types, as well as compilation
07:29jdzalso
07:29jdz,(binding [*print-dup* true] (pr-str (with-meta (array-map :x 17 :y 42) {:type :whatever})))
07:29clojurebot"#^#=(clojure.lang.PersistentArrayMap/create {:type :whatever}) #=(clojure.lang.PersistentArrayMap/create {:x 17, :y 42})"
07:30jdz,(binding [*print-dup* true] (pr-str (with-meta (hash-map :x 17 :y 42) {:type :whatever})))
07:30clojurebot"{:y 42, :x 17}"
07:30jdzthe only difference is array-map vs. hash-map
07:30jdzi.e., the :type meta tag is lost
07:30rhickey,(doc print-dup)
07:30clojurebot"; "
07:32rhickeyhrm, should put experimental
07:48lbjrhickey: Are you still using emacs + swank (no slime) ?
07:49rhickeyemacs mode only, no swank/slime
07:49lbjrhickey: Ok - Why is that? I consider slime (in most cases) to be a help to me
07:50rhickeyI like to keep things simple, plus, I'm working on Clojure itself
07:51lbjOk
07:51rhickeynote, I'm not much of an emacs guy
07:51lbjYoure more of a Lisp Works guy ? :)
07:52lbjI guess we'll all have to hold our breath until Enclojure is a bit farther up the road than it is now. I lack a better overview of the entire project with Emacs
07:52lbj(guess I should write the plugin)
07:52rhickey not much of an editor guy at all. But I switch around, use IntelliJ for Java and have used enclojure too
07:53AWizzArdDo you have (roughly) an ETA for newnew?
07:54lbjOk - I dont care about the name on the door, but I do want every single feature I need in my daily work within the reach of one shortcut, thats why I use emacs + linux
07:55y-combinatorHello. I have problem using clojure.contrib.json.write. It references (:use [clojure.test :only (deftest- is)])) which Clojure cant find on classpath. Info about this lib states that it should actually use clojure.contrib.test-is. Is this a bug or im missing something?
07:55rhickeyAWizzArd: you can start playing with it now, still more to come: http://github.com/richhickey/clojure/tree/new
07:57lbjBy the way rhickey, are you yourself planning on putting out a book ?
07:57rhickeylbj: would you prefer I write a book or write Clojure?
07:58lbjSpecificially I was wondering if you were cooking on something that was more philosophical than practical, regarding clojure, concurrency etc
07:58lbjrhickey: I see what youre saying :)
07:58AWizzArdI would vote for writing Clojure.
07:58rhickeythere you go
07:58rhickeysomeday perhaps
07:58lbjOk
08:04ttmrichterrhinkey: You're the person behind Clojure?
08:04ttmrichterIf so, thank you for giving me the first Lisp dialect I didn't merely admire, but actively liked.
08:05ttmrichterrhickey, even. :) Stupid fingers.
08:07lbjrhickey: Btw, I read a review of JAOO (you know, the event were you ditched your danish crowd), and all they had discussed that day was concurrency and related problems, and you were mentioned specificially as being missed :)
08:09rhickeyttmrichter: you're welcome
08:10AWizzArdbtw, I am now looking into Drools to see how useable it is from Clojure. It works on POJOs, but then again our Clojure collections are nothing more under the hood. Some macro magic might be enough to get something nice.
08:10rhickeylbj: which JAOO? I'm speaking (twice) at JAOO Aarhus: http://jaoo.dk/aarhus-2009/
08:11rhickeylbj: link to review?
08:11lbjrhickey: You told me you bailed on JAOO? Hang on Ill find the review, I caught it on dzone I think
08:11rhickeyAWizzArd: last I looked they didn't support maps as facts, much to my chagrin. Everything based on beans
08:14lbjrhickey: http://danweinreb.org/blog/programming-with-concurrency
08:18Chousery-combinator: did you get an answer?
08:18rhickeylbj: I wasn't invited to that one (2008)
08:18Chousery-combinator: looks like you're using clojure 1.0.0 but contrib HEAD. You'll need to either get a newer clojure or an older contrib.
08:19lbjrhickey: Ok -Its very intersting that you're showing up for the 2009 event, I'll be looking forward to it. If theres anything you need help with while youre here dont hesitate to let me know. You can also catch a ride to Copenhagen after the event if need be.
08:20rhickeylbj: thanks
08:38Fossilbj: where are you from? i might be going from hamburg
08:39lbjFossi: Im from Ringsted, Denmark
08:46Fossiah. guess we have about the same time to drive to arhus :D
09:00y-combinatorChouser: Clojure 1.1.0-alpha-SNAPSHOT, seems new
09:01y-combinatorChouser: and Contrib from HEAD
09:02y-combinatorChouser: other libs from contrib are working fine
09:03ChouserClojure HEAD has test/clojure
09:04y-combinatorok, i will checkout and compile HEAD
09:11alinphi
09:11alinpclojure have foldl/foldr ?
09:11alinpor reduce is the only way to do it ?
09:16jdzto do what?
09:29y-combinatorChouser: thank you, building HEAD helped
09:29Chousergood
09:32y-combinatorIve used some shell scripts from ineternet to install clojure and now i checked them and they use googlecode svn, it seems version in google code is not updated currently
09:32y-combinatorthat why i didnt had clojure.test
10:00Chousukehmm.
10:01ChousukeI tried refactoring the Clojure reader to use an interface instead of PushBackReader directly, and it works. :o
10:02ChouserChousuke: sweet!
10:05ChousukeI changed as little as possible, but I'm pretty certain there is something I broke.
10:05Chousukethere always is
10:08lpetithi
10:09Chousukehm
10:09Chousukeall tests pass in both Clojure and contrib.
10:11lpetitsorry for the question that has been asked again and again but ... does the function that creates a new map from an old by applying an fn to the values exist ? Or do I have to write my own (defn map-values [f m] (into {} (map (fn [[k v]] [k (f v)]) m))) ?
10:11Chousukelpetit: there's something in contrib I think.
10:12lpetitnot in map-utils
10:12Chousukec.c.generic.functor or something
10:13lpetitok, found the ApiDocIndex wiki page created by Tom,
10:14lpetit-> map-utils in datalog.utils :-$
10:14lpetitnot the best place ...
10:17cgrandlpetit: if you only use the resulting map as a a function try (comp f my-map)
10:18hiredmanooo
10:18hiredmancute
10:18hiredmanwell it's already in clojure.lang right?
10:18drewr,(.replaceAll ":foo :bar :baz :foo" ":foo" "f$o")
10:18clojurebotjava.lang.IllegalArgumentException: Illegal group reference
10:18Chousukehmm, true.
10:19drewris there a replaceAll that doesn't try to use backreferences?
10:22cgranddrewr: none that I'm aware of, you have to use http://java.sun.com/javase/6/docs/api/java/util/regex/Matcher.html#quoteReplacement(java.lang.String)
10:23lpetitcgrand: elegant, but no I'm working on datastructures
10:24drewrcgrand: thanks!
10:27stuartsierraoff-topic, but anyone ever used Fedora Commons?
10:36lbjrhickey: This 'Concurrency experts panel', is that a joint presentation that youve prepared with Simon Peyton and the rest of the gang?
10:37rhickeylbj: oh, yes, I'm on that too. No idea, probably just a panel, moderator, questions etc
10:37lbjQuite interesting that you've in the same panel as the co-creator of Haskell... will need to prepare some questions :)
10:37lbjAre you taking off wednesday night, or staying till friday?
10:42rhickeyI plan on spending most of my time with SPJ listening :)
10:42rhickeyleaving Thursday
10:43lbjk
11:46drewrhttp://brizzled.clapper.org/id/93
11:50Chouserfoo.x += 1 ....mmm yummy
11:50Chouser:-)
11:51ChouserIt wasn't too long ago that I would have meant that sincerely, instead of worrying about the mutation.
12:04iBongis there a built in join method for strings in clojure?
12:05Chouserclojure.contrib.str-util2 and str-utils both have a join
12:06stuartsierraThat's like Perl's join. If you just want to concatenate strings, use "str".
12:06Chouserboth just do this:
12:06Chouser,(apply str (interpose "," (range 5)))
12:06clojurebot"0,1,2,3,4"
12:08iBonglike Perl's join, I've only been using the clojure core api, just found the github clojure doc project, hopefully it will be enlightening
12:08lpetitany plans on merging str-utils 1 & 2 ?
12:08iBongthanks, I just thought I'd ask before I started rolling my own versions
12:08ChouserI think str-utils2 is meant to supercede str-utils
12:08stuartsierraThat was my plan. I haven't replaced str-utils because so many libs depend on it.
12:08lpetitor adding docs so that newcomers (as me today) know what to pick and where
12:08lpetitha ok
12:09lpetitmaybe a little "deprecated" note on the former, and a "new version of str-utils" on the latter ?
12:09stuartsierrastr-utils2 was my attempt to make a complete string-manipulation library with a consistent API, rather than the random assortment of functions in str-utils
12:09lpetitI've switched back and forth both of them today, I guess other will in the future too
12:09stuartsierrabut I never quite finished, so I never made a formal announcement
12:10stuartsierraIn general, str-utils2 should be faster. It also has copies of the core Clojure sequence functions, but optimized for operating on Strings.
12:10lpetitit's this "experimental" or "still under active development" indications that are missing from the docs I think. Transparency will help not having users come angry to us
12:10lpetitah ok
12:14stuartsierraalthough there was a reason for that -- I always put the String argument first, so that multiple str-utils2 fns can be chained with ->
12:15stuartsierrabut I should probably fix that
12:16stuartsierramaybe I'll just rename them str-drop, str-take, etc.
12:17hiredman:(
12:17hiredmanwhat is the point of namespacing then?
12:18lpetitI must leave, cu
12:19iBongis it possible to chat with clojurebot?
12:20iBong,(println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
12:20hiredman~a man of means by no means
12:20clojurebotjava.security.AccessControlException: access denied (java.lang.RuntimePermission getClassLoader)
12:20clojurebotda da king of the road
12:22iBongdoes he just have clojure.jar and clojure-contrib.jar? just wanted to see what libraries he can load
12:37jwhitlarkIs anyone working on packaging clojure for ubuntu?
12:38stuartsierraIt's still developing rapidly, OS packages would have a hard time keeping up..
12:39jwhitlarkDo you think a stable package every six months is not enough to keep up?
12:39stuartsierraI actually don't see much need. It's just a JAR, after all.
12:39iBongubuntu has a hard time keeping up with emacs
12:43jwhitlarkI think it would depend more on the maintainer of the package. Once it's there, clojure-mode can be handled also, and I think it lowers the barriers to entry, as well as opening the possibility of having apps written in it in the repos.
12:43weissjhow much of clojure's devices like agents, atoms, refs, make sense to use with db-backed data?
12:43jwhitlarkI'm just trying to get a feel for people's opinion; I was considering doing it myself.
12:44iBongwhat would the package do? download the jar, export a few paths, and make a clj bash script?
12:45iBonga clojure mode for gedit would be nice
12:45jwhitlarkit would have the 1.0 jar in it, or the latest bug fix, then yea, export paths, add some docs, and the bash script.
12:46jwhitlarkI'd also like a script to build a jar containing clojure, but I haven't looked into it yet. I expect there is a solution already out there.
12:46ChouserI think it'd be fantastic to have an ubuntu pkg that would let someone do: apt install clojure; clj ...and have a prompt.
12:46iBongis clojure on git?
12:46jwhitlarkit is now.
12:46iBongcould make a script that just clones the most recent version and sets up the pathsd
12:47iBongwouldn't be too much work
12:47ieureChouser, There’s a Debian package for it already, dunno if it’s in Lenny though.
12:47jwhitlarkhttp://groups.google.com/group/clojure/browse_thread/thread/a57be34382e047db
12:47jwhitlarkah, I hadn't seen that.
12:47ieureChouser, http://packages.debian.org/squeeze/clojure
12:48iBonggetting slime to work was more effort than I thought it should be, would be nice if the script could manage that too
12:48jwhitlarkIt is *possible*
12:48replacaChouser: fill-queue will be pressed into use immediately to replace custom java interop in my webhook processor. I was just too lazy to write it so cleanly.
12:49jwhitlarkI'm not sure how much work it would be. I've not done a great deal of packaging, and the emacs packages are interesting.
12:50Chouserreplaca: cool! It's a minor refactoring of code from lazy-xml that was written simultaneously with seque
12:50ChouserI needed it for a 3rd time yesterday, so I took the time last night to clean it up.
12:50iBongthe ides might be best left to readmes, setting up the basic clj script is pretty straightforward
12:51Chouserreplaca: are the names ok? That's always the worst part for me...
12:52replacaChouser: yeah, I was thinking I should write it when I was building my webhook, cause it's obviously a problem that comes up all the time and you want a "primitive" for it, but I've been a little scatterbrained lately so I procrastinated that part
12:52replacaChouser: names look ok. after I throw it in the program, I'll give you feedback if it doesn't feel right
12:53Chousergreat, thanks.
12:54Chouserit probably needs more docs somewhere too -- a few features are undocumented, and at least one potential "gotcha" with the thread hanging around...
12:59mebaran151does clojur ehave a decimal type of any sort?
12:59mebaran151other than ratio?
12:59ChouserIt has all the Java numbers: Integer, Double, BigInteger, etc.
12:59Chouser,(class 5M)
12:59clojurebotjava.math.BigDecimal
12:59mebaran151no I meant in addition
12:59iBongare there any JSON rpc clojure projects?
13:00Chousermebaran151: I think Ratio is the only extra number class Clojure provides.
13:00mebaran151okay thanks
13:01mebaran151iBong, I sort have some json rpc going on
13:01mebaran151I rolled by own using compojure: it wasn't too bad
13:01iBongyeah that's what I'm looking at doing
13:04iBongwould be nice if there was one in contrib, if compojure could make an instant restful json rpc server (insert custom domain logic here) Im not sure if I would use rails anymore
13:07iBongmebaran151: your implementation isn't in a repo by any chance is it?
13:07mebaran151not yet
13:08mebaran151it's gotta be cleaned up
13:08mebaran151it's not very general either: it powers a javascript scripted webscraping proxy
13:08mebaran151so it works, but only for ONE thing
13:09mebaran151then again, writing a restful service in compojure was really easy, and reading the JSON was trivial
13:09iBongI want to make a generic json rpc backend for javascript ria frontends
13:10iBongif clojure could generate all the javascript too...
13:10mebaran151I mean how would you decide which function to call?
13:10mebaran151other than by stating the url etc etc
13:10mebaran151it's not ike clojure has classes that you dispatch against
13:10iBongcould use a hashtable
13:11iBongthe server can just register any functions they want to expose
13:11mebaran151that wuld work, but I don't think naive rpc is that big a win
13:11mebaran151but compojure lets you do that by letting you supply the callback for what url you hit
13:12mebaran151I guess the win would be not having to define the routes yourself, but I found that the quickest part of the job
13:12mebaran151getting Rhino to play nice on the other hand.
13:12mebaran151:|
13:12iBongif you have a big database you want to expose, it would be nice just to have everything in a hashmap, but youre right that its not so hard to roll your own
13:13mebaran151I'm actually working son something similar to that right now on top of berkeley db
13:13mebaran151trying to build a lazy hash
13:14mebaran151lazy sorted hash with look ahead
13:15mebaran1512 week project
13:16iBongit all sounds very interesting
13:32alrex021in clojure, how would I iterate over a list and print each item on a new line in repl output?
13:33alrex021I see take function, iterate, etc...not to sure how to put it together.
13:33stuartsierra(doseq [x the-list] (println x))
13:35alrex021stuartsierra: thx, doseq macro was what I was after...learning bit by bit :)
14:00alrex021clojure.contrib.test-is doesn't seem to be available in my emacs env but clojure.contrib.duck-strams is. I have installed the contrib jar via emacs elpa.
14:01alrex021am I missing something?
14:01stuartsierratest-is moved to clojure.test recently
14:09stuartsierraSo either get the latest Clojure core sources with the latest contrib sources, or get Clojure 1.0 and the clojure-1.0-compatible branch of contrib.
14:11alrex021I installed clojure via emacs elpa which connected to github to get latest
14:11alrex021funny enough doesn't seem to have clojure.test
14:12stuartsierraWhat does (clojure-version) report?
14:13alrex021"1.1.0-alpha-SNAPSHOT"
14:13stuartsierraok, then you should be able to (require 'clojure.test)
14:13alrex021r you sure its not clojure.core.test?
14:13stuartsierrayes
14:13stuartsierra,(require 'clojure.test)
14:13clojurebotnil
14:13stuartsierra,(the-ns 'clojure.test)
14:13clojurebot#<Namespace clojure.test>
14:13alrex021oh I see
14:14alrex021ok, ot works
14:14tomojI have clojure.contrib.test-is in my elpa-installed clojure
14:14stuartsierraThen you probably have an older copy of contrib.
14:15tomojwhich is odd, since I just installed it a couple days ago
14:15alrex021member:stuartsierra: is there a way to view all functions within a package? (like dir() in python)
14:15stuartsierrayes
14:15stuartsierrabuiltin core function is ns-interns
14:15stuartsierra,(ns-interns 'clojure.test)
14:15clojurebot{deftest- #'clojure.test/deftest-, join-fixtures #'clojure.test/join-fixtures, *initial-report-counters* #'clojure.test/*initial-report-counters*, assert-predicate #'clojure.test/assert-predicate, default-fixture #'clojure.test/default-fixture, testing-contexts-str #'clojure.test/testing-contexts-str, deftest #'clojure.test/deftest, *testing-vars* #'clojure.test/*testing-vars*, is #'clojure.test/is, testing-vars-str #'clo
14:16stuartsierrathen in one of the contrib libraries, maybe it's c.c.repl-utils, there's a function that prints names & documentation
14:16alrex021thx, that'll help me navigate since I'm new to clojure
14:16Chousukefind-doc is useful too
14:16tomojso if I want to upgrade, I just should go with the master branches of both repos?
14:16stuartsierrayes
14:16tomojalright, thanks
14:19alrex021stuartsierra: clojure.test there is no 'is' function ...(is (= 5 (+ 2 2)))
14:22alrex021hmm, sorry, pls ignore last comment of mine
14:27iBongif you have a collection of predicates like [#(< %1 10) #(> %1 5) ...] what's the most idiomatic way to apply them to some value x while it returns true ?
14:29hiredman,(take-while true? (map #(% v) predicates))
14:29clojurebotjava.lang.Exception: Unable to resolve symbol: v in this context
14:29Chouseralso note you could write the two you showed as a single #(< 5 % 10)
14:30iBongah, actually using regexes, but take-while seems to be what I'm after
14:30iBongmerci
15:05iBong,(empty? (filter #(false? %) (map #(< % 10) (range 20))))
15:05clojurebotfalse
15:05iBongmore idiomatic way to do this?
15:06hiredmanwell
15:07hiredmanfirst off you can just say false?
15:08iBongok, second off?
15:08Chouser,(every? #(< % 10) (range 20))
15:08clojurebotfalse
15:08iBongah, that's much better
15:39replacaWow: http://github.com/richhickey/clojure-contrib/commit/2d2c2003325cb5e38a7a984d5d349c12d8dafa4d#L0R175
15:39iBongI think I'm beginning to understand the Matz (para)quote "Ruby is like Lisp for normal people"
15:40replacaChouser combines Clojure-Fu and Java-Fu so you don't have to! I learn stuff every time I read your code, Chris.
15:40replaca(even when I thought I already knew it :-))
15:40Chouserreplaca: heh, thanks. Rich was doing a lot of hand-holding as we hammered out the original forms of that.
15:41ChouserMaybe I should have put his name in there too.
15:41ChouserI was just afraid my changes were wrong and wouldn't want him blamed.
15:44Chouserhm, yeah, I should definitely fix the attribution.
15:44Chouserhttp://paste.lisp.org/display/63224
15:47replacaI looked at seque for what I was doing, but it didn't seem to fit together with Ring's model of the universe quite right.
15:47Chouserhttp://groups.google.com/group/clojure/browse_frm/thread/e7f4de566eddb6ea
15:49Chouserwow, that's over a year old
15:51replacawe're all growing up here! :-)
15:51ChouserI guess I should have reviewed the old discussions before releasing this version.
15:52Chouserpassing in 'fill' like I do now is definitely better than binding *enqueue*
15:53cemerickrhickey: do you happen to know how dlw is planning on contributing to clojure?
15:53Chouser"rhickey: Chouser: I did a lot of testing and was frustrated by the unpredictability of weak-ref reclamation" -- http://clojure-log.n01se.net/date/2008-07-02.html#14:36
15:55rhickeycemerick: I wouldn't want to speak for him, because he's very busy, but I think he's interested in getting together a more formal definition of Clojure, starting with a glossary of well-defined terms
15:55cemerickwell, he's certainly got a body of work in that area
15:56replacaChouser: yeah, I think I like it that way too. When I have it hooked up with Ring, I'll post the code and we can discuss
15:56cemerickI was really happy to see him pop up on the assembla notification.
15:57replacaChouser: I had some good luck with WeakRef stuff when I was using it a few years back, but that was under very high churn which probably pushed it to be more predicatble.
15:59Chouserreplaca: if you consume the seq fully, the weakref never comes into play
16:00replacaChouser: yeah, I see that. But it's good for an infinite seq, you can abandoned it and the thread will die on the next event.
16:00ChouserI think it's a sane use of weakref -- the thread and any resources its holding on to will all be gc'ed when/if the lazy seq itself is gc'ed.
16:00replacaMight be even better if the thread would die before that.
16:01ChouserThe thread will die within 1 second of the seq being gc'ed
16:01replacaYup, that's pretty much what WeakRef's are for. I'd say it's a very appropriate use.
16:03replacaChouser: but if fill is unpredicatably slow (waiting for a request from the net, for instance), the thread won't get closed up until the next time that fill is called, right?
16:04Chouseroh, I see what you're saying. yes, that's right.
16:04rhickeyChouser: could scopes solve your cleanup problems?
16:05ChouserI just meant that once the thread is blocking on filling the queue, no further 'next's are required to get the thread to go away.
16:06tomojwhat would be a good way to grab the n smallest elements of a lazy seq?
16:06Chouserrhickey: I think so. The filling thread could register a :finally or whatever it's called, and try to kill itself off. Still messy, but more predictable.
16:06Chousertomoj: (take n my-seq) ?
16:06hiredmantomoj: you're going to have to sort the list
16:06rhickeyChouser: finalizer?
16:06Chousertomoj: oh, sorry, I understand...
16:07tomojhiredman: but you don't have to sort the list to actually do it at a low level. you can just iterate through once keeping track of the n smallest
16:07Chousertomoj: but what if all the smallest are at the far end?
16:08rhickeyChouser: also, is this interesting for this problem?: http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166ydocs/jsr166y/LinkedTransferQueue.html
16:08hiredmantomoj: I imagine you will find the lower bound of that operation to be exactly the same as sorting
16:08tomojChouser: the idea is that you only do the iteration once and you already know how much you'll want
16:09tomojhiredman: maybe, but it's too much to store in memory
16:09hiredmantomoj: I would start looking for "lazy" sorting algorithms
16:10tomojthanks
16:10Chouserrhickey: I don't know what you mean by "finalizer". I was thinking of :exits http://paste.lisp.org/display/73838
16:10hiredmanif you have the nth element of a list, how can you tell if it is one of the i smallest elements?
16:10rhickeyChouser: ok, fine
16:11hiredmanit seems like you have to walk through the whole list
16:11tomojI don't mind walking through the whole list, I just don't want to have to store the whole sorted list in memory
16:11Chousertomoj: ok, *now* I understand... :-) you're okay with walking the whole list, you just want to retain no more than n in memory at once
16:11Chouser:-)
16:12hiredmanactually
16:12tomojI was thinking I could keep a sorted seq with the smallest n so far, then add to it, sort, and cut off whatever gets pushed out
16:12hiredmanyeah
16:12hiredmanthat makes sense
16:12tomojwhich sounds inefficient but I suspect it won't matter since finding a new low will be very rare
16:13hiredmankeep an n sized vector
16:13Chousersorted-set
16:13rhickeyyes, please
16:14rhickeythis sounds familiar though
16:14hiredmanif finding a new low is rare, a sorted list maybe a better choice then a vector
16:15tomojhrmm, I stated the problem a bit incorrectly
16:16tomoja sorted anything won't work because the values I'm keeping track of aren't the ones being compared for sorting
16:16tomojwhich means I'll need to keep track of both the n elements and their sort values :(
16:16hiredman:|
16:16Chouserrhickey: I think LinkedTransferQueue would work but not be better than using a LinkedBlockingQueue. I'm not sure though that I fully understand the purpose of LinkedTransferQueue
16:17Chousertomoj: sorted-map ?
16:17Chouseror a sorted-set of vectors
16:18Chousertomoj: your input is a seq plus a fn for computing the sort value of each element?
16:18tomojChouser: sorted-map seems like a good idea
16:18tomojthe more I think about it the more I realize that it's harder than I thought :)
16:19tomojbut actually, yes, a seq plus a fn for computing the sort value
16:20tomojproblem is I have to do that sort for every element in the seq. so O(n^2)
16:20Chouserwhat!?
16:20Chouserwhich sort?
16:20Neronustomoj: cache it. (map #([(f %) %]) list), and traverse that list
16:20rhickeytomoj: http://groups.google.com/group/clojure/msg/3101ff5ea37cd79b
16:22tomojChouser: the sort isn't O(n^2), the problem is I have to do this "find the top k" n times
16:22rhickeyman, ggroup search doesn't even go back a month :(
16:22tomojrhickey: thanks
16:22tomojwill take me a while to figure out what the heck that function does, I imagine :)
16:32tomojlooks like that does some dup tracking I don't need, it's a good start, thanks again
17:01lbj~seen blackdog
17:01clojurebotno, I have not seen blackdog
17:03hiredman~max people
17:03clojurebotmax people is 149
17:04jwhitlark~help
17:04clojurebothttp://www.khanacademy.org/
17:04iBong,(println 'woot!')
17:04clojurebotUnmatched delimiter: )
17:05jwhitlarker. that wasn't quite what I was expecting. interesting though.
17:06hiredmanjwhitlark: no single quoted strings
17:06hiredman' is (quote …)
17:06jwhitlarkI mean the link for ~help.
17:06Chouserthat was iBong
17:06jwhitlarkbut thanks.
17:07hiredmanit sure was
17:07jwhitlark,(+ 2 2)
17:07clojurebot4
17:08jwhitlarkI think they've turned off some of the fun: http://clj.thelastcitadel.com/clojurebot
17:08hiredman(+ 2 2)
17:08clojurebot4
17:08iBong,(println ":x")
17:08clojurebot:x
17:08hiredman(+ 2 3)
17:08clojurebot*suffusion of yellow*
17:09hiredmanI could have sworn I removed that
17:09hiredmanthree or four times even
17:09jwhitlarkoh, is clojurebot yours?
17:09jwhitlarkheh, sorry, I had your git repo open in a tab I hadn't looked at yet.
17:09mrsoloemacs 23..safe to upgrade as far as slime/clojure concern?
17:09hiredman:P
17:10Chousukemrsolo: works for me.
17:10mrsolonice
17:11ChousukeMoved away from aquamacs because it was buggy :/
17:11jwhitlarkhiredman: how much work do you think it would be to port clojurebot to jabber?
17:11mrsolowell
17:11mrsoloaquamacs habit is hard to kick
17:11mrsoloi am so used to apple-f-l-s ...
17:12hiredmanjwhitlark: it depends
17:12hiredmanit would be great if I could find a pircbot equiv for xmpp
17:13jwhitlarkhmmm.
17:14Chousukejwhitlark: I might give Aquamacs 2.0 a go when it's ready. apparently it's based on emacs.app
17:14hiredmanat one point I had the repl hooked up to twitter, but that never worked reliably for want of testing
17:14ChouserI'm looking forward to clojurebot on wave
17:14jwhitlarkChousuke: I tried a mac for 6 months at work, but in the end went back to linux on a thinkpad.
17:16mrsoloeither one is fine with me
17:17hiredmanthe only java xmpp lib people use seems to be smack, and I am not a huge fan
17:17jwhitlarklong as it's *nix, I've no problems, really.
17:17ChousukeI'd probably use Debian or something but OS X still works somewhat better overall. Particulary the dictionary in Leopard is great.
17:17jwhitlarkis that the one from the openfire people?
17:18jwhitlarkIf the new machines had been out at the time, I might still be using it...
17:18hiredmanyeah
17:19jwhitlarkor if I could have gotten a newer air.
17:19jwhitlarkhiredman: I tried that a little bit, but I was doing most of my xmpp stuff in python.
17:21jwhitlarkclojurebot: def true?
17:21jwhitlarknice.
17:21hiredmanI think xmpp is the one place I feel let down by java libraries
17:22jwhitlarkI could see that.
17:22jwhitlarkI've been working with zookeeper lately through the java libraries, and it's awesome.
17:22jwhitlarkonce I figured out you need to specially import inner classes.
17:22hiredmanheh
17:23technomancyjwhitlark: what are you using zookeeper for?
17:23jwhitlarkI *really* like Stewart's book, but that wasn't in there, AFAIK.
17:23baetis-flyis there a way to do static imports of classes?
17:24jwhitlarktechnomancy: it's complicated, well, poorly defined at the moment.
17:24jwhitlarkbasically ad-hoc group membership of machines and making services available.
17:25hiredmanbaetis-fly: I don't think so
17:25hiredman"So when should you use static import? Very sparingly!"
17:26baetis-flyi agree, it's lame, but i'd like to sneak some clojure into work by using waitForState.sh
17:26jwhitlarkI like zookeeper very much so far.
17:26baetis-flyerr, http://watij.com/wiki:quick_start
17:26baetis-flycan't seem to instantiate an IE
17:27jwhitlarkI was thinking of doing a quick talk on it at the next ba-clojure meetup. I've not been using it long though...
17:31jwhitlarkhiredman: what's the deal with make 7-?
17:32jwhitlark(looking at clojurebot's brain)
17:32hiredmanits from a 7-UP tv ad
17:33hiredmanhttp://www.youtube.com/watch?v=WsMFZBDIcFs Make 7 … UP YOURS
17:33jwhitlarkoh, I was wondering if it was an obscene emoticon I hadn't come across ;-)
17:33jwhitlarkput that way...
17:34jwhitlarkhiredman: you put some fun stuff in here...
17:34hiredmannot all me
17:36hugzbunnyhello i wanted to know if there is some way to get the full text of a function
17:36hiredmanclojurebot: how can the common lisp hyperspec help us through these troubling times?
17:36clojurebotlisp is the red pill
17:36hiredman:/
17:37hiredmanclojurebot: how can the hyperspec of common lisp help us through these troubling times?
17:37clojurebothyperspec is not applicable
17:37hiredman~def source
17:37hiredman(doc source)
17:37clojurebot"clojure.contrib.repl-utils/source;[[n]]; Prints the source code for the given symbol, if it can find it. This requires that the symbol resolve to a Var defined in a namespace for which the .clj is in the classpath. Example: (source filter)"
17:43hugzbunnyhmmff.. CompilerException java.lang.ClassNotFoundException: clojure.contrib.repl-utils .. any ideas?
17:44Chouser(use 'clojure.contrib.repl-utils)
17:44Chouserof course you have to have contrib in your classpath somewhere first
17:46hugzbunnybtw im very new to clojure so please could explain to me where i add new paths to my classpath?
17:46hiredmanhugzbunny: how are you launching clojure?
17:46hugzbunnynetbeans
17:47hiredman:|
17:47hugzbunnyhehe
17:48hiredmanI imagine netbeans has some kind of project classpath setting
17:48hiredmanbut I don't use netbeans
17:50hiredmanhttp://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#q-and-a "I need to add a library JAR from outside the NetBeans installation"
17:52iBongwill enclojure become a standard netbeans plugin in the near future?
17:53alrex021I've had a look at enclojure, looks promising, but becoming a standard plugin in the near future, I don't think so.
17:54hugzbunnyhiredman: thanks i will look into it
17:54iBongI couldn't get it to work
17:54iBongor rather, the repl didn't work at all
18:13dnolenhugzbunny: are you using enclojure? If so you can just add the clojure-contrib.jar to your project
18:13dnolenyou don't need to mess with your classpath at all.
18:24hugzbunnyhello dnolen, how do i do that?
18:29akhudekI find that I'm often writing loops like this http://paste.lisp.org/+1T87
18:30akhudekis this really a common pattern?
18:31akhudekI dont' have a lot of experience actually writing lisp yet, so I'm concerned I'm doing things in the wrong way.
18:31akhudekin other words, is there a more concise way to process over lists like that?
18:31Chousukemap?
18:31Chousukeredue?
18:31Chousukereduce*
18:31ChousukeI can't quite figure out what that does.
18:32akhudekprobably reduce would be closes
18:32akhudekerr closest
18:32akhudekit just iterates over elements of the seq
18:32hiredman,(doc reduce)
18:32clojurebot"([f coll] [f val coll]); f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the r
18:32hiredman,(doc doseq)
18:32clojurebot"([seq-exprs & body]); Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil."
18:32Chousukeakhudek: iterates over them doing what?
18:32akhudekand does some processing on them that requires some state
18:32hiredmansounds like reduce
18:33akhudekin this case I'm converting a list like (1 sizeA) (2 sizeB) (1 sizeC)
18:33hiredmanclear as mud
18:33akhudekto ranges that are ((0 sizeA-1) 1) (sizeA (sizeB-1 + sizeA) 2) ...
18:33Chousukebtw. instead of (if (empty? remaining) ...) the clojure idiom is (if (seq remaining) ...)
18:34Chousukeseq returns nil for empty sequences
18:34akhudekah, ok
18:34hiredmansounds like reduce
18:34hiredmanactually
18:34akhudekyeah, I suppose that would be cleaner, although the result object would need to carry the stat with it
18:34hiredmanyou could do it with map
18:35akhudekhow so?
18:35akhudeksince you need the sum of all previous sizes
18:35hiredmanyou just map over two lists
18:35akhudekand compute the sizes in a separate list
18:35akhudekright
18:35hiredmanthe two lists identical except the second list has a dummy first entry
18:36akhudekhmm, maybe I'm not following then
18:36hiredmaneasier just to use reduce
18:37Chousuke,(reduce (fn [[state acc] item] [(inc state) (str acc state item)]) [1 ""] '[foo bar zonk])
18:37clojurebot[4 "1foo2bar3zonk"]
18:38akhudekhm, ok thanks
18:38akhudekthat makes sense
18:38Chousukereduce really is versatile :)
18:39lpetitakhudek: the definition you gave in your lisppasted code does not just "look like" reduce, to me it is reduce constrained to have its first accumulator value be an empty list
18:40akhudekok, I figured I was doing something wrong
18:41Chousukewell, when learning a language pretty much everyone reinvents half of the wheels at first :P
18:41akhudekyeah, it takes a while moving from C++ to a functional language
18:41akhudekbut the amount of repetition in that loop construct I pasted had me suspicious, I guess for good reason
18:43lpetitwelcome on a long journey !
18:44akhudekthanks :)
18:44lpetityou know, we're not that ahead in front of you, it's just that for you everything seems a little bit foggy right now, so you can't see ur just 2 steps from us ;-)
18:45lpetitif at all
18:46akhudekI did think of using reduce, but what I didn't realize is that you can bind as Chousuke showed (fn [[state inc] item] ... )
18:46akhudekI didn't want to be stuck in (first ..) (second .. ) land
18:47lpetitmake first $(CLOJURE_HOME)/src/clj/clojure/core.clj your friend. Not because there is some lack in the documentation, but first because it is plain of functional wisdom :-)
18:47lpetitoh yes
18:47akhudekok, I'll take a look at some of the implementations :)
18:48lpetitok, enough of me being pedant, and it's also time to go to bed for me, here in France ! (almost 1 am). cu
18:56lisppaste8iBong pasted "maintainable?" at http://paste.lisp.org/display/84536
18:57iBongtrouble reading my own handwriting... hoping for suggestions on style, idioms
18:58ChousukeiBong: #(if % true) == identity
18:59Chousukealso (if foo bar nil) -> (when foo bar)
19:01Chousukebut hmm
19:03Chousuke,(let [coll {"foo" 1 "bar" 2 "foobar" 3}] (map coll (filter #(re-matches % "foo") (keys coll)))
19:03clojurebotEOF while reading
19:03Chousuke,(let [coll {"foo" 1 "bar" 2 "foobar" 3}] (map coll (filter #(re-matches % "foo") (keys coll))))
19:03clojurebotjava.lang.RuntimeException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.regex.Pattern
19:04Chousukehmm
19:04Chousuke,(let [coll {#"foo" 1 #"bar" 2 #"foobar" 3}] (map coll (filter #(re-matches % "foo") (keys coll))))
19:04clojurebot(1)
19:05iBongah
19:05Chousukeclojure maps are functions, which is nice :)
19:06iBongyeah, its funny I was using that to return the value but it didnt occur to me use the map with map
19:06iBongthat makes me very happy, thank you
19:41uninverted"(do (print "foo") (read))" reads before printing. WTF? I thought pascal showed us how confusing and limiting this was.
19:58JAS415,(do (print "(+ 1 2)" (read))
19:58clojurebotEOF while reading
19:59tomojpascal didn't show me anything
19:59JAS415,(do (read (print "(+ 1 2)")))
19:59clojurebotjava.lang.NullPointerException
19:59Chousukeprint returns nil :P
19:59JAS415print returns nil
20:00JAS415,(do (print "foo") (read))
20:00clojurebotExecution Timed Out
20:00JAS415hmm
20:00JAS415oh
20:00JAS415duh
20:01JAS415it prints foo and waits to read something
20:01tomojno, that's the point
20:01tomojit waits to read something, then prints foo
20:02JAS415,(print "foo")
20:02clojurebotfoo
20:02JAS415hmm
20:02JAS415that is really weird
20:05Chousukeah, I know why it happens
20:05Chousukeit's buffered.
20:06Chousuke(do (print "foo") (flush) (read)) works as expected
20:07tomojstrangely it works in my slime repl
20:07tomojwithout flushing
20:08tomojspeaking of, does anyone know why my minibuffer is displaying the value of variables?
20:10tomojlike I do (count *foo*) where foo is a big map, and it takes forever because it tries to display the value of *foo* in the minibuffer
20:11tomojbut only sometimes...
20:12rhickey,(str (new [] (toString [] "hello")))
20:12clojurebot"hello"
20:13tomojturning eldoc off seems to solve it, will investigate there
21:13tomojwhat's wrong with (sorted-map-by #(> (val %1) (val %2))) ?
21:13hiredman,(doc sorted-map-by)
21:13clojurebot"([comparator & keyvals]); keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator."
21:14hiredman,(sorted-map-by #(> (val %1) (val %2)))
21:14clojurebot{}
21:14hiredman,(assoc (sorted-map-by #(> (val %1) (val %2))) :foo 1)
21:14clojurebot{:foo 1}
21:14hiredman,(assoc (sorted-map-by #(> (val %1) (val %2))) :foo 1 :bar -1)
21:14clojurebotjava.lang.RuntimeException: java.lang.ClassCastException
21:15tomojsame result here :(
21:15hiredman,(assoc (sorted-map-by #(> (prn %1) (val %2))) :foo 1 :bar -1)
21:15clojurebotjava.lang.RuntimeException: java.lang.ClassCastException
21:15hiredman,(assoc (sorted-map-by #(do (pr %1) (pr %2) -1)) :foo 1 :bar -1)
21:15clojurebot{:bar -1, :foo 1}
21:15clojurebot:bar:foo
21:15hiredmanso keys are what are passed to the comparator
21:16tomojwell crap
21:16tomojguess I will sort at the end
21:16tomojthanks
22:06JAS415is there a 'group' function in clojure?
22:07mebaran151like partition?
22:07JAS415like partition except by number of groups
22:08JAS415i guess i can use partition and math but i seem to lose the last few with partition
22:10mebaran151you mean something like divide an array into 4 pieces or something?
22:14hugzbunnyi have downloaded the clojure-contrib thing from github and added it to my classpath in enclojure, but to no avail - i can't use it. any suggestions?
22:15JAS415well what i'm doing is splitting a string into tokens, interleaving every x tokens with a "<br/>"
22:15JAS415so is like that but I'm doing arbitrary number of chars in the string and a fixed chars per line
22:16JAS415but i don't want to break the words up
22:19_mstin clojure.contrib.seq-utils there's a "partition-all" that doesn't drop the last few elements
22:19JAS415ah cool
22:19JAS415thanks :-)
22:20_mstno worries :)
22:43JAS415bah
22:43JAS415this makes no sense
22:43JAS415my header is
22:43JAS415(ns chickadee
22:43JAS415 (:require clojure.contrib.seq-utils))
22:44JAS415however i load the file
22:44JAS415nvm i know what it is
23:41iBongis there something like each-with-index?
23:43iBong(doc index)
23:43clojurebot"/;nil; "
23:44Chouser,(indexed [:a :b :c])
23:44clojurebot([0 :a] [1 :b] [2 :c])
23:46iBongty
23:46Chouser,(for [[i x] (indexed [4 4 4 10])] (+ i x))
23:46clojurebot(4 5 6 13)
23:46iBongwas about to try
23:47Chouseroh, and that's from contrib
23:47Chouser, #'indexed
23:48clojurebot#'clojure.contrib.seq-utils/indexed