#clojure logs

2010-05-30

01:04hiredman,(+ 1 2)
01:04clojurebot3
01:05hiredman(doc map)
01:05clojurebot"([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]); Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments."
01:20defnmmmm map
01:24KirinDaveI think I am finally starting to understand how protocols are meant to be used.
03:15vIkSiThmm, could anyone explain the concept of currying?
03:15vIkSiTand how one does it in clojure?
03:16vegaiit's partial application
03:17vegaiif you have a function f that takes two parameters, you can bind the first parameter and get a new function that takes the remaining parameter
03:18vegailet's say sum function f(x,y)=x+y, you can get an inc from that by g(y)=f(1,y)=y+1
03:18vIkSiTvegai, right. I think I understand that - but I still don't know why it would be used. One thing I can think of is to eliminate anonymous functions?
03:18vegaidunno exactly how it works in clojure
03:19vegaiit allows an additional form of abstraction. IMHO, not a very important one, but Haskellists seem to enjoy it
03:19vegaiyeah, it's kind of a shortcut for some lambda forms
03:20vIkSiTah
03:20vIkSiTlooks like js has a curry function too, and it seems applicable in prototype.js
04:28vIkSiTargh
04:28vIkSiThow do i break an infinite loop using slime/emacs?
04:28LauJensen,q
04:28clojurebotjava.lang.Exception: Unable to resolve symbol: q in this context
04:29vIkSiTLauJensen, ?
04:31RaynesNot sure he was answering your question.
04:32vIkSiTaah.
04:32vIkSiThmm, i'm sure there must be a way
04:32hoeckvIkSiT: ctrl-c or ctrl-g
04:33vIkSiTokay, so perhaps someone can help me out with the problem. trying to do : a function f that takes a list [1 2 3 4], and returns all sublists formed by removing successive elements..
04:33vIkSiTso (f [1 2 3 4] should give me [1 2 3 4] [2 3 4] [3 4] [4]
04:33vIkSiThoeck, :) will try
04:33RaynesThat wont work.
04:34hoeck,(reductions pop [1 2 3 4])
04:34clojurebotjava.lang.IllegalArgumentException: Wrong number of args passed to: core$pop
04:37hoeck,(reductions (fn [c _] (next c)) [1 2 3 4] [1 2 3 4])
04:37clojurebot([1 2 3 4] (2 3 4) (3 4) (4) nil)
04:37vIkSiThmm, how does that work exactly?
04:38hoeckreductions is like reduce, but it returns intermediary results
04:39vIkSiTah
04:39vIkSiTalso what is the fn [c _] doing?
04:39vIkSiTwhy not just fn [c]?
04:39hoeckit ignores the second argument, therefor the idiomatic underscore
04:39RaynesBecause the function needs to take two arguments.
04:40vIkSiT,(doc reductions)
04:40clojurebot"([f coll] [f init coll]); Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with init."
04:40hoeckbasically thing reduces a sequence to nothing, because were only interested in the intermediate results
04:41vIkSiThmm tying to understand why that function needs 2 args
04:41LauJensenvIkSiT: What I meant was, that if the SLIME buffer hangs in a loop, ",q" will quit it
04:42hoecknormally, you want reduce to do something useful, like (reduce + '(1 2 3))
04:42hoeckor (reductions + [1 2 3])
04:42vIkSiThoeck, right
04:43hoeckbut you are only interested in the intermediate steps of "eating" a sequence
04:43vIkSiTaaaah
04:43vIkSiTgotcha.. the second arg is never used
04:43hoeck,(next [1 2 3 4]
04:43clojurebotEOF while reading
04:43vIkSiTits just a placeholder
04:43hoeck,(next [1 2 3 4])
04:43clojurebot(2 3 4)
04:43hoeck,(next [1 2 3])
04:43clojurebot(2 3)
04:43RaynesIn your case, the second arg is never used.
04:43hoeckand so on - right
04:43vIkSiTright, i understand now
04:43RaynesBut in the case of (reductions + [1 2 3 4]), the second arg is being used.
04:43vIkSiTso, what would be the idiomatic functional way of doing this?
04:43vIkSiTI was trying to do a loop recur version of this and hitting the inf loop
04:44hoecksince reductions is in core now, I guess its idomatic and functional, its even lazy :P
04:46hoeck,(map #(nthnext [1 2 3 4] %1) (range 4))
04:46clojurebot((1 2 3 4) (2 3 4) (3 4) (4))
04:47vIkSiTLauJensen, btw, i didn't wnat to close the slime buffer itself. i was just hoping to break the loop without having to close the buffer itself..
04:47hoeckworks too, but only for vectors, not for lists
04:47vIkSiThmm
04:48vIkSiTah thanks, let me check that
04:48vIkSiThttp://paste.lisp.org/display/110963
04:48vIkSiTi'm tryhing to do something like that
04:49vIkSiThoeck, re the generating sequences bit
04:51vIkSiTany suggestions on how that would/should work?
04:51hoeck(recur (next c)) instead of (recur (next coll))
04:53hoeckand instead of (zero? (count c)), use (empty? c)
04:54vIkSiThoeck, ah, but the point i'm still stuck at is - how do i recur AND use conj to build the sequence?
04:54vIkSiTusually the recur examples happen like : (recur (dec n) (* factorial n)))))
04:54vIkSiTwhere n is being decremented
04:54vIkSiTbut in my case - i'd like to pass in a seq
04:55hoecksee http://paste.lisp.org/display/110963#1
04:57vIkSiThoeck, ah interesting. whats the <computed value> part about?
05:00hoeckthere, you place your value
05:01vIkSiThoeck, not sure i understand
05:01hoeckvIkSiT: http://paste.lisp.org/display/110963#2
05:03vIkSiToh. does this imply that during a recur, a (next c) is actually passing the next into the recur form?
05:03vIkSiTso in that line : (next c) (conj ret c), c is now (next c). It got modified
05:04ChousukevIkSiT: it didn't get modified, it gets rebound
05:04vIkSiTah I see
05:05Chousukeit kind of appears to be the same thing though, but since Clojure is a functional language, it's good to keep the terminology separate
05:23vIkSiTChousuke, agreed
05:23vIkSiTbrb
05:48pastornRaynes: hello :D
05:48Raynespastorn: Ohai.
05:48Raynes:D
06:00naeuwhat's the easiest way to call functions A and B 1000 times each in parallel?
06:06Chousuke(future (dotimes [i 1000] (a))), repeat for b?
06:06naeuoh, interesting, I hadn't considered futures
06:07naeuI was just looking at the following: (pcalls #(dotimes [_ 1000] (a)) #(dotimes [_1000] (b)))
06:08Chousuke(doc pcalls)
06:08clojurebot"([& fns]); Executes the no-arg fns in parallel, returning a lazy sequence of their values"
06:08ChousukeI had forgotten that entirely :P
06:11naeulooks pretty nifty :-)
07:32LajlaChousuke, Se Lexx on fallinen.
07:47_na_ka_na_Q: I just learnt that calling (seq coll) where coll is itself a lazy-seq would realize the 1st element of coll. Any clues why seq was chosen to behave this way, it must have some other utility??
07:48OForeroI am having some issues trying to run circumspec tests
07:48OForerohttp://paste.pocoo.org/show/219948/
07:49OForeroI used the scripts from labrepl that appear to work
07:49OForeroany ideas?
10:59defnis it possible to destructure over a coll?
10:59defnnevermind im thinking backwards i think
10:59Raynesdefn: As long as you aren't thinking sideways.
11:00defn:)
11:01defnI have something like (let [[[k v]]] '(("a" "b") ("c" "d")) {k v})
11:01defnwhich embodies what im trying to do, but id like to apply that to all of the items in a coll, not just the first element
11:02defn,(let [[[k v]] '(("a" "b"), ("c" "d"))] {k v})
11:02clojurebot{"a" "b"}
11:05dnolen,(into {} (map vec '(("a" "b") ("c" "d"))))
11:05clojurebot{"a" "b", "c" "d"}
11:05defndnolen: thanks
11:35_na_ka_na_anyone know what fn* is? in source lazy-seq
11:36BorkdudeIs there an easier way to accomplish this, e.g. without force-set? http://gist.github.com/419108
11:40alexykis there a blog aggregator for clojure blogs one can submit his to?
11:40Borkdudealexyk: there was http://clojure.in/ I thought, but now it says: coming soon
11:40eevarhttp://www.reddit.com/r/clojure ?
11:42joshua-choi_na_ka_na_: fn*, I believe, is a special form of Clojure that you don't have to care about. Its purpose is to provide the base implementation of the clojure.core/fn macro.
11:43_na_ka_na_joshua-choi: ok so for all purposes (example understanding source) I may assume its same as fn?
11:43joshua-choiVery similar. Not exactly the same in arguments, maybe.
11:43joshua-choiLook at what clojure.core/fn does in terms of fn*.
11:49_na_ka_na_Borkdude: (reduce (fn [m [k v]] (assoc m k (conj (m k #{}) v))) {} (concat {:a 1 :b 2} {:a 1 :b 3}))
11:53Borkdude_na_ka_na, my purpose was to provide a fn to merge-with, sorry I didn't made that clear
11:53Borkdudebut maybe there was already smth in Clojure like force-set
11:54Borkdude,(merge-with (fn [r l] (if (set? r) (conj r l) (conj #{} r l))) {:a 1 :b 2} {:a 1 :b 3})
11:54clojurebot{:a #{1}, :b #{2 3}}
12:03_na_ka_na_i once saw a uml kind class diagram for the java source of clojure .. anyone knows where to get the most updated version of that ?
12:03replaca,(merge-with (fn [r l] (if (set? r) (conj r l) (conj #{} r l))) {:a 1 :b 2} {:a 1 :b 3 :c 5})
12:03clojurebot{:c 5, :a #{1}, :b #{2 3}}
12:04joshua-choi_na_ka_na_: There's a chart for Clojure's core classes and interfaces.
12:04replacabut that's not so satisfying
12:05_na_ka_na_joshua-choi: link?
12:06joshua-choi_na_ka_na_: It was on among the Google group's files, but I couldn't find it there. It's at here too though: http://bc.tech.coop/blog/081108.html
12:37Licenser(doc partition-all)
12:37clojurebot"([n coll] [n step coll]); Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end."
12:38Licenser(partition-all 1 (range 10))
12:38Licenser,(partition-all 1 (range 10))
12:38clojurebot((0) (1) (2) (3) (4) (5) (6) (7) (8) (9))
12:43pdktesting
13:04Borkdudereplaca: right
14:14raek_na_ka_na_: saw your unaswered question from some hours ago. (seq coll) have to realize the first element in order to know whether it should return nil or not
14:14raek(seq coll) always return nil if there are no elements
14:50krumholthi. i am looking for a way to apply a function exactly n times. example: (bar 5 foo arg) would be (foo (foo (foo (foo (foo arg)))))
14:56Raynestechnomancy: Pingy.
14:58hoeck,(first (drop 5 (iterate - 1)))
14:58clojurebot-1
14:58hoeckkrumholt: ^
14:59LauJensenhoeck: perhaps 'take' would be better than 'drop'
14:59krumholthm ok i coud do nth too right?
14:59LauJensenyea
15:00krumholtok thanks
15:00hoeckLauJensen: I assumed he is interested in the sixth function application, not the whole seq of intermediate results
15:01hoeckor (reduce (fn [a _] (- a)) (- 1) (range 0 6))
15:01LauJensenhoeck: Ok - He said 'I need to apply a function exactly n times'
15:01hoecka bit uglier in my eyes, but potentially more efficient
15:31datkahas anyone managed to get compojure 0.4 working with maven and the maven jetty plugin?
15:32datkaor at least in a situation where it works compiled to a war.
15:58bozhidarwhat would be idiomatic way to create a sequence comprising of several same values?
15:59bozhidarin my case I'd like to do an (apply * [2 2 2]) (2 to the power of 3)
16:00bozhidarI cannot use Math/pow since it works with double, and I'm about to the some BigInt calculations
16:00bozhidars/the/do
16:04krumholt,(repeat 3 5)
16:04clojurebot(5 5 5)
16:05krumholtbozhidar, or in your case (apply * (repeat 3 2))
16:05krumholt,(apply * (repeat 3 2))
16:05clojurebot8
16:06bozhidarkrumholt: 10x, that's exactly what I needed. I weren't aware of the existence of repeat
16:11pf_mooreHi - dumb question, but how do I refer to something on clojure.contrib from a .clj script?
16:11pf_moore(refer clojure.contrib.accumulators) doesn't work for me...
16:12pf_moore(I have clojure-contrib.jar in my classpath
16:13bozhidarpf_moore: I think you forgot to quote the namespace symbol
16:13bozhidar(refer 'clojure...
16:14bozhidarand you should have done an require before that
16:14bozhidaror you can simply do use to combine require & refer in a single step
16:15pf_mooreAh! I'd tried quoting, but missed that it was a different error. Sorted now, thanks!
20:15joshua-choiHey, let's hypothetically say that I have an immutable data structure implemented in Clojure called a Relation. If I want to coordinate a mutating database, should I use many refs each of a Relation, or should I use one ref of a map of Relations?
20:42tomojjoshua-choi: I think it depends
20:43joshua-choiHmm
20:43tomojone ref is prettier, but means anyone changing the database has to compete
20:43tomojmany refs is ugly but only changes to the same ref need to compete
20:43tomojsame ref(s) I mean
20:44joshua-choiAre there any other disadvantages to many refs that you can think of?
20:44tomojI can't, but that is not good evidence that there aren't any :)
20:44joshua-choiYou know that "Functional Relational Programming" paper that Rich Hickey said was an inspiration for Clojure, or something? I'm thinking of writing a library modeled very closely to that with datatypes and protocols, just for kicks
20:44joshua-choiThis question is very germane to that
20:45tomojthe turing tarpit paper?
20:45joshua-choiYeah
20:45tomojcool, good luck
20:45joshua-choiBut I gotta release the FnParse beta first, now that I got Autodoc to work
21:36jcromartieI HATE MUTABLE OBJECTS
21:37jcromartiehi
21:37jcromartiejust wanted to share
21:51greghyou're in the right place
21:51greghthat is all
21:51programbleomg mutation
22:03jcromartie"Mutable objects are the new spaghetti code" is a quote that will go down in history.
22:09programbleyum, spaghetti
22:09programblewith mutable tomato sauce?
22:10jcromartiebased on the stains in my tablecloth, tomato sauce is persistent
22:50tetronI'm trying to figure this out, is tail recursion as a way of passing program state between iterations of a loop good or bad in clojure?
22:51tetronI understand that clojure doesn't do tail recursion, so...
22:51tetrontail recursion optimization, I mean
23:09chousertetron: direct recursion without 'recur' or 'lazy-seq' may cause problems if you're doing a lot of iterations.
23:09chousers/may/will/
23:09sexpbottetron: direct recursion without 'recur' or 'lazy-seq' will cause problems if you're doing a lot of iterations.
23:10redalastorI'm looking for a way to take a make a seq that is the cumulative sum of another seq. I'm currently thinking of recur, is there a cleaner way?
23:11chouser,(reduce + [2 4 6])
23:11clojurebot12
23:11redalastorchouser: I meant if the first seq is (1 2 4), the second should be (1 3 7).
23:12tomojthere's reductions somewhere
23:13chouseryeah, reductions is what you want. it's in clojure.core in 1.2-snapshot
23:14chouser,(reductions + [1 3 7])
23:14clojurebot(1 4 11)
23:14chouseroh
23:14chouser,(reductions + [1 2 4])
23:14clojurebot(1 3 7)
23:14chouseryes.
23:14redalastorWow. I'm impressed, I didn't know this existed.
23:15tetronchouser: that's what I thought, perhaps "trampoline" what I am thinkiing of?
23:15redalastorthanks
23:16chousertetron: if you need some kind of recursion, lazy-seq, recur, and trampoline are all options that may help.
23:17tetronchouser: well, what I need is essentially an event loop where the state changes each time through
23:18tetronso it seems like either one can rebind a var (in a transaction?) or pass the new state in a tail-recusive call
23:20tomojmaybe you want an agent that sends the new state to itself?
23:20tomojor keep the state in refs/atoms?
23:20tetronyea, perhaps
23:21chouserthe loop blocks waiting for events?
23:21tetronno, actually it's a discrete event simulation
23:22tetronwell, actually it's a learn-clojure simulation :-)
23:22chouserhehe
23:22tetroncoming from a common-lisp background
23:23tetronsort of
23:23chouserself-sending agent is likely what you want. have you looked at Rich's ant sim?
23:23tetronyea, I did
23:23chouserI used a similar technique in a little demo sim I did for a talk a couple weeks ago.
23:24tetronthat works then
23:24chouseroh, ok. so send-sending agents is how the ants simulate events.
23:25tetronso is there an effective difference between that and a trampoline except for which thread it runs on?
23:27chouseryes, they do have somewhat similar runtime shape if you will. I hadn't ever thought of it that way.
23:27chouserin both cases you do some work, then package up your state in a function call (or a function call + agent state), and pass that to some 3rd party to have it executed
23:28chouserwith the agent, other threads can observe the agent-state part which of course isn't the case with trampoline
23:29tetronI see
23:31tetronI don't suppose you have a link to the ant demo?
23:32tetronn/m, going to bed
23:32tetrongood night
23:32tetronthanks