#clojure logs

2010-07-19

00:01technomancyslyrus: just use uniquify
00:01technomancyhang on
00:02technomancyslyrus: (require 'uniquify) (setq uniquify-buffer-name-style 'forward)
00:02technomancykeeps your sanity
00:02technomancyanyway, you symlink the whole directory into the checkouts dir
00:03technomancyoh yeah; what he said
00:11nathanmarz, (binding [+ - - +] (+ 1 2 3))
00:11clojurebot-4
00:11nathanmarzoddly, i get "2" when i run it in my repl
00:14IRCMasterwhy does (class set!) throw an exception: Unable to resolve symbol: set! in this context
00:15rhudsonit's a special form
00:16IRCMasterI was originally trying to (map !set ...) in order to set a bunch of instance fields at once
00:17IRCMasteris there an easier way, than one at a time?
00:17rhudsonYou'll need to map #(set! %1 %2)
00:31IRCMasterhi, one more question.. what is the #(...) form called, as given a few lines back by rhudson? I'm trying to look up documentation but don't know what to search on
00:36brehautIRCMaster: http://clojure.org/reader look at Dispatch, its a reader macro for an anonymous function literal
00:38IRCMasterexcellent, thanks!
00:49slyrushow can I get things printed like slime does at the repl (i.e. with line breaks and nice indentation, instead of all one line)?
00:53technomancyslyrus: (use 'clojure.pprint) (pprint (range 99))
00:53technomancyor clojure.contrib.pprint for older clojures
00:54slyrusoh, that's nice!
00:56technomancyportrait orientation rules
01:25slyrusif anyone wants to hack on a library for representing undirected graphs (and maybe digraphs soon), shortcut can be found here: http://github.com/slyrus/shortcut
01:43replacaslyrus: pprint is still not that fast, so sometimes one regrets it when one uses it at the repl :-)
01:44replacabut I should make some instructions for doing it - it's not too hard.
01:46TakeV(doc format)
01:46clojurebot"([fmt & args]); Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax"
03:03raekwhoa! checkout dependencies in the new Leingingen sounds awesome!
03:05TimMcWhat's this now?
03:06raekif one of you projects that you are working on depends on another that you work on too
03:06raekyou can now make the dependent project use the project directory of the other one directly
03:07raekno need to build jar files, copy to the dependent project, lein deps, lein swank
03:07raekthe checkouts/ directory contains symlinks to the other projects
03:08raekleiningen then adds the classpaths of all those projects into the current one
03:09TimMcHmmm...
03:09TimMcReminds me of svn externals, which sounded like a great idea but turned out to be a load of trouble.
03:09tomojthat does sound nice
03:10tomojpain to have to startup a new swank server to fix a bug in some other project, then another new swank server to verify the fix works in the original project
03:11TimMcSpecifically, when you have a couple version branches of project A that depend on different versions of project B, it's a mess.
03:16Licenser_morning
03:17slyrusraek: yes, this was one of the big things that I was afraid I was going to miss from using CL/asdf
03:18slyrusin fact I couldn't really see the point of leiningen without this sort of thing :)
03:18Licenser_I've a problem compiling some clojure code :( use works but not compile it says something like Runtime
03:19Licenser_Exception: ClassNotFoundExceptopn bla.bla.bla.core$loading__5166_auto____1253
03:19Licenser_has anyone encountered something like that?
03:26slyrushmm... I'm not familiar with the proper clojure terminology, but it seems that protocols aren't "exported", i.e., I need to do (shortcut.graph.Graph. #{} {}) instead of (Graph. #{} {}) even though I'm using the ns and I can call non-fully-qualified functions.
03:38Licenser_problem solved, updateing to clojure 1.2b1 helped :)
03:55tomojslyrus: they're not functions anymore
03:55slyrustomoj: not sure what you mean
03:56tomojused to be when you did defrecord/deftype Graph, you'd get a constructor function named Graph, but no longer
03:56tomojthey're java classes so you have to import them like other java classes
03:57slyrusoh, I think I get it
03:57slyrushrm... I'll have to figure out how to do this cleanly in the morning then.
03:59tomoj(ns ... (:require [shortcut.graph :as graph]) (:import shortcut.graph.Graph))
04:23esjhappy monday y'all
04:23raekI think it's pretty common to make one's own constructor functions
04:23raekthat way, one can have default values for fields, etc
04:24raekbut I guess that all this depends on whether the use of records is an implementation detail of the lib or not
04:28esjraek: that's certainly how I've done it.
05:35yasonIs the "core.clj" name just a leiningen convention or something dictated by Clojure?
05:35mikemyason: it's a leiningen thing afaik
05:37yasonmikem: just a convention or can't be changed?
05:39TimMcI think leiningen just sets it up as a default.
05:39mikemyason: you can change it, i think it's just the default directory layout leining creates
05:39TimMcIn your project.clj you can specify whatever main file you want.
05:39TimMcs/file/class/?
05:39sexpbotTimMc: Format is sed [-<user name>] s/<regexp>/<replacement>/ Try $help sed
05:39yasonok, thanks for the information
07:33bortrebis there some way to change the print function the repl uses to my own generic version?
08:09bortrebnm -- I found that I can just do (defmethod print-method <my-class> ..)
08:13lpetitericthorsen: hi, you there ?
08:36lpetiterichthorsen: nevermind, I've transformed what started like a man-to-man brainstorming into a (hopefully) community brainstorming in the ml
09:45xcthulhuI've been looking at ADTs in clojure and I have two questions: (1) Are ADTs still in proof of concept phase, or can they be used in production code? (2) The mathematically, there are two ways to define ADTs - inductively and coinductively. Coinductive ADTs are lazy data structures - do ADTs for clojure make this distinguish between whether they've been defined inductively or coinductively?
09:46xcthulhuerm /distinguish/distinction/
09:46Licenser_xcthulhu: what are ADT's?
09:47opqdonutalgebraic data types
09:48Licenser_opqdonut: you mean native variables and litterals?
09:50opqdonutno
09:50opqdonuthe means stuff like "data Tree = Node Tree Tree | Leaf"
09:51opqdonutlike what clojure.contrib.types offers
09:51opqdonuthttp://github.com/richhickey/clojure-contrib/blob/master/src/main/clojure/clojure/contrib/types.clj
09:52xcthulhuLicenser Algebraic Data Types
09:52cemerickVery rarely used. The deftype collision is unfortunate.
09:53xcthulhucemerick, It's a the way of life in ML, Haskell, Isabelle/HOL, and Coq
09:53xcthulhuless so in Coq I suppose
09:54opqdonuti guess he meant the clojure library is rarely used
09:54Licenser_oh okay then I've no clue, I'm sorry xcthulhu
09:55xcthulhuLicenser, NP it's a bit of a silly question.
09:58xcthulhuOutside of the ivory tower you don't see people programming with ADTs all that often, so I don't think support for them should be a priority for clojure
10:00Hodappand you do NOT want to get into an ivory tower war with a Lisp... you will most certainly lose.
10:00xcthulhuHodapp, What do you mean?
10:01cemerickxcthulhu: yes, I only meant that c.c.types is rarely used
10:01cemerick(at least in the various clojure libs I've seen, anyway)
10:02cemerickPeople writing data structures in clojure should be using core's deftype. Anything defined otherwise is not going to have the performance one would typically expect in that domain.
10:03cemerickNow, if someone were to macro on top of core's deftype with stuff to support ADT-like constructs, that could get interesting.
10:48AWizzArdrhickey: currently the Clojure compiler uses a comfortable naming scheme to produce its output files (.class). Will you gurantee that this naming scheme will survive also in future?
10:49AWizzArdI ask because I use this for Ant jar tasks. I compile the whole utils/ folder, but only include those in the .jar that the end customer is supposed to get.
10:49AWizzArdCurrently I can easily work with * wildcards, and it's working nicely.
10:53slyrusah, thanks tomoj. so I need to do that with records (and protocols)?
11:20rhickeyAWizzArd: no guarantee there
11:29cemerickinteresting that "clojure prepend vector" is the #1 suggested query when I type "clojure" into my FF search field
11:30TeXnomancycemerick: I think those are personalized depending on your search history. For me "clojure API", "clojureclr", and "clojure cond" are the top suggestions.
11:31cemerickTeXnomancy: I scrolled past all my personalized (I think they're just history) queries to the "Suggested Queries" *shrug*
11:31TeXnomancyah. interesting.
11:31cemerickseems glitchy, as that's above "clojure editor" "clojure web programming" and "clojure emacs" though.
11:33cemerickNot a horrible question though -- I can't think of any easier way than (vec (concat [5] some-other-vector))
11:34rhickeyyikes
11:35cemerickut-oh ;-)
11:35rhickey(into avec another-vec), but the real answer is - "why do you feel you need to do that?"
11:35cemerickrhickey: is there some obvious core fn that I've been neglecting all this time
11:36TeXnomancyeveryone neglects into
11:36cemerickrhickey: roughly the same as using vec, no?
11:38cemerickI've had to prepend (or, in general, insert) into a vector before, though it's rare.
11:39lpetitTeXnomancy == technomancy ??
11:40rhickeypeople need to remain vigilant about not advising others as to how best use the wrong data structure. Yes, every now and then for a one off, but imagine if someone goes and puts that inside a loop...
11:40rhickeycemerick: into much faster than vec + concat
11:41TeXnomancylpetit: yeah, it's my fallback nick. better than techno~1...
11:41rhickeyTeXnomancy: I thought you were an imposter
11:42TeXnomancyrhickey: in a way I am--in truth I am not any good at typesetting at all.
11:42rhickeyheh
11:42cemerickrhickey: the latter ends up being necessary for those odd insert requirements.
11:42lpetitrhickey: he may be. It depends whether you've been convinced by his answer, or not !
11:43rhickeycemerick: just wait for chouser's finger trees
11:43TeXnomancyso concat is slower because it has to list-ize the whole thing, then go back and vectorize it, while into can use transients, I suppose.
11:43lpetitrhickey, cemerick: will chouser's finger trees be delivered before or after cinc and ClojureScript ? :-p
12:00cemericklpetit: I think cinc will end up being a continuous effort. Each additional host will probably prompt incremental cinc-related changes, etc.
12:01lpetitcemerick: yep. the first one being probably the CLR, rather than javascript, I guess
12:02cemerickThat's up to rhickey and the different implementors, but I suspect the work needed to simplify things for js is far less than for the CLR (simply because so many clojure features are out of scope for js).
12:05AWizzArdrhickey: a standard that defines the file names the compiler produces would be useful. And the current granularity is currently very nice.
12:10lpetitno reaction to my post on the ml concerning user assistance and IDEs: of interested to nobody (except me !) ? or should I leave more time for people to answer ?
12:16cemericklpetit: I hadn't noticed the thread, but we're deep into the summer doldrums. Attention is down across the board. :-)
12:17lpetitcemerick: oh :)
12:30lpetitcemerick: now that you've noticed the thread, I'm counting on you to feed it :-)
12:45defnAnyone read this book? http://tinyurl.com/2bhnc8p (Language Implementation Patterns: Create your own DSL and general programming languages)
12:53bigwavejakei'm new to clojure and incanter. i get an error when trying to evaluate the following: (ns myproj (:use [incanter core stats]))
12:53bigwavejakeI get: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol
12:54bigwavejakewhat am i doing wrong?
12:55NikelandjeloTry (:use [incanter.core.stats])
12:56bigwavejakeNikelandjelo: with no ns around it?
12:56Nikelandjelobigwavejake: with ns, do you work in repl or write separate file?
12:57bigwavejakeCould not locate incanter/core/stats__init.class or ...
12:57bigwavejakerepl
12:57NikelandjeloDid you include incanter in classpath?
12:58bigwavejakeyep. i added the incanter dep in the project.clj, lein deps, lein repl
12:59maravillasit's not incanter.core.stats - he's trying to use incanter.core as well as incanter.stats
12:59bigwavejakemaravillas: right
13:00maravillasthat said, i'm not sure what the issue is
13:02zkimbigwavejake: try lein clean && lein deps
13:03zkimbigwavejake: then lein repl
13:03zkimbigwavejake: whoops, i have to learn to read
13:04bigwavejakezkim: no go
13:04bigwavejakezkim: same error: '...Don't know how to create ISeq from: ...'
13:05Nikelandjelobigwavejake: Does (:use [incanter.core]) (to use only core) work?
13:13zkimwonder if that worked
13:14zkimwhenever i get those iseq error messages due to a ns change it's usually a badly formatted use / require / import
13:15bigwavejakesorry... i had a phone call
13:15bigwavejakeNikelandjelo: didn't work
13:15bigwavejakesame error
13:15zkimbigwavejake: try (use 'incanter.core)
13:15bigwavejakezkim: no good
13:16zkimbigwavejake: same error?
13:16bigwavejakejava.lang.RuntimeException: java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.
13:16bigwavejakelang.Symbol
13:16zkimhrm, maybe i've got the syntax wrong, hold on, got a project with incanter here somewhere
13:17zkimyeah, that's the right syntax
13:17Nikelandjelobiwavejake: what about (use 'clojure.contrib.seq-utils) ?
13:17Nikelandjelobigwavejake: Can you use any lib? :)
13:17bigwavejakeNikelandjelo: that worked
13:17zkimweird
13:17bigwavejakeyeah!
13:18bigwavejakesuper weird!
13:18zkimcan you pastebin your project.clj?
13:18bigwavejakesure
13:19bigwavejakehttp://pastebin.com/QYLnBF50
13:20zkimone sec
13:20bigwavejakesure, take your time
13:23zkimgot it, seems like a problem with clojure 1.1.0, try this project.clj: http://pastebin.com/BXVeHWWV
13:26zkimbigwavejake: forgot to mention, do a lein clean && lein deps too
13:26bigwavejakethat's it
13:26bigwavejakenice!
13:26zkimcool
13:26bigwavejakeso, the rule to getting clojure projects working is to live on the bleeding edge?
13:27zkimhaha
13:27bigwavejakeanyways, thanks for all your help
13:27zkimdonno, maybe there's something in the incanter notes about incompatability
13:27zkimyeah np
13:43chouserhuh. 3rd printing of Programming Clojure. Not too shabby.
13:45cemerickI'm surprised that there's a notion of "printings" anymore at all, really. Figured the whole industry would be JIT, or damn close at this point.
13:46chouserI was notified by an email that suggests there may be changes to the content as well. Perhaps "printing" is more of a minor version number or something now.
13:48cemerickSemantic versioning of books is around the corner. Programming Clojure e1p3 just released. :-P
14:43hugodis it possible to annotate a deftype constructor?
14:51slyrusspeaking of deftype... so can I use deftype to extend a clojure.lang.IPersistentVector instead of an IPersistentMap?
14:53cemerickslyrus: yes
14:53slyrushave an example of how to do so lying around?
14:54cemerickslyrus: look at gvec.clj in clojure itself
14:55slyrusthanks cemerick
14:57aria_42speaking of deftype/defrecord, can you serialize them such that you can eval them back into memory from disk?
14:58cemerickaria_42: defrecord is java.io.Serializable, so there's that. Neither deftype or defrecord have readable printed representations yet.
15:12slyrusI (think) I want a vector that supports a couple operations (that I'll define) and clojure.lang.IObj. If I use defrecord, the type will be a map. If I use deftype, I can make it a vector, but I lose the built-in IObj support, right?
15:14cemerickslyrus: You could just proxy PersistentVector.
15:15cemerickSee, what we need are some flavour of mixins!
15:15chouseror write functions that operate on a vector. what operations do you want to add?
15:16chousercemerick: we need, and I assume we will get, mixins that are currently provided by the various base clojure collection base classes.
15:18cemerickchouser: For deftype usage? I'm all for it. I remember some ill words on mixins here a while back though.
15:18slyruschouser: not sure I need any, tbh. I current have some operations that are provided by my record, but maybe these can just go away and be replaced by sequence operations.
15:19slyrusoh, no, I still want a couple "convenience" operations so that even though this is a sequence (vector), it can still implement my NodeSet protocol.
15:20slyrusI'm thinking of replacing the Edge record in http://github.com/slyrus/shortcut/blob/master/src/shortcut/graph.clj with something built on top a 2-element vector.
15:20chouserslyrus: perhaps you could just extend your protocol to PersitentVector
15:21chousercemerick: I'm sure everyone else did mixins wrong ;-), but extend with a merged map is essentially a sort of mixin, the sort that clojure collections will need to be implemented in clojure without duplicated code.
15:21slyruschouser: hate to be dense, but I'm not exactly sure what you mean. Do you mean have my Edge record implement methods from IPersistentVector?
15:24cemerickchouser: See, I thought you were talking about impls being mixed into inline deftype/record definitions. Protocols/extend are a superset of mixins as far as I've ever seen them embodied before.
15:25chouserslyrus: I don't know exactly what you're doing, but if you want something that behaves just like a vector, but with a few more functions on it, one option is to have the object actually be a regular vector, and provide functions (perhaps protocol methods) that operate on them.
15:25slyrusyeah, that sounds great. how do I do that? :)
15:26chouserwhat sort of operation do you want?
15:26slyrusthe protocol methods part that is...
15:26chouseroh
15:27slyrusok, let's take a trivial example. I have [:a :b]. I want (get-the-other-value <the thing that is/has the [:a :b] vector> :a) to return :b.
15:29slyrusnaively, I would think that I would want a MySillyVectorOperations protocol with get-the-other-value and then some sort of defprotocol/deftype magic that allows me to write methods for MySillyVectorOperations.
15:29slyrusMy understanding is that's the way it works if I'm extending a map, which is awesome
15:29slyrusI want the some sort of thing for a vector and am under the impression that this can be done with deftype, but I don't understand the details.
15:30chouser(defprotocol Pair (left [n]) (right [n])) (defn get-the-other-value [p x] (if (= (left p) x) (right p) (left p)))
15:30chousersomething like that?
15:30slyrusyes
15:31chouser(extend-type clojure.lang.PersistentVector Pair (left [v] (first v)) (right [v] (second v)))
15:31chouser(get-the-other-value [:a :b] :a) ;=> :b
15:32slyruswow, this is neat
15:32slyrusonly I'm not quite sure what the extend-type there just did
15:32chouserthat sound you hear is the expression problem going up in smoke.
15:33cemerickheh
15:33chouserslyrus: extend-type is telling the 'left' and 'right' functions what to do when confronted with a plain old clojure vector.
15:34cemerickoh, how I wish case evaluated static field dispatch constants
15:34chousercemerick: yeah, I've run into that as well.
15:34chouserJava enums are essentially the same, aren't they?
15:34slyrus"A macro that expands into an extend call." isn't too helpful :)
15:34clojurebotamespaces are (more or less, Chouser) java packages. they look like foo.bar; and corresponde to a directory foo/ containg a file bar.clj in your classpath. the namespace declaration in bar.clj would like like (ns foo.bar). Do not try to use single segment namespaces. a single segment namespace is a namespace without a period in it
15:35slyruschouser: what does the third argument (Pair) do in that extend-type example?
15:35slyrusboth get-the-other-value and [:a :b] don't know anything about Pair, right?
15:35chouserslyrus: that's indicating *which* 'left' and 'right' functions I'm about to implement.
15:36cemerickchouser: I'm not sure what case does with a Classname/field dispatch. And yes, enums are static fields.
15:36slyrusso now I can call left and right on all vectors?
15:36chouserslyrus: get-the-other-value is built specifically on top of the Pair functions 'left' and 'right'. You could hint the args as [^Pair p, x]
15:36chouserslyrus: yes
15:37slyrusfascinating...
15:37cemerickI'd like to make case insensitive to hash collisions as well, so I've got a pile of case hacking to do. :-)
15:37chouserit's all the power of monkey patching without that itchy-teeth feeling
15:41slyrusoh, neat: (extend-type clojure.lang.APersistentMap Pair (left [v] (:left v)) (right [v] (:right v)))
15:41slyrus(get-the-other-value {:left :a :right :b} :a)
15:41chouser:-)
15:42slyrusOk, thanks for the mind-expanding explanation!
15:42chouserswitch to (extend-protocol Pair ...) and you can do both in a single top-level expression.
15:43chouserslyrus: you're welcome. This is what I hope to do for everyone that comes to my talk at Strange Loop.
15:43chouserstill looking for the killer example...
15:43ecyrbIn a deftype I tried to create a field with ^{:tag int :unsynchronized-mutable true}, and I got the message "Must assign primitive to primitive mutable"
15:44ecyrbIs a primitive mutable a boxed primitive wrapper (i.e. java.lang.Integer)?
15:45chouserthat's some dark magic you're playing with there...
15:46ecyrbI am having trouble reading my spellbook
15:47chouserecyrb: can you paste a small example that generates the error?
15:47ecyrbI suspect what I'm trying to do is not *currently* supported, but the "primitive mutable" term makes me unsure.
15:49chouserthe field you created is the primitive mutable
15:50chousera boxed Integer is not a primitive. It's telling you that the value you pass to set! needs to be a primitive, not a boxed Integer.
15:51ecyrbhttp://paste.lisp.org/+2EW9
15:51ecyrbah
15:52ecyrbjust needed to fix my set!
15:52ecyrbthanks
15:52chouser'mod' will always returned a boxed number
15:52chouserok
15:52chouserbut those :unsynchronized-mutable's are really scary.
15:52ecyrbyeah, I don't know yet when I need a type-hint / cast
15:52slyrus(edges q7 1) ==> ([385 1] [1 35]...) is much nicer than (#:shortcut.graph.Edge{:node1 3, :node2 4} ...)
15:53slyrusthe only thing more satisfying than writing records is deleting them when they're no longer needed!
15:53chouserheh
15:54eshiraI'm working on a memozied prime finder (for a project euler problem: find the sum of the primes below 2 million): http://gist.github.com/480723
15:54eshirait is too slow for primes bigger than about 20,000. any ideas why?
15:55ecyrbchouser: Are they scary for any reason other than unsynchronized method calls?
15:55slyrusoh, only thing is now I can't just rely on the type of the object to know what kind of behavior to implement. hmm...
15:56chouserecyrb: and uncontrolled mutables. Very non-clojury except at the innermost levels of the most performance-demanding code. application-level code should definitely not be using them.
15:56slyrusthe example is that I used to have an Edge record for undirected edges and an Arc edge for directed edges. Now if those both go away and are replaced by vectors, I have to keep track of whether the edge is directed or undirected. metadata?
15:57ecyrbchouser: Alright, cool. Thanks for the help, and I'm looking forward to the rest of the book.
15:57chouserslyrus: ah, that is one wrinkle. protocols only dispatch on the actual java type, so if you need different implementations, you'll need different objects -- at least one defrecord again.
15:58chouserecyrb: great, thanks!
15:59slyruschouser: then I'm back to my original question. can I defrecord a vector instead of a map?
15:59chouserslyrus: no, not in any way I can think of.
15:59slyrusit's not so much different implementations, but that certain operations should only be allowed on certain objects.
16:00slyrusok, thanks. perhaps there's a need a defvector analog to defrecord.
16:00chouserhm. I rather doubt that'll happen.
16:01chouserThe only thing you really need from vectors is IObj?
16:01slyrusyeah, I think so
16:03chouserwhich is just get/set of metadata
16:04slyrusok
16:04chouserso add a 'meta' to your field list -- then implementing IObj should be just 3 lines in each of your defrecords
16:05slyrusgreat
16:05slyrusforgive me if i've asked this already, but is there a more idiomatic way of doing: (remove #(= % 3) [1 2 3 4 5])
16:06herdrickI'm not sure if it's ok to promote my own (Clojure) blog post here
16:06herdrickIs it?
16:08raekwhy not?
16:09raekwhat's it about?
16:09herdrickWell, refactoring some Clojure
16:09herdrickto get rid of hashtables
16:09chouser,(remove #{3} [1 2 3 4 5])
16:09clojurebot(1 2 4 5)
16:10raeklink?
16:10clojurebotyour link is dead
16:10herdrickthat is, instead of returning a hashtable from a function
16:10herdrickjust call that function every time you need a value that would have been in said hashtable
16:11herdrickjust put the key from the hashtable that you would have gotten on the end of your argument list
16:11slyruschouser: again, nice!
16:11herdrickHere it is: http://news.ycombinator.com/item?id=1529918
16:13slyruschouser: when you implementing IObjc should be 3 lines in defrecords, you mean deftypes, right?
16:13herdrickIt's a technique not specific to Clojure
16:14slyruss/you/you say/
16:14sexpbotchouser: when you say implementing IObjc should be 3 lines in defrecords, you say mean deftypes, right?
16:14herdrickbtw is there a name for that technique? i've never run across it anywhere.
16:14chouserslyrus: sorry, yes.
16:14slyrusok, just checking
16:16chouserherdrick: nice. it's a sort of laziness
16:17herdrickchouser: yeah
16:17chousersame kinds of benefits and tradeoffs as clojure's caching lazy seqs compared to cons-cell lists.
16:25herdrickchouser: really?
16:25herdrickI wouldn't have said that
16:26herdrickbut then I've not ran into much in the way of tradeoffs with lazy seqs
16:26herdrickexcept the difficulty in finding bugs
16:26herdrickthat's really similar
16:26chouserheh
16:27herdrickand there's something similar in feel there
16:27herdrickwhere a lazy seq sets up a function call chain but doesn't use it immediately for all values
16:28herdricksame thing with this - you call down the function chain to get your value when needed, instead of batching it all up into a hashtable
16:28herdrickso it's a lazy hashtable, yeah
16:29chouseralso interacting with dynamic or "real world" environment -- when you're less sure when the code is going to be called or the results cached, you have to be more careful about impure functions.
16:30slyruschouser: I take it back, yes, I want IObj functionality, which is small, but I also want the thing to be a vector! which I don't think I can do with deftype. (in 3 lines anyway)
16:31chouseryou want to be able to conj on the end?
16:32slyrushmm... no, I guess not.
16:33chouseryou want nth to work? or what?
16:33slyrusyeah, that sort of thing.
16:33slyrusperhaps I'm not thinking this through clearly enough
16:34chouserI suppose you could implement a subset of PersistentCollection, or may just java.util.Collection. It generally requires about one line per method.
16:35slyrusok
16:48raekhow does future-cancel work? must the thread block or something to be canceled, or can it be stopped anyway?
16:49raekalso, if the future, say, does a blocking read from a socket, will any data be lost if the future is canceled?
16:51slyrusooh, this gets me out of wanting protocols and records of the same name. I can define the protocols as I want and then just extend-type the underlying representation. neat!
16:56herdrickchouser: yes, very much so. I was thinking that sometimes the way to go would be to just make a new memoization wrapper of a function to 'clear the cache' for example at the beginning of a web page context
16:56herdrickso with a new call to that page, you get a new cache
16:57herdricksometimes handy, i think
17:03mattreplraek: http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/java/util/concurrent/Future.html#cancel(boolean)
17:04mattreplexecutors process a queue of futures, so if the future hasn't been run yet it can be cancelled
17:05raekbut if it is running?
17:05raekI'm investigating methods of aborting a blocking read
17:07raekbut maybe there isn't any good way
17:07mattrepluse a timeout on the blocking read
17:11raek(defn source-seq [source] (lazy-seq (let [item (take! source end-of-stream)] (if-not (= item end-of-stream) (cons item (source-seq source))))))
17:11rshare there any good part of speech tagging libraries for clojure?
17:11raekI'm doing a library to make IO more functional
17:11arohnerrsh: there's a clojure wrapper around openNLP
17:12arohnerrsh: http://github.com/dakrone/clojure-opennlp
17:16chouserraek: future-cancel will cancel a blocking read
17:25timcharper`lein swank` fails for me
17:26timcharperhttp://pastie.org/1051074
17:26timcharperException in thread "main" java.lang.Exception: Unmatched delimiter: ) (basic.clj:185)
17:26timcharperusing [swank-clojure "1.2.1"]
17:27raekwhen I do a .readLine on a BufferedReader connected to a socket in a future and cancel it, one line gets dropped
17:28technomancytimcharper: probably an outdated version of clojure-test-mode
17:28timcharperthat's the general solution to that problem
17:28timcharperhowever this is occurring when firing up from the console
17:28timcharpernot from within emacs
17:30timcharperAt any rate, at clojure-test-mode 1.4 in emacs. I upgrade it a while ago to fix this problem. Now that we've upgraded a project to clojure 1.2, I'm getting it again :(
17:30slyrus,(sort-by #(:level (val %)) {"foo" {:level 1}, "bar" {:level 4}, "ape" {:level 3}})
17:30clojurebot(["foo" {:level 1}] ["ape" {:level 3}] ["bar" {:level 4}])
17:30lpetitif I were to implement the function I described in the ml (the one which takes a list of namespaces, finds out all the transitive namespaces which depend upon these namespaces, and then calls reload in the right order for each of these namespaces),
17:30lpetitwhat do you think could be a good name for it ?
17:30lpetitOptionnally, would you use this function ?
17:30chousersounds like reload-all
17:31timcharperhmmm
17:31lpetitchouser: nope, it's the exact inverse.
17:31lpetitchouser: it reloads all ns which "depend" on the ns I pass to the function, thus ensuring that all ns which have functions using macros of my ns are accurate (compiled towards the last version of the namespace)
17:31lpetitetc.
17:32chouseroh, I see.
17:32arohnerlpetit: though the inverse would be nice to have as well
17:32chouserreload-dependents
17:32lpetitchouser: that's a feature I want for ccw, but I guess it could be used outside ccw as well, so I intend to write it in an independent place
17:33chouserlpetit: I love that that's your approach. Someday someone's going to steal all your code and put it in a pure-clojure editor.
17:34lpetitchouser: if I haven't written the pure clojure editor in pure JDK swing before him :-p
17:34timcharpertechnomancy: do you know how to get the "52 more" to sho ?
17:34timcharpershow ?
17:34chouser:-)
17:34technomancylpetit: search the mailing list; Steve Gilardi was working on an overhaul for require that basically implemented what you're looking for.
17:34timcharper(at the end of my pastie)...
17:35somniumlpetit: will you accept random requests for features from emacs?
17:35technomancytimcharper: dunno; sorry. clj-stacktrace is nice for that.
17:35lpetittechnomancy: oh! Now that you're talking about it, I remember the thread, but I didn't remember this feature was on the list. Thanks !
17:36lpetitsomnium: yes, if you're ready accept random reponses ! :)
17:36somnium:-)
17:36crowbar7I think it's time I write a clojure asterisk lib.
17:36lpetitsomnium: seriously, yes.
17:37lpetit~counterclockwise
17:37clojurebotCounterclockwise aka ccw at http://code.google.com/p/counterclockwise/
17:37neotykis there a way to see if promise was delivered yet? (delivered? prom)
17:37lpetitsomnium: ^^^^ the issue tracker accepts feature requests
17:37lpetitsomnium: what do you have in mind ?
17:38lpetit,(doc delivered?)
17:38clojurebotNo entiendo
17:39lpetitneotyk: no
17:40TimMclpetit: Is there a plan to integrate lein into CCW?
17:41lpetitTimMc: yes
17:42TimMcYay!
17:42TimMcWith all the jars nesting happily together in ./lib?
17:43lpetitTimMc: there's even a first demonstration of the use of ccw with lein in Stephan Mühlstrasser's ccw repository. He used it to enable a "File > new > Example > LabRepl project" feature. And while adding lab repl support, he wrote the first parts of integration lein with ccw
17:43timcharpertechnomancy: I'm trying to trace my way through and see where the problem lies. The only clue is swank.clj, line 11. When I fire up `lein repl` and type (require 'swank.core)... it seems to hang with no output. Any ideas on how to proceed ?
17:43lpetitTimMc: it's planned, not totally done yet :-)
17:43lpetitTimMc: but I guess so.
17:43TimMc:-D
17:44somniumlpetit: maybe org-mode and a shell-emulator?
17:44lpetitsomnium: you'll first have to explain me (no RTFM please) what those are !
17:44timcharperhttp://pastie.org/1051105
17:45Raynesorg-mode is a TODO list format on crack.
17:45lpetitsomnium: really, I don't know these modes. So maybe you were joking ?
17:45somniumhttp://www.bestinclass.dk/index.clj/2010/07/trail-blazing-innovators.html
17:45lpetitsomnium: answers collision. Is org-mode what is demonstrated by Lau ?
17:46lpetitsomnium: collision again :p
17:46lpetitsomnium: Eclipse already has a TODO list manager solution. It's heavy, it does everything you want, and I know nobody which uses it :)
17:47somniumlpetit: shell-emulator is just bash in emacs
17:47somniumlpetit: the only time Ive used eclipse was to try ccw :)
17:47lpetitsomnium: I don't see any interest in shell-emulator. Maybe I'm missing something
17:48dpritchettCan anyone help me figure out this simple function? defmapcatop split [sentence] (seq (.split sentence "\\s+")))
17:49TimMcI think you're missing some parens at the front there.
17:49dpritchettI'm specifically confused by the .split part at the end... it doesn't seem to return anything (side effects from a native Java function I guess?) and the "\\s+" appears to be a regex but the ones i see in my books are more like #"\s+"
17:51dpritchettYes TimMc I did miss the leading paren when I copied this out of a blog post. I'm actually working on project Euler problem 11 and I turned to a wiki for help on converting this big string into a series of lists of 20 ints using (partition 20 (map #(Integer. %) (.split nums "\\s+")). I'm only confused by the .split and the regex I guess
17:51lpetit,(.split "ab cd" "\\s+")
17:51clojurebot#<String[] [Ljava.lang.String;@d1102f>
17:51lpetit,(seq (.split "ab cd" "\\s+"))
17:51clojurebot("ab" "cd")
17:52lpetitdpritchett: of course you're wrong, and .split returns something, because if not you would not want to pass it to seq, and also because Strings in java are guaranteed immutable since java inception
17:53lpetitdpritchett: #"\s+" is not "a regex", it's a regex pattern, precisely:
17:53lpetit,(type #"\s+")
17:53clojurebotjava.util.regex.Pattern
17:55lpetita java.util.regex.Pattern instance. dot calls in clojure are for java interop. You thus have to conform to the java object's API. java.lang.String has a split function, and you used the version which takes a pattern encoded in a String. Nothing wrong with this. It's just less readable.
17:55somnium,(seq (.split "foo\\bar\\baz" "\\\\"))
17:55clojurebot("foo" "bar" "baz")
17:55lpetitdpritchett: you could although do that:
17:55lpetit,(seq (.split "foo bar baz) (.pattern #"\s+"))
17:55clojurebotUnsupported character: \s+
17:55lpetitargh
17:57lpetit,(seq (.split "foo bar baz") (.pattern #"\s+"))
17:57clojurebotjava.lang.IllegalArgumentException: No matching field found: split for class java.lang.String
17:57lpetitre-gargl
17:57lpetit,(seq (.split "foo bar baz" (.pattern #"\s+"))
17:57clojurebotEOF while reading
17:57lpetitre-re-gargl (must go to bed, now)
17:57lpetit,(seq (.split "foo bar baz" (.pattern #"\s+")))
17:57clojurebot("foo" "bar" "baz")
17:57lpetitah !
17:58lpetitfinally !
17:59dpritchettthanks lp
17:59dpritchettI better understand the java interop part
17:59dpritchettStill not quite sure why the code I copied uses "\\s+" instead of "\s+"
18:00timcharperOK... so (require 'swank.swank) makes my repl hang...
18:00somnium,"\s+"
18:00clojurebotUnsupported escape character: \s
18:00dpritchettOk I'm with you now somnium
18:01dpritchettI'm passing "\s+" to java but unless I escape the backslash Clojure eats it instead of passing it along like any other character
18:01timcharper(require 'leiningen.swank) causes an error: java.io.FileNotFoundException: Could not locate leiningen/compile__init.class or leiningen/compile.clj on classpath: (swank.clj:1)
18:01dpritchettso "\\s+" is interpreted as a "\s+" by .split
18:01timcharperI'm really struggling to try and diagnose this..
18:03lpetitdpritchett: not quite. You're passing the source code literal string composed of characters slash, letter s, sign plus to the clojure reader. The clojure reader reads clojure Strings with the same algorithm as the java compiler reads literal java Strings. And "\s+" is not a valid clojure/java string.
18:04timcharpertechnomancy: any clues... please? :) I am trying to understand how lein works so I can figure this out.
18:04dpritchettTim what are you trying to do?
18:04timcharperwhy can't I issue 'lein repl' and then invoke (use 'leiningen.compile)?
18:04technomancytimcharper: there's a bug in the repl task that sometimes makes it look like it's hanging when it's not... try entering a few more lines (http://github.com/technomancy/leiningen/issues#issue/71)
18:04timcharperI'm trying to get to the bottom of why lein swank no longer works for me after a clojure upgrade
18:05timcharpertechnomancy: ahh... that solves it
18:05technomancy=\
18:06timcharperable to dig deeper...
18:09dpritchettThanks again lpetit. I admit I know even less about Java than I do about Clojure so this has helped me.
18:09timcharpertechnomancy: unfortunately, clj-stacktrace was no additional help, though the output was prettier :) still making progress though with the fake repl-hang workaround
18:09timcharperknowledge
18:10lpetitdpritchett: np, it was done with this intent in mind ! :)
18:13timcharpertechnomancy: found it !!
18:13timcharpertell me if this little line doesn't reveal the issue to you:
18:13timcharperhttp://github.com/stuarthalloway/orolo/blob/master/project.clj#L8
18:15timcharperhow much damage did I just do ?
18:15technomancyheh that'd do it
18:16technomancyI was hoping for a fix to the repl problem =(
18:16timcharperI have a fix: use emacs
18:16timcharperok... not much of a fix if emacs/clojure aren't playing well with eachother
18:17lpetittechnomancy: I didn't manage to find the thread created by Steve Gilardi, related to requiring dependants. Could you give it a try ?
18:17timcharperactually... nevermind... maybe not... erase the last two message by me
18:18lpetittechnomancy: nevermind, found in my personal archives :
18:18lpetit:)
18:21timcharperFor future people who stumble on this: If, when you invoke `lein swank`, using lein 1.2.0, and adding [swank-clojure "1.2.1"] to your project.clj, you get this error message:
18:21timcharperException in thread "main" java.lang.Exception: Unmatched delimiter: ) (basic.clj:185)
18:21timcharperIt could be because another dependency of yours is bringing in an older version of swank. Like orolo is doing currently, for example: http://github.com/stuarthalloway/orolo/blob/660e8260/project.clj#L8
18:22technomancytimcharper: it could be an older version of any lib; that exception is caused by using ^ as meta, which has been deprecated for a while.
18:23timcharperhmm... so this is more like a "not compatible with clojure 1.2" issue
18:23Raynestechnomancy: I updated clojure-http-client to use the new betas and threw you a pull request.
18:24lpetittechnomancy: re-read the thread you mentioned. I can't see where the feature I was mentioning ^^^ is covered
19:46eshirahow would i init a vector of bools of a certain size?
19:47technomancy,(into [] (repeat 10 false))
19:47clojurebot[false false false false false false false false false false]
19:48chouser,(into (vector-of :boolean) (repeat 10 false))
19:48clojurebot[false false false false false false false false false false]
19:48technomancywell hello mister fancy-pants. =)
19:48chouseror what technomancy said, depending on what you want.
19:48chouser:-)
19:48eshirais vector-of suppose to be a builtin?
19:49timcharperI can verify that I have indeed hear chouser has pants that are mighty fancy
19:49timcharper^hear^heard
21:26TakeVDoes Clojure have anything like Rails, yet?
21:27dnolen_TakeV: conjurehttp://github.com/macourtney/Conjure
21:27dnolen_oops http://github.com/macourtney/Conjure
21:27dnolen_never tried it myself, but it does seem pretty heavily developed
21:27TakeVAwesome, thank you.
21:53rhudsonGiven (defprotocol P (f [p])), (defrecord R [a] P (f [_] (- a))), (def r (R. 2)), it seems I can use the calls (f r) or (.f r). Is there any semantic or performance difference between the two?
22:02rhudsonok, if I move to a different namepace, (.f user/r) works & (f user/r) doesn't ("unable to resolve symbol: f")
22:12rhudsonSo (defprotocol P (f [p])) interns P and f in the current namespace
22:14slyrushow can I make a method preferred: Multiple methods in multimethod 'code-dispatch' match dispatch value: class chemiclj.core.Bond -> interface clojure.lang.IPersistentMap and interface clojure.lang.IPersistentVector, and neither is preferred
22:17rhudson,(doc prefer-method)
22:17clojurebot"([multifn dispatch-val-x dispatch-val-y]); Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y when there is a conflict"
22:17slyrusi see. thanks rhudson.
22:19rhudsonYour dispatch value is Bond? or IpersistentVecor or IPersistentMap?
22:21slyrusBond. (defrecord Bond ... clojure.lang.IPersistent Vector length ...)
22:21slyrusbut, you know, that's probably not so smart anyway.
22:21slyrusjust because I _can_ do something, doesn't necessarily mean I _should_.
22:32sprousthelo clojurians ; I have a question about leiningen.
22:34sproustI want to embed swank-clojure into my code; how do I get leiningen to pull it from its own checkout (outside my project)? How am I supposed to specify the path to it?
22:38tomojis there a reason you need to pull it from its own checkout? living on the edge? hacking on swank-clojure?
22:40tomojthere is a new feature in 1.2.0 which can do what I think you're asking, but there's really no reason to do it unless you are hacking on swank-clojure
22:41tomojin the normal case you'd just add swank-clojure to your project's deps
22:42dnolen_rhudson: f is preferred over .f if using protocols. For one I think .f probably needs a typehint to work without reflection. f does not. there is no performance difference that I've seen.
22:43dnolen_rhudson: I mean f and type-hinted .f seem equally fast. f is of course much prettier, no uglying up your arglists with type hints.
22:44slyrusis there a *print-circle* equivalent for the pretty printer?
22:45slyrusoh, there is.
22:45rhudsondnolen_: Then how do I make sure f is defined in a different namespace?
22:45slyrustoo bad it's not implemented yet :(
22:45dnolen_rhudson: like any other function, :use :require
22:47sprousttomoj: i'd have to tell it where to find it.
22:47sprousttomoj; adding it to my project's deps is what i'm trying to do
22:48tomojsproust: :dependencies [[swank-clojure "1.2.1"]]
22:49sproustthx tomoj
22:49sprousti shouldn't have updated leiningen, looks broken, well something's broken with it not being able to locate find-namespaces from contrib.
22:50tomojdo you have contrib in your :dependencies?
22:51sproustyep.
22:51tomojmaybe the version you're depending on doesn't have find-namespaces?
22:52sproust1.2.0-beta1, i doubt that's it
22:52tomojagreed
22:53tomojI doubt it's leiningen's fault though