#clojure logs

2009-09-16

03:09Fossihi
03:40lpetit_hello all
03:47LauJensenMorning gents :)
03:48arbschthey LauJensen
03:49LauJensenWeee :)
03:49LauJensenHow's that working out for you
03:50arbschta few rough edges, but it's doing a fine job of logging my data
03:51LauJensenGreat - Let me know if there's something we need to have a look at
03:51hiredmanis clojureql/run really the best way to execute statements?
03:52LauJensenhiredman: For now, we're still .... debating.. how to best implement a long lived connection type execution
03:52hiredmanmy main issue is the form of the call
03:52hiredman(cql/run [db results] statement (doall results))
03:53hiredmanover and over and over
03:53LauJensenSuggestions?
03:53hiredman(cql/run db statement)
03:55hiredmanI've, of course, only scratched the surface of clojureql I'm sure, likely missing some nuanced something or other
03:56LauJensenhiredman: (run *conn* (query table *)) will return the resultset-seq directlyl
03:56hiredmanorly
03:56hiredmangood to know
03:56LauJensen(doc run) :)
03:56clojurebot"clojure.contrib.repl-utils/run;[[ns-name & args]]; Loads the specified namespace and invokes its \"main\" function with optional args. ns-name is not evaluated."
03:57hiredmanall my complaints are resolved
03:57hiredmanI dunno, it took a lot of work just to find cql/run
03:57hiredmanspeaking of complaints :P
03:57LauJensenooh :)
03:57LauJensenGotcha
03:57hiredmanI think I ended up digging through the source
03:58LauJensenThe demo is a good place to start
03:58LauJensenShows off most features in their primitive forms
03:58arbschtwhat's the status of limit/offset now?
03:59LauJensenFor limit you simply use (take 10 (run *c* (query foo *)), drop is pending Kotaraks return - He's currently moving
04:00arbschtgreat
04:00LauJensenyea, I also thing we still need to debate that a little more
04:00eevar2LauJensen: that works, even if your query selects a million rows?
04:00eevar2*efficiently
04:00LauJensenYes
04:01LauJensenresultset-seq is fully lazy, so take what you need, then drop the reference and it closes
04:01LauJensenyou CAN also use drop, but that's a waste of resources
04:01eevar2LauJensen: lazy on the server side as well, i mean?
04:02LauJensenYes it should be
04:02eevar2oki
04:02LauJensenThere are a few things where we rely on the jdbc driver, I think this is one of them
04:03hiredmanerm
04:04AWizzArdMoin guys
04:04hiredmanthe lazinesss of result-seq has the same issue of dynamic binding vs. map
04:05LauJensenMorning AWizzArd
04:05LauJensenhiredman: clarify ?
04:05hiredman(binding [*db* some-db-connection] (result-seq-producing-function)) try to use the lazy result-seq outside of the binding *BOOM*
04:06LauJensenOh ok
04:06hiredmanthat's why I have (doall results) everywhere
04:10LauJensenBut shouldn't the compiler be able to work that stuff out?
04:10LauJensenI would feel funny to tailor make CQL to work around it
04:10hiredmaneither work on the compiler, or work on clojureql
04:10LauJensenSIR YES SIR
04:10LauJensen:)
04:11hiredmanmy personal preference is a simple compiler, sense compiler bugs are bad :(
04:12LauJensenWell, I just got through all my messages from the scala community, so I can get to work :)
04:22AWizzArdhiredman: yes, I noticed that too
04:23hiredmansince
04:23AWizzArdyou mean when I discovered it? It was in the beginning of this year, when I was doing sql
04:24hiredmanno, I was just correcting my use of sense
04:25LauJensenhehe
05:37LauJensenNow on the frontpage of DZone :) http://dzone.com/links/scala_vs_clojure_lets_get_down_to_business.html
06:00magnetAm I the only one who feel it is biaised?
06:01LauJensenNo it's biased
06:01magnetLauJensen, Clojure isn't pure either
06:01magnet"pure functional"
06:01hiredmanhttp://twitter.com/RichardVowles/statuses/4024290926
06:02LauJensenHaha
06:02LauJensenYes he left a comment on the blog also :D
06:02LauJensenmagnet: It's close enough I'd say
06:02magnetLauJensen, look at Haskell and you will see it's pretty far
06:02LauJensenI know
06:03magnetOK, you are safe from mutable data *if you stay away from Java code*, and clojure prevents you from a lot of pain
06:03magnetbut I felt your Scala examples weren't idiomatic at all
06:03magnetAnyway it's lunch time
06:03hiredmanI can't actually bring myself to read the blog post, but my impression is that it is something of a hatchet job
06:04LauJensenmagnet: The examples we're supplied by Scala programmers - I don't have the chops for it
06:04LauJensenhiredman: define hatchet job ?
06:05hiredman~google hatchet job
06:05clojurebotFirst, out of 173000 results is:
06:05magnet"Scala does not in anyway discourage it’s users from side-effects and mutable code". Sure it does, thourough the Scala book, with standard data structures (and with the scheduled STM that will probably look a lot like Clojure's)
06:05clojurebothatchet job - definition of hatchet job by the Free Online ...
06:05clojurebothttp://www.thefreedictionary.com/hatchet+job
06:05magnetSee you later
06:05LauJensenl8r
06:06LauJensenhiredman: seriously?
06:06LauJensenI re-read it last night, wondering what all the anger was about, and I felt like I gave Scala a pretty good review
06:06hiredmanseriously
06:07hiredmanwell, like I said, I haven't read it, but that's been my impression
06:08LauJensenah ok
06:21G0SUBwhat's the recommended way of parsing XML in Clojure?
06:25hiredmanclojure.xml/parse
06:26hiredman,(doc clojure.xml/parse)
06:26clojurebot"([s] [s startparse]); Parses and loads the source s, which can be a File, InputStream or String naming a URI. Returns a tree of the xml/element struct-map, which has the keys :tag, :attrs, and :content. and accessor fns tag, attrs, and content. Other parsers can be supplied by passing startparse, a fn taking a source and a ContentHandler and returning a parser"
06:28G0SUBhiredman: cool. thanks
06:29G0SUBhiredman: btw, can you recommend any templating engine? I was thinking about StringTemplate.
06:34crioshello
06:42raphinou_where can I report in documentation? (see http://clojure.org/api#remove where it should be "predicate returns true")
06:55criosdoes Clojure require a JVM >= 5 ?
07:02raphinou_crios: i think so
07:20criosIs there an idiomatic Clojure way for a blocking wait ? For example, before send another "ping" message I must first receive a "pong" one
07:21criosIn java, i'd wait and notify on the same instance (inside a synchronized block)
07:21jdzcrios: why don't you send the ping message when you receive the pong one?
07:22criosjdz: using an Agent?
07:22jdzi mean, how do you wait for the pong message?
07:23criosin Java?
07:23jdzi'm not sure you want agents. (they delay the task until *some* time in the future; the only guarantee is that it will execute before you aske it for the result)
07:24hiredmanwoa
07:24hiredmanno
07:24hiredmanagents don't guarantee that
07:24criosmmm. I'm just trying to understand how a producer/consumer queueu should be implemented in Clojure
07:24hiredmanthey are totally async
07:25jdz,(doc wait-for)
07:25clojurebotIt's greek to me.
07:25jdzugh, shows how much i've used agents :?
07:25hiredmanthere are futures, promises, BlockingQueues, etc, etc
07:25crios,(doc await-for)
07:25clojurebot"([timeout-ms & agents]); Blocks the current thread until all actions dispatched thus far (from this thread or agent) to the agents have occurred, or the timeout (in milliseconds) has elapsed. Returns nil if returning due to timeout, non-nil otherwise."
07:26criosah ok
07:26arbschtwhat about adding a watch to an agent?
07:29criosmmmm. In a chess board game, how would you implement a "player moves after the other's movement"
07:29crios?
07:33hiredmandepends
07:36powr-tocWhat's the difference between clojure.test and test-is? It seems that test-is was renamed to clojure.test when it moved into core... but is test-is still developed in contrib?
07:37Fossii think it's just there for compatibility
07:38Fossinot sure if there are any differences though
07:38crioshiredman: depends of what?
07:39powr-tocso test-is is now deprecated in favour of clojure.test?
07:42criosawait for blocks the current thread, waiting an agent. So the other player should (send something) to the same agent?
07:45durka42crios: await waits for the agent to finish the send-off it's currently working on
07:48criosI'll try to write a simple ping-pong, just for study purposes.
07:55criosby the way, can I read from the standard input stream on the REPL?
07:56crioscan a *in* rebind work?
08:38futuranon.6
09:04adityohello
09:04cgrandadityo: hi!
09:05adityohow do i define something like StringTemplateGroup group = new StringTemplateGroup("myGroup", "C:\\Tutorials", DefaultTemplateLexer.class) this in clojure
09:05adityocgrand: hey
09:05adityoespecially DefaultTemplateLexer.class
09:06Chouser(let [group (new StringTemplateGroup "myGroup" "C:\\Tutorials" DefaultTemplateLexer] ...)
09:06adityookie so .class means nothing
09:06Chouserright
09:06LauJensenChouser, new ?
09:07Chouserunless used like a namespace (FooBar/baz) a class name will resolve to the Class instance (like FooBar.class in java)
09:07ChouserLauJensen: *shrug*
09:08adityocool thanks it works (let [#^StringTemplate group (StringTemplateGroup. "myGroup" "/home/adityo/ib-projects" DefaultTemplateLexer)]
09:14adityocant we import all the libraries in a java package, something like org.antlr.stringtemplate.*;
09:15Fossino
09:15adityookie, not a problem but can be a pain sometimes :)
09:16Fossii guess only really with stuff like Swing
09:16Fossipersonally, i've never used it in java either
09:16adityo;)
09:16Fossithen again eclipse and such do the job pretty well for you
09:17Fossitoo bad that there's nothing like it in emacs/slime/clojure-mode
09:18adityojust what i was getting to..too bad..but seriously how good is clojure development using Eclipse, i havent used eclipse ever but i would like to try it out
09:20Fossii switched to emacs for clojure
09:20Fossihaven't regret it
09:20AWizzArdIs there a vid from rhickeys MS talk yesterday?
09:20Fossiediting s-expressions is just so much better when your editor can handle them
09:20Fossiespecially with paredit
09:21adityoFossi: that i agree paredit rocks!!
09:21Fossiit's more slice and dice than cursor around and type
09:23AWizzArdWhat are your two or three favourite paredit features?
09:23lisppaste8raphinou pasted "idea for map utils?" at http://paste.lisp.org/display/87163
09:24ChouserI assume paredit uses multiple-key chords for its commands?
09:24adityoM-r is nice
09:24Chousertwo keys. hm.
09:24raphinou_chouser: I needed to pasted code for my project. Might be interesting for clojure.contrib.map-utils?
09:25AWizzArdadityo: what is M-r doing?
09:25Fossiopen parenthesis (also closes them), split s-expr, paredit-forward-slurp-sexp and not really paredit but much more useful then: transpose-sexpr
09:26Fossii rarely use M-r. i guess i should :)
09:27Fossiany time you find yourself using the arrow keys, something is wrong :)
09:28raphinou_Chouser: Take your time, but if you don't like the code don't hesitate to tell me as I'm still learning clojure ;)
09:28Chouserraphinou_: it seems a little odd to use both key and val in such operations.
09:29Chouserraphinou_: seems to treat a map as a set key/val pairs. You look up these things by key as well?
09:29raphinou_Chouser: I need to test the val : {:name "e"\} is a submap of {:name "e" :email "v@v.com"}
09:29raphinou_but {:name "e" :email "myemail@name.com"} is not
09:30Chousukeraphinou_: I think you should destructure kv to k and v rather than doing (kv 0) and (kv 1) :/
09:30raphinou_ha, yes
09:30Chousukehmm
09:30Chouser,(into {} (map (set {:a 1 :b 2 :c 3}) {:b 2 :c 4 :d 5}))
09:31clojurebot{:b 2}
09:31adityoAWizzArd: M-r (paredit-raise-sexp)
09:31Chouserthere's another way to write map-intersect
09:31Chouser(though quite possibly less efficient)
09:31adityoAwizzArd: raises a single S-expression up the tree, deleting all of its siblings and its enclosing list.
09:32raphinou_don't hesitate to anotate the paste
09:32adityoAwizzArd: awesome if you want to delete some stuff and have deeply nested S-expr's
09:33ChousukeI just use barf, slurp and kill-sexp the most :P
09:33Chousukein fact I don't even remember the keybindings for the rest :)
09:34ChouserChousuke: is that paste/copy/delete of an s-expr?
09:34ChousukeChouser: no
09:34Chousukebarf and slurp are something else
09:34Chousukekill-sexp is "cut"
09:35Chousukeif I want to copy I usually just kill and yank it twice
09:35Chouserwhat are barf and slurp?
09:35raphinou_Chousuke: your map-intersect is much shorter indeed :-) Any suggestions for is-submap? (I don't see how to destructure as I don't know the name of the keys)
09:36Chouserraphinou_: working on it...
09:36Chousukebarf "extracts" an s-expr from inside another and slurp, well, slurps it :P
09:36raphinou_ha, ok :-)
09:37adityoA good link to understanding barf and slurp http://www.cliki.net/Editing%20Lisp%20Code%20with%20Emacs
09:37Chousuke(every? identity (for [[k v] submap] (= v (mainmap k)))) ?
09:38Chousukehmm
09:38Chouser(defn is-submap? [big sml] (every? (fn [[k v]] (= (big k) v)) sml))
09:40lisppaste8Chouser annotated #87163 "smaller map-as-set fns" at http://paste.lisp.org/display/87163#1
09:41Chouserraphinou_: I'd be curious if anyone else has needed these. Doing set operations on maps key/val pairs strikes me as unusual.
09:42Chousukeraphinou_: to begin with, in a functional language an explicit loop is rarely the best option :)
09:42Chousukeso if you find yourself writing (loop ...) then stop and consider if it's possible to use higher-order functions instead.
09:43raphinou_Chousuke: I need it to remove elements from a list of maps, and want to be able to specify a possible submap. Kind of a sql delete: where name="r" will delete more than where name="r" and status=1
09:44raphinou_ehm, shuffling Chousuke and Chouser.....
09:44Chousukeheh
09:44Chouserraphinou_: clojure.set has several functions that work on sets of maps -- you may find much of what you're looking for there.
09:45raphinou_Chousuke: will remember that about the loops!
09:45raphinou_will look, thx for the pointer Chouser
09:46raphinou_and thanks to both of you for your feedback, even if I now may throw away those functions I was so proud of :-D
09:46Chouserraphinou_: yeah, sorry. it's how it goes. :-/
09:47Chouserother little tips -- conj onto a map can actually take a vector
09:47raphinou_Chouser: no problem, that's learing ;) I'd rather throw away and learn than keep and stay ignorant!
09:47Chouser,(conj {} [:a :b])
09:47clojurebot{:a :b}
09:47Chouserso (conj result {(kv 0) (kv 1)}) could just be (conj result kv)
09:48raphinou_ok!
09:48Chouseruse == instead of = when comparing numbers, but be suspicious of checking the size of things with 'count'
09:48raphinou_why this caution about count?
09:48Chouserthe idiomatic way to check for an empty collection is (seq coll) or (empty? coll)
09:49Chouserso (if (empty? test-map) result ...)
09:50raphinou_ok!
09:51Chouserotherwise, use destructuring more and your code looked fine.
09:52raphinou_thanks for the encouragements Chouser. I can see the direction to take, now I have to get used to that way of doing!
09:52ChouserI suspect my is-submap is roughly as fast as yours. my map-instersect does an O(n) walk of map1 (building the set) that yours doesn't
09:53Chouserso mine might be slower. you could change filter's predicate to be more like 'is-submap?' if you find it's too slow as-is.
09:54Chouserconversely is-submap? could be more compact: (defn is-submap? [big sml] (every? (set big) sml))
09:56raphinou_yes, I see
10:00raphinou_about arguments order, is is-submap? [big sml] better than [sml big]?
10:00Chouserraphinou_: I just used the same order as you, I think.
10:01criosstupid question: I'm trying to emulate:
10:01criosfor (int i=1; i<= 10; i++ ) println i+"";
10:01criosbut (apply println (range 1 10) )
10:01criosis not correct: it seems concat all parameters
10:01raphinou_Chouser: yes, but I wondered if I had taken the usual order of arguments
10:01criosthen printing just one \n
10:01Chousercrios: for side-effectful loops, use 'do'-something. doseq, dotimes
10:03Chouserraphinou_: there's always some debate about that. (conj coll item) vs. (cons item coll) for example
10:03Chousukecrios: the apply means calling println once with 10 arguments, while the for loop calls it twn times with one argument :)
10:03Chousukeor actually, (range 1 10) only produces numbers up to 9
10:04Chousuke,(doseq [i (range 1 11)] (println i))
10:04grigna-akcrios: something more like this (doall (map println (range 1 11)))
10:04clojurebot1 2 3 4 5 6 7 8 9 10
10:04Chouserraphinou_: I guess for 'is-submap?' feels a bit like a predicate/collection fn, in which case I'd expect [sml big]. *shrug*
10:04Chousukeclojurebot: hello?
10:04clojurebotBUENOS DING DONG DIDDLY DIOS, fRaUline Chousuke
10:04Chousukehmm /:
10:04Chousukewow
10:04Chousukesome lag :P
10:05raphinou_ Chouser: yes, or keep arguments order and rename function has-submap?
10:07crioswhat is wrong with: (dotimes [count 10] println (count) ) ?
10:08crioshttp://clojure.org/api#toc226
10:08Chouser,(dotimes [i 10] (println i))
10:08clojurebot0 1 2 3 4 5 6 7 8 9
10:09criosah pardon
10:09Chousercrios: parens around 'count' would try to invoke a number. won't work.
10:09Chousercrios: no parens around (println ...) meant it wouldn't be called.
10:09criosyes, you're right
10:09Chouserand 'count' is a builtin name, so I'd recommend avoiding using it for your own locals.
10:10criosok
10:20crios'(dotimes [i 11] (fn [] ( (Thread/sleep 1000) println i) ))
10:20crios,(dotimes [i 11] (fn [] ( (Thread/sleep 1000) println i) ))
10:20clojurebotnil
10:21crios,(dotimes [i 11] (fn [] ( (Thread/sleep 1000) println i) ))
10:21clojurebotnil
10:22crios,(dotimes [i 11] (fn [] (Thread/sleep 1000) (println i) )
10:22clojurebotEOF while reading
10:22criosmm I don't understand
10:23criostrying ;for (int i=1; i<= 10; i++ ) { Thread.sleep(1000); println i+""; }
10:26raphinou_crios: this works for me: (dotimes [i 11] ((fn [] (Thread/sleep 1000) (println i) )))
10:26raphinou_note the extra paren around fn
10:26raphinou_you only defined the function without calling it
10:30raphinou_crios: and this should do what you expected: (dotimes [i 11] (.start (Thread. (fn [] (Thread/sleep 1000) (println i)))))
10:31Chouserdotimes takes a block, not just a single expression.
10:32Chouser,(dotimes [i 4] (Thread/sleep 1000) (println i))
10:32clojurebot0 1 2 3
10:32adityoi have created code with two diff namespaces e,g foo.bar and abc.def..now how do i call foo.bar in abc.def?
10:33raphinou_yes chouser, even better
10:34Chouseradityo: once both have been loaded, foo.bar/your-var-name
10:35criosthanks raphinou_, never thought on that more parens!
10:35criosusing Thread/sleep sleeps the current thread
10:35criosyour .start etc sleeps a new thread
10:36Chouseradityo: you can use 'alias' or 'refer' to use a different name or no name at all for the foreign namespace.
10:36Chouseradityo: you can use 'use' or 'require' to load and alias a namespace all at once.
10:36adityoChouser: and how will i load both of them..sorry for stupid questions but i am a bit confused
10:37Chouserso in abc.def: (ns abc.def (:use [foo.bar :only [a b c]]))
10:37Chouseradityo: then you can call foo.bar's a b and c functions directly: (a 1 2)
10:38criosby the way, this should start 10 threads? (dotimes [i 11] (.start (Thread. (fn [] (Thread/sleep 1000) (println i)))))
10:38Chousercrios: 11
10:38Chouser,(count (range 11))
10:38clojurebot11
10:38adityoChouser: thanks :)
10:38criosthanks by me too :)
10:44Fossiis there a way to get a macro/backquote to not do the namespacing for me?
10:46Chouser,`(namespacing is ~'usually good)
10:46clojurebot(sandbox/namespacing sandbox/is usually sandbox/good)
11:00crioswhy this get a nullpointer?
11:00crios,(let [tPing (Thread. (fn [] (dotimes [i 11] ((Thread/sleep 500) (println "ping"))))) ] (. tPing start) )
11:00clojurebotnil
11:00crios[well in the REPL goes in NullPointer]
11:02shoovercrios: looks like too many parens inside the dotimes
11:03Chouser,(Thread/sleep 1)
11:03clojurebotnil
11:03ChouserThread/sleep returns nil. You then have that at the front of a list, so Clojure tries to call nil as a function.
11:03Chouser,((Thread/sleep 1) 'anything 'here)
11:03criosok
11:03clojurebotjava.lang.NullPointerException
11:05criosI think this is my problem: any time I see a API which expect a body/form, I tend to wrap that into two parens
11:05criosthat is, I'm still new to the "executablity" of parens
11:06raphinou_when writing tests with clojure.test, I thought to use fixture functions to set up a ref that is manipulated by functions. Am I right to think that this ref should be put ina binding for it to be available to actual test functions?
11:08criosby the way, how could I access to the current thread instance? a sort of: ,(let [tPing (Thread. (fn [] (dotimes [i 11] (( this.sleep 500) (println "ping"))))) ] (. tPing start) )
11:08criossee this.sleep
11:10stuartsierraraphinou_; yes, bindings are how fixtures pass information to tests
11:10Chousersleep is not an instance method
11:11raphinou_thx stuartsierra
11:12criosyes, Chouser. But in general? I'd like to call countStackFrames for example
11:12criosin that new thread
11:12Chouser,(Thread/currentThread)
11:12clojurebot#<Thread Thread[Thread-178,5,main]>
11:14criosthat is, I know I can write (. tPing start)
11:16raphinou_this must be a stupid question: how do a remove an element of an arry by its key?
11:16criosbut how could I write something as ( THIS countStackFrames )
11:16raphinou_kind of (remove 5 [1 2 3 4 5 6 7 8])
11:16Chouser,(.countStackFrames (Thread/currentThread))
11:16clojurebotjava.lang.IllegalThreadStateException: this thread is not suspended
11:17Chouserraphinou_: neither Java arrays nor Clojure vectors can remove items from the middle efficiently
11:18raphinou_Chouser: hmm... what do you advise?
11:18Chouserraphinou_: about the best you can do is:
11:18Chouser,(let [v '[a b c d e f]] (into (subvec v 0 2) (subvec v 3)))
11:18clojurebot[a b d e f]
11:19Chouserraphinou_: sets and maps are good at removing arbitrary items
11:20criosChouser, I mean: inside the anonymous function wich implements Runnable (dotimes [i 11] (. countStackFrames ) (println "ping")) can I call countStackFrames?
11:21criosI think no, because I've no symbol associated to the new Thread instance
11:21Chouserraphinou_: that subvec example is O(n) on the second subvec
11:21raphinou_Chouser: I don't think maps and sets correspond to what I need. I was already using split-at for inserting elements in the vector (with destructuring btw ;-) . I guess I'll do like you say for removal
11:21Chousercrios: yes, I keep giving you examples. (Thread/currentThread) returns the current thread object. you may call any methods you'd like on it, including countStackFrames.
11:23Chouserraphinou_: my finger trees still have high constant costs, but they're O(log n) for removal.
11:25raphinou_Chouser: bookmarking them for later, will use vector for now
11:26criosah ok Chouser, I didn't notice that currentThread returns "this" thread
11:31criosIf currentThread didn't exist, it would be not possible to call that instance method? "this" is not allowed, correct?
11:36Chousereven in Java 'this' doesn't mean "this thread"
11:37Chouserbut yes, in Clojure 'this' is only special inside 'proxy' forms, otherwise it's just another identifier like i or foo
11:39criosabout "this" I know it :), I was meaning that without the currentThread reference, I cannot access any instance method inside an anonymous function which is given as Runnable argument to the Thread constructor
11:40crios"any instance method" of the current thread
11:40raphinou_is this the best way to insert into an array at a certain index? (let [ [pre post] (split-at index sections)] (vec (concat pre [new-item] post))))
11:41raphinou_I need a vector returned, hence the call to vec
11:41Chouserright, again it's the same as Java. The Thread class could pass its own instance as an parameter to the method it calls, but it doesn't and Runnable doesn't even have a signature to allow it. So in both Clojure and Java you must use the currentThread static method.
11:42Chouserraphinou_: no, you can use assoc on a vector. it's fast. And be careful not to call them arrays -- array implies Java array.
11:42criosok
11:42Chouser,(assoc '[a b c d e] 2 'X)
11:42clojurebot[a b X d e]
11:43raphinou_ok, thx! I meant vector, really :-)
11:45raphinou_Chouser: actually I need to insert, not replace ;)
11:46Chouserraphinou_: oh. :-( indeed. what you wrote is fine.
11:46Chouserraphinou_: it might be slightly faster to conj onto a subvec.
11:47raphinou_but I need to concat anyway, no?
11:47Chouser(apply conj (subvec v 0 i) new-item (subvec v i))
11:47raphinou_so I would have a conj + a concat
11:48lisppaste8crios pasted "untitled" at http://paste.lisp.org/display/87168
11:49Chouserhm, conj doesn't use transients yet.
11:49Chouserraphinou_: are we concerned about speed here? how large are these vectors?
11:49raphinou_no concern for speed
11:50raphinou_small vectors, to be used in a web application
11:50Chouserthen vec and concat is fine, or apply conj
11:50raphinou_apply conj I didn't think of!
11:50Chouseryour vec/concat is probably clearer in its meaning
11:51criosabout the code in http://paste.lisp.org/display/87168, it does not work correctly, I think it is related with the evaluation time of sendMsgFor ?
11:53Chousercrios: the Thread constructor expects a Runnable. Instead you're calling sendMsgFor and passing its return value (I'm guessing nil) to Thread.
11:53Chousercrios: try (Thread. #(sendMsgFor 11 500 "ping"))
11:55criosthat works. mmm I'm was sure of having read that a clojure function implements Runnable
11:55Chouserit does
11:55criosah I was passing its return value
11:55Chouseryes
11:56criostime to check the # escape :)
11:57Fossii though LazyPersistentVector etc implement Collection?
11:58ChouserFossi: huh! that might be bug.
11:59Fossihow do i get a collection from them?
11:59Chousuke,(ancestors clojure.lang.LazilyPersistentVector)
11:59clojurebot#{java.lang.Iterable java.lang.Runnable clojure.lang.IPersistentVector java.util.Collection clojure.lang.AFn clojure.lang.Indexed clojure.lang.Seqable clojure.lang.IFn clojure.lang.APersistentVector java.util.List clojure.lang.IMeta clojure.lang.Streamable java.lang.Object java.util.concurrent.Callable clojure.lang.IObj clojure.lang.Counted java.util.RandomAccess clojure.lang.Obj clojure.lang.Sequential :clojure.contrib.g
11:59Chousukeit is a Collection. :/
12:00ChouserChousuke: what's wrong with my clojure!? (supers clojure.lang.LazilyPersistentVector) ==> #{java.lang.Object}
12:00ChousukeChouser: try ancestors? :P
12:00Chousuke,(supers clojure.lang.LazilyPersistentVector)
12:00clojurebot#{java.lang.Iterable java.lang.Runnable clojure.lang.IPersistentVector java.util.Collection clojure.lang.AFn clojure.lang.Indexed clojure.lang.Seqable clojure.lang.IFn clojure.lang.APersistentVector java.util.List clojure.lang.IMeta clojure.lang.Streamable java.lang.Object java.util.concurrent.Callable clojure.lang.IObj clojure.lang.Counted java.util.RandomAccess clojure.lang.Obj clojure.lang.Sequential clojure.lang.Rever
12:00Chousukehm
12:01Chousukeokay, something is wrong with your clojure :)
12:01Chousersame
12:01Chouseryeah
12:01ChousukeI'll check mine.
12:01Chousukehm. it's broken too
12:04Chouseroh!
12:04Chouserit's gone
12:04Chouser,(class [1 2 3])
12:04Chousukeoh. haha
12:04clojurebotclojure.lang.LazilyPersistentVector
12:04ChouserI just get a PersistentVector here
12:04ChousukeClojurebot must be running an old version
12:04Chousuke,(doc transient)
12:04clojurebotGabh mo leithscéal?
12:04ChousukeI think it went away with transients.
12:04Chouseryeah
12:06criosChouser so by adding a # I warn the clojure reader that I'm creating a (anonymous) function, so it must not evaluate and execute the next parentheses... correct?
12:07Chousercrios: yes
12:07Chousukecrios: that's a bit contrived way of putting it.
12:08Chousukecrios: the reader doesn't evaluate anything in the first place (except #=(foo) forms)
12:09Chousukecrios: what happens is that #( is reader magick and instead of outputting just the list '(yourfunc args here), the reader instead outputs the list '(fn [] (yourfunc args here))
12:10Chousukeand when the program gets around to evaluating that, it of course produces an anonymous function
12:10Chousuke-it
12:10Chousukeer
12:11Chousukenever mind :D
12:11criosit now makes much more sense, thank you
12:12Chousukethe actual implementation of # is a bit more complicated because it has to handle %1 %& etc.
12:12Chousuke#( I mean.
12:14ChousukeI think my #() implementation is still a bit buggy.
12:14crios?
12:14ChousukeI think it discards any metadata you attach to the % parameters :/
12:15Chousukecrios: I have a mostly-working reader written in Clojure and should find the time to finish it :P
12:15crios:)
12:15crioscome on ;)
12:15Chousukebut most of the fun work is over and suddently I'm feeling much less motivated
12:15criosjust for my stupid question?
12:15criosquestions?
12:16Chousukehm?
12:17crios[ ehm - what does it mean 'hm' ? ]
12:18ChousukeI mean I didn't quite understand you :P
12:20criosah :) - I was thinking that my stupid questions make you "feeling much less motivated" eheh
12:21criosby the way do you use some ANTLR grammar in your reader?
12:22Chousukeno.
12:22Chousukeit's the simplest possible reader :P
12:22raphinou_I need to go. Bye!
12:23Chousukecrios: http://github.com/Chousuke/clojure/commits/clojure-reader ... I cleaned up the commit history a bit some days ago :)
12:25criosby raphinou_
12:25criosbye
12:30criosIs reader.clj currently used by the REPL?
12:31Chousukeno.
12:31Chousukethe current reader is written in java
12:32criosare you thinking of replace it?
12:33Chousukemaybe.
12:33ChousukeIf I can make this reader good enough :)
12:34criosand why should be better a Clojure reader, instead of a Java one? (besides the former is written by you ;-)
12:35Chousukecrios: because it's in Clojure :)
12:37crios:)
12:37crioswell, good job.
12:37criosi have to go
12:37criosbye
12:56grigna-akwhere can I find documentation for what was once clojure.contrib.template ? (btw github has been down, so I couldn't find it in there)
13:04danlarkincgrand: ping
13:06cgranddanlarkin: pong!
13:06danlarkinI have a question about PersistentHashMap2 -- your commit from august 10th
13:07danlarkinaugust 10th was when it replaced PersistentHashMap, anyway
13:07cgrandyes?
13:07danlarkinwhat was the impetus behind that refactor?
13:09cgrandbetter memory usage and better "transient" perfs -- regular perfs are slightly better
13:12danlarkinclojure-json didn't pass its tests on master so I did a git bisect on clojure and it was that commit that breaks it
13:13cgrandwhich test(s)?
13:16danlarkincgrand: the "pass1" test in clojure-json's test.clj directory. It's a big complex json file from json.org
13:25cgranddanlarkin: ok, looking at it
13:26danlarkincgrand: thanks
13:38stuartsierragrigna-ak: clojure.contrib.template became clojure.template, but most of its functionality was removed.
13:38stuartsierraThe clojure.template sources are at src/clj/clojure/template.clj in the Clojure distribution.
13:39Chousukehmm, this looks promising. I changed my reader to use a character sequence instead of a line sequence, and it still works.
13:39grigna-akstuartsierra: thanks
13:40grigna-akblast github still under ddos
13:40ChousukeI should be able to use a PushbackReader as the source now without worrying about consuming stuff than necessary :/
13:40Chousuke+more
13:53ericthorsenIs this a bug?
13:53ericthorsen(def m {:a 1 :a 2 :a 45})
13:53ericthorsenhas 3 items in it
13:53ericthorsenI would have thought it would just have 1 :a ?
13:54Chousukehm
13:54Chousuke,(count {:a 1 :a 2 :a 3})
13:54clojurebot3
13:54Chousukeoops
13:54stuartsierraThat's been ruled not-a-bug, it's an artifact of how ArrayMaps are implemented.
13:55Chousukethen again, I think such a literal is illegal anyway :P
13:55stuartsierraThe compiler accepts it, but the result is undefined.
13:55triyojava.util.HashMap implements java.io.Serializable interface. How come, as far as I can tell, Clojure's map doesn't implement java.io.Serializable?
13:56hiredman,(ancestors (class (hash-map)))
13:56clojurebot#{java.lang.Iterable clojure.lang.APersistentMap java.lang.Runnable clojure.lang.AFn clojure.lang.Seqable clojure.lang.IFn clojure.lang.IMeta java.lang.Object clojure.lang.IPersistentMap java.util.concurrent.Callable clojure.lang.IObj clojure.lang.Counted clojure.lang.Obj java.util.Map :clojure.contrib.generic/any java.io.Serializable clojure.lang.Associative clojure.lang.IPersistentCollection}
13:56hiredman^- no HashMap
13:56triyohmm
13:56ericthorsenstuartsierra: I see...hash-map and the like do the right thing when there are key dups...just surprised me
13:56stuartsierrame too, first time I discovered it
13:57ericthorsenstuartsierra: do you have a link to that discussion by any change? It still feels wrong
13:57ericthorsenchance
13:58stuartsierradon't remember
13:58stuartsierraI think it was on IRC
13:58ericthorsenstuartsierra: I'll fish around for it...thanks
14:02triyohiredman: thanks I see now that hash-map does implement the Serializable interface however I still have a problem. I am trying to use memcached to cache a hashmap. It should work if it is a serializable object however I still get an IllegalArgumentException "Non-serializable object".
14:03hiredman~ticket search Serializable
14:03clojurebot("#174: Make c.l.Keyword Serializable" "#64: GC Issue 61: \t Make Clojure datatype Java Serializable" "#174: Make c.l.Keyword Serializable" "#64: GC Issue 61: \t Make Clojure datatype Java Serializable" "#98: GC Issue 94: \t (ancestors ClassName) does not include tag ancestors of ClassName's superclasses ")
14:04hiredman~ticket #64
14:04clojurebot{:url http://tinyurl.com/kv5v3t, :summary "GC Issue 61: Make Clojure datatype Java Serializable", :status :new, :priority :low, :created-on "2009-06-17T19:38:52+00:00"}
14:17technomancyit doesn't look like there's a way to shut down a single agent, is there?
14:17technomancyjust the whole thread pool
14:18technomancydo they get shut down when GC'd?
14:19hiredmaneh?
14:20technomancysay you've got a rogue agent that's busy doing something you don't want it to do anymore.
14:20hiredmanare you asking if they continue to run after they have been deallocated?
14:20technomancyI guess a running agent would never get GC'd; that doesn't make sense
14:21hiredmanwell, the running action does have a reference to the agent
14:21technomancyI'd like to stop it from the sending context
14:21technomancyI could stop the whole agent thread pool too, but it doesn't look like there's a way to start it back up again once you do.
14:21technomancywhich is weird
14:22hiredmanyou can cancel a future, I believe
14:23hiredman,(map #(.getName %) (.getMethods (class (future nil))))
14:23clojurebot("__initClojureFnMappings" "__updateClojureFnMappings" "__getClojureFnMappings" "get" "get" "hashCode" "clone" "equals" "toString" "deref" "isDone" "cancel" "isCancelled" "wait" "wait" "wait" "getClass" "notify" "notifyAll")
14:30technomancyso even with the ability to get at *agent* from within the running action, you can't stop it.
14:33triyohiredman: patch in #174 fixes the problem. Now that Keyword implements Serializable, I can serialize maps that have keyword objects. thx for link
14:41triyoI am trying to understand when exactly I should use the set! . What I understand is that set! changes mutable state. But then I see this example in the docs: (doto (new java.util.HashMap) (put "a" 1) (put "b" 2)) that also change mutable state yet it doesn't use the set! ?
14:44wtetznerset! is for changing thread-locally bound vars
14:44wtetznerthat example is just calling java
14:44wtetznernot clojure functions
14:47triyook, now I get it. asp. the thread local part. thx
15:11LauJensenWhat do you guys consider the main advantage of Clojure non-distributed approach to concurrency ?
15:13Chouser:-)
15:14LauJensenhehe :)
15:14LauJensen...but I promised them :)
15:16stuartsierraLauJensen: multi-core is the future
15:16LauJensenstuartsierra: so? the distributed model is also well suited for mc
15:17stuartsierrabut less efficient than share-memory multi-threading
15:17LauJensenIsn't that theoretically, it's basically the same stuff under the hood isn't it ?
15:18stuartsierrawell, it's all theoretical now, since no one's building 1000-core machines yet
15:19Chousukereality often gets in the way of theory :/
15:20LauJensenhehe
15:20stuartsierrayeah, it's going to depend a lot on the hardware/software implementations
15:20LauJensenYou guys should get into making t-shirts :)
15:20Chousukemostly because the theories fail to take into account everything that happens not directly related to the phenomenon one is theorising about.
15:25LauJensenI think I'll do the Sleeping barber problem in Scala + Clojure, that should be grounds for comparison
15:34Anniepoojust on for a moment, but had to laugh - Amazon's spam 'you might also like' email to me features 'programming scala'
15:34Chouserwell... you might!
15:34Chouser:-)
15:34AnniepooLOL
15:35Chouseronce clojure-in-clojure is done, we can have a back end that emits Scala code.
15:35Anniepoolol
15:35LauJensenChouser, did you know that Scala is already implemented in Scala?
15:36ChouserI didn't.
15:36LauJensenThey beat you to it man
15:36Chouserso why do they only have the one back-end?
15:36ChouserI know they sorta support CLR
15:37LauJensenI don't know. And also... I should say, most of the info I got from IRC was pulled as soon as I posted the article
15:37LauJensenSo, some people may have spoke too soon, I don't know
15:37Chouserpulled?
15:38LauJensen'retracted'
15:38Chouserhow do you retract something from IRC?
15:38LauJensenYou don't, but they asked me to remove it from the website
15:39Chouserhuh
15:54technomancyAnniepoo: which "Programming Scala", that's the question?
15:54Anniepoosome new one from Oreilly. That was it's name
15:54Anniepoo(title)
15:58cgranddanlarkin: ok, fixed
15:59danlarkincgrand: wow, nice!
15:59danlarkincgrand: where can I see it?
16:01hiredmanLauJensen: that blog post just seems to sow enmity between scala and clojure
16:01cgrand,(count (reduce conj (hash-map) (for [i (range 30)] [i nil])))
16:01clojurebot30
16:01LauJensenhiredman: Which one?
16:02cgranddanlarkin: here http://github.com/cgrand/clojure/commit/40a0cd947b6eb03396756566683841878f480e8a I'll create an issue later
16:03hiredmanLauJensen: there is another one?
16:03danlarkincgrand: and a test case too I hope :-)
16:03LauJensenhiredman: There's one brewing
16:03LauJensenBut let's take this in private
16:03hiredman
16:03hiredmanI'd rather not
16:06danlarkincgrand: well that's awesome, I'm glad you were able to fix it, thanks again
16:21cgrand,*clojure-version*
16:21clojurebot{:interim true, :major 1, :minor 1, :incremental 0, :qualifier "alpha"}
16:22lpetit,(clojure-version)
16:22clojurebot"1.1.0-alpha-SNAPSHOT"
16:22Chouserit wouldn't always be completely useless to include the git SHA1 in that
16:23Chouseroh, nm. :-/
16:23lpetit:)
16:23lpetitwould be an interesting exercise :)
16:23cgrand,(resolve 'transient)
16:23clojurebotnil
16:24Chouserwell, you'd have to be careful to never include the SHA1 if the working copy were dirty
16:24Chouserotherwise you might have a version claiming to be something it's not, which would be worse than useless.
16:25lpetitYou mean the SHA1 of the future commit object ,
16:25clojurebotlpetit: the fn created by future (like all fns) doesn't close over dynamicly scoped stuff
16:25lpetit?
16:25cgrand1.1 pre transient that's why (count (reduce conj (hash-map) (for [i (range 30)] [i nil]))) returns 30...
16:25cgranddanlarkin: this is my test case (= (count (reduce conj (hash-map) (for [i (range 30)] [i nil]))) 30)
16:26Chousereven if that were easy at 'ant' time, it would still be rediculously hard -- what if someone tweaked their core.clj and re-loaded it? still misleading without any build process getting a chance to turn off the SHA1
16:26Chouserridiculously
16:28lpetitNot sure. Either you trust the source of what you're getting, either you don't trust. Having the wrong SHA1 in a lib you get from 3rd party may be the less dangerous security hole :)
16:30triyoI used elpa to install latest ver of clojure in my emacs env. How do I go about keeping that latest ver of clojure up to date?
16:44triyohmm never mind :)
18:13somethingI'm opening up a clojure repl in my clojure app, I want the repl to change the namespace like execute in-ns, is there a way to do that?
18:36hiredmanhmmm
19:55technomancy(:use [clojure.test]) ; <= feels good to finally be able to type that
20:02technomancy(doc with-ns)
20:02clojurebot"clojure.contrib.with-ns/with-ns;[[ns & body]]; Evaluates body in another namespace. ns is either a namespace object or a symbol. This makes it possible to define functions in namespaces other than the current one."
20:04technomancyI'm kind of tired of copying my delete-file-recursively function around to all my different projects... should it go in contrib?
20:09technomancyobviously it belongs in the JDK, but I don't think that's going to fly
20:25Chousertechnomancy: sounds reasonable to me. is there a namespace already where it would fit?
20:26technomancyChouser: that's the problem really
20:26technomancythere's a bunch of file-related stuff under java-utils that could be spun out into file-utils, but I feel uncomfortable about moving stuff like that
20:34kanakhas anyone here tried doing Norvig's PAIP in clojure?
20:37kunjanthat is an awesome project. why dont you write a blog about it?
20:37clojurebothttp://clojure.org/rationale
23:52jamespHi guys, Could you by chance help me out with a java interop question? I'm afraid I not written much java.
23:52hiredmanask away
23:53jamespI'm attempting to use a library for handling asynchronous events. The last call in the example java code is:
23:53jamespObject object = new Object(); synchronized (object) { object.wait(); }
23:54hiredman:(
23:54jamespHow on earth do I replicate that in clojure code?
23:54hiredmanwhere is the example?
23:57jamespLet me see if there is an example online