#clojure logs

2008-06-20

01:54Lau_of_DKMorning folk
02:21cgrand1morning Mr Lau
05:49Lau_of_DKcgrand - Can you post the link to your blog again ?
06:22cgrandclj-me.blogspot.com
06:23cgrandStill trying to find the first x! with 7^20 trailing 0s?
06:44Lau_of_DKcgrand - If you have one I'd love to hear it, Im thinking that maybe brute is not the best way to go
06:51cgrandwhen you define naturals like this (def naturals ((fn [x] (iterate inc x)) 1)) the thing to know is that all computed values will stay in memory
06:54cgrandthat explains why you run out of memory with the code you pasted
06:58cgrandplus, you are testing all the naturals til you found the first natural wich can be divided by 10^(7^20), which even if you test 10^9 numbers by second would take 10^(7^20-3) seconds to run...
07:01Lau_of_DKyea, so youre saying its a dumb approach which is exponential in time consumption?
07:01smeehey
07:02smeecgrand, how's your blogpost about parallelizing widefinder2 coming along?
07:08cgrandLau_of_DK: no I think that brute force may work but you have forgotten to apply the factorial
07:11cgrandsmee: I hope to post something this afternoon (er.. I mean in the next hours) I played a lot with the server trying different implementations (the naive one to which I allude in the previous blog post works pretty well with a few cores (2-4) but not with 32 -- the bottleneck is shifting from CPU to IO) and resolving some GC problems
07:16smeecgrand: nice, thanks. looking forward to it, as the documentation of using the concurrency feats of clojure is quite sparse...
07:34cgrandLau_of_DK: hmm after some trials, I was wrong: brute force won't cut
07:37lisppaste8cgrand annotated #62507 with "Brute force does not work :-(" at http://paste.lisp.org/display/62507#1
07:40Lau_of_DKcgrand, ok, thanks for looking into it
07:41Lau_of_DKI actually think that theres a pattern emergin in the number of trails
10:29cgrandrhickey: from the main thread I send an action to agent A, in this action I send an action to agent B. After awaiting A, on the main thread, I can await B. No?
10:43rhickeycgrand: you can await B, but there is no guarantee your wait request will follow A's send to B
10:48cgrandso I have to send a second action from A to B, which action would .countDown on a latch while the main thread await this latch or something like that?
10:49rhickeyis there some context here that could help me understand what you are trying to do?
10:52cgrandok
10:56cgrandI have some workers (agents) which when they are done with their batch send the result to an accumulator agent. I want to know when the accumulator is done.
10:56rhickeydoes the accumulator know when it's done?
11:05cgrandno
11:08rhickeydo only the distributor knows how much work was dispatched? does it know how many agents will be created to do the work?
11:08rhickeyor how much work there is, in advance?
11:09rhickeyyou can either send a sentinel/shutdown job through or wait on a completion counter
11:10cgrandthe distributor doesn't know how the amount of work in advance but it knows how many agents there are (it creates them)... so it's a sentinel in that case I guess
11:12rhickeythe sentinel job can decrement a countdown latch
11:12cgrandok
11:18cgrandthanks, that what I was after.
11:25cgrandBut right now the await trick works, no? It's not clear for me which are the guarantees of the agents system. I thought that they ware: 1/ in order execution of all actions dispatched from one thread to one agent and 2/ when await returns, all actions dispatched from the awaited agent are enqueued in the target agents. So I suppose you don't guarantee the second point.
11:25cgrands/ware/were/
11:29rhickeyright, point 2, while currently true, is not a guarantee. What is guaranteed is the order of actions sent A) from the same agent to a single agent, B) from the same thread to a single agent. An await is just another action. Message sends are technically asynchronous
11:30rhickeyif you were to build on the fact that a's sends were queued before a returned, then your architecture would break as soon as b's started delegating to c's
11:30rhickeyi.e. the trick only works for one hop
11:31cgrandyup
11:32rhickeyawait is just for the simplest cases - queues and latches are the right way to do workflow, and Java has a good suite
11:35cgrandok -- I'm doing some cleaning on my wf2 implementations
11:36cgrandbtw why is butlast eager?
11:43rhickeyno good reason, probably because I needed it for defn and just hacked last
11:49cgrandAh, ok.
11:49cgrandAm I wrong thinking you are cleaning locals before tail call?
11:50rhickeyyes, I'm clearing locals on tail call
11:53drewrAfter evaluating (def foo 1) (def foo 2), what happens to the first object foo was pointing at? I'm assuming it gets garbage collected?
11:53rhickeydrewr: yes
11:54drewr...assuming nothing else is reading it I guess.
11:58cgrandand on a "tail loop" as well?
12:00rhickeyno, since the body might need them again, but of course the loop 'args' are replaced by the new values
12:05drewrWow, jochu's been busy.
12:05drewrswank-clojure now has sldb support.
12:56drewrHow do I kill a thread that I SEND-OFFed?
12:57rhickeykilling threads is generally bad practice - what is it busy doing?
12:57drewrQuerying a database.
12:58drewrI didn't give my query a sufficient WHERE clause to keep it from running for way to long.
12:58drewrtoo
12:58rhickeycan you break the db connection?
12:59drewrAh, (.close *conn*) did the trick.
12:59drewrThen my agent got SQLException. Nice.
13:00drewrSo what happens to old agents, they just get GC'ed too?
13:00rhickeyGC is pervasive - things no longer referenced get GCed eventually
13:01rhickeybut yes, there is no registry of agents to clean up
13:02drewrRight, I was making sure there wasn't a Clojure-y thing I needed to do to say I was done with it.
13:40Lau_of_DKEvening Gents
13:43drewrYo.
13:56meredyddHey, rhickey
13:56rhickeyhi
13:56meredyddIn the 'set namespace under what conditions does (join) return nil?
13:56meredyddI was expecting an empty relation (#{})
13:58meredyddIt seems to be "when one of the relations is empty"
13:58meredydd(join #{{:a 0 :b 1}} #{{:a 1 :c 2}}) gives an empty set; (join #{{:a 0 :b 1}} #{}) gives nil
13:59rhickeyI see
14:00meredyddAh...you have a "(when (and (seq xrel) (seq yrel)))"
14:00rhickeyfixing now, hang tight...
14:00meredyddta
14:04rhickeyI've made that return an empty set for now, but wonder if both cases shouldn't return nil...
14:06meredyddAs I see it, if you're looking for a faithful representation of the relational algebra, the empty set is the mathematically correct thing to have
14:07Lau_of_DKhow is that more correct than nil?
14:07meredyddLau_of_DK: You can (conj) onto it, for starters
14:07rhickeyif you end up with a lot of (if (zero? (count result)... then I disagree
14:07rhickeythis is a Lisp with a CL bent in this area
14:08meredyddI agree entirely on the subject of convenience
14:08meredydd(I'm doing (= best-match #{}) myself)
14:08rhickeythere you go :)
14:08meredyddTo be honest, a little bit of me secretly wishes that all the empty collections were logical "false" values
14:09meredyddBut I feel profoundly uncomfortable with a (join) operation that isn't guaranteed to return a relation
14:10rhickeythat would be a reduction in power, since the current strategy gives you the ability to distinguish the two
14:10meredyddUh-huh - I understand why you did it.
14:10meredydd(although one could also argue that even under the current scheme, you retain the ability to distinguish between 'false' and 'nil')
14:11rhickeyI understand about the empty set, I think I returned that against my Lisp inclinations for fear of lack of composability in this algebra, although I don't know that that is the case
14:11meredyddHeh. It is definitely in mine - one of the next things I do to the return value is (conj) another map onto it
14:13Lau_of_DKI cant find this on the website, but what was the form from printing ints as either hex or binary
14:19Lau_of_DKzzZZZ
14:20meredyddEh-oh. I just pulled your latest from the repos, and the Repl now won't start.
14:20rhickeyclean?
14:20meredyddCaused by: clojure.lang.Compiler$CompilerException: proxy.clj:52: clojure.lang.RT.cons(Ljava/lang/Object;Lclojure/lang/ISeq;)Lclojure/lang/ISeq;
14:20meredyddoh, oops.
14:21meredyddThat worked.
14:21Lau_of_DKrhickey, after answering my binary question, maybe you should make a script to fetch the svn, clean up and compile, it seems to be a common pitfall
14:26meredyddrhickey: If you do change your mind on (join) behaviour (although I favour the #{} representation), could you drop a note to the Google Group? Fool that I am, I'm writing stuff on top of this functionality, so would appreciate the notice to go change things.
14:26rhickeyleaving it where it is for now, will mention on group if changed
16:03wwmorgan(fn [[a & b]] (if (nil? a) 0 (recur b))) works for all vectors except []
16:03wwmorganshould it throw an except when it gets passed []?
16:04drewrwwmorgan: Why [[a & b]] ?
16:05wwmorganyou mean instead of [coll] then let [[a & b] coll] ?
16:05drewrAre you trying to destructure a vector parameter?
16:06wwmorgantrying to destruct an seq-able parameter
16:07wwmorganvectors, strings, etc
16:14drewrI assume since A is a required param that [] should throw an exception.
16:15wwmorganI thought the behavior was to set a to nil then?
16:15wwmorganbecause it works if you pass in nil but not []
16:19wwmorganI think it's because it calls nth and rest on the parameters
16:20wwmorganand (nth nil X) is nil for all X
16:20hoeckwwmorgan: yeah, and (nth [] 1) is an Exception
16:21wwmorganright, although it's (nth [] 0) in this specific case
16:22hoeckor generally nth'ing on the empty vector
16:23wwmorganbut (first []) is nil
16:24hoeckyes, but it reads as (first (seq []))
16:24hoeckit makes a seq 'view' on the vector
16:24hoeck(get [] 0) returns also nil
16:25wwmorganshouldn't sequential decomposition also read a seq view?
16:26hoeckit does, but only the b in [[a & b]]
16:26wwmorganright, which is why the function above works for non-[] values
16:28wwmorganit looks like sequential decomposition calls nth instead of get
16:28hoeckexactly
16:28wwmorganis this right or wrong?
16:29hoeckto use `get', just wrap (binding [nth get] ... ) around your function
16:30wwmorganoh yeah, there are a few ways to do it
16:30wwmorganI guess this is more of a feature request
16:31lisppaste8Lau_of_DK pasted "Delayed execution" at http://paste.lisp.org/display/62570
16:32Lau_of_DKGents - This little setup-ui implements 3 event listeners, on click, on property change, and on action. They all work, but only onClick outputs the result immediately, so if I change the property 3 times, and then click on the form, it outputs
16:32Lau_of_DKchanged
16:32Lau_of_DKchanged
16:32Lau_of_DKchanged
16:33Lau_of_DKclick
16:33Lau_of_DKbut I dont see the 3x changed, before I fire OnClick - Why is that ?
16:35blackdogi don't println to the stdout either, i didn't investigate but i use an alert instead (defn alert [mess]
16:35blackdog (. JOptionPane showMessageDialog (Gget :frame) mess))
16:36Lau_of_DKoh, so its a stdout issue?
16:36Lau_of_DKcause alert fires like it should
16:37blackdogyea, i think it's that, or maybe swing redirects stdout or something
16:37blackdogdon't know
16:37blackdogif alert works i think it's all good, maybe use a logger instead of stdout
16:38Lau_of_DKYea, alert works, so I'll simply implent the real event handlers
16:38Lau_of_DKIts the firing time that mattered
16:38cemerickrhickey, hoeck: I think wwmorgan is right -- that's a bug. [] should destructure just as well as the empty list.
16:38Lau_of_DKThanks alot Blackdog
16:38blackdogyw
16:38cemerick(let [[a & b] '()] 0) works but (let [[a & b] []] 0) doesn't.
16:39cemerickOr, it's a bug at least insofar as I read the section on destructuring at http://clojure.org/special_forms
16:43hoeckcemerick: but the special-forms page mentions nth explicitly
16:45cemerickhoeck: that doesn't strike me as a problem. In this case, if 0 and 1 are illegal indices, then I would expect clojure to catch those exceptions and substitute nil so as to be congruent with how seqs are destructured.
16:45hoecki have never used destructuring for traversing vectors, only to hold and destructure data, so that excepion was quite useful
16:45cemerickOtherwise, vector (and string) destructuring has these odd corner cases, and you really need to wrap everything going into a destructured let in a (seq ...)
16:46hoeckyeah, thats bad, especially when destructuring in a fn or defn (where you can't call seq)
16:48cemerickRight. It certainly seems like a straightforward problem (although I'm currently looking for my flak jacket for when Rich lands on me for making such pronouncements ;-)).
16:48rhickeyI was just looking at this, destructuring seqs with nth. The docs and behavior match (it says it will use nth, and nth on vectors has that behavior), but I agree that get might be more useful
16:50cemerickrhickey: nth is used instead of get for performance?
16:51hoeck:or in vector/seq destruction would be usefull too!
16:54rhickeynth is potentially faster as it is just about indexed access, i.e. the key is known to be an int
16:55rhickeycemerick: in any case Clojure is not going to catch exceptions in normal control flow
16:56cemerickrhickey: Sure, right.
16:56rhickeythe tradeoff is a lack of 'arity' checking
16:56rhickeywhich has utility for sequential destructuring
16:57cemerickrhickey: Isn't that true when destructuring a seq, though?
16:57Nafairhickey: Watching your Clojure for Java programmers talk. Enjoying it so far.
16:57rhickeythe real problem may be nth's different behavior for seqs
16:57rhickeyNafai: great!
17:00cemerickWell, in any case, I'd certainly like to see destructuring "work" for all seqs, vectors, and strings. I think defaulting to nil is the right behaviour, and goes nicely along with default behaviour for (and), (+), etc.
17:24rhickeyok, SVN 915: nth takes an optional not-found value, and destructuring uses nth with a nil not -ound value for sequential destructuring, nth without not-found value throws exception in all index-out-of-bounds cases including seqs
19:09Lau_of_DKI have a function that supposed to resize an image in a swing gui, but instead of resizing it sounds the system bell, no warnings, no exceptions, nothing - How do I figure out whats firing the bell?
19:11Lau_of_DKIm asking for a general approach - the specific problem doesnt matter
19:12Chouser_can you break it up into smaller pieces?
19:12Lau_of_DKThats what I usally do, but it seems like the Flintstones approach
19:18Chouser_Hm. I must live in Bedrock.
19:19Lau_of_DKDont be offended
19:19Lau_of_DKI'm just used to Visual Studio : "Cast type exception thrown: main.cpp [line: 25;column:8]"
19:19Lau_of_DKThat speeds up development by about 1600% compared to splitting routines up
19:24Chouser_Does Visual Studio capture beeps? ;-)
19:26Lau_of_DKsure :)
19:27Lau_of_DKBut you get the point right? Bug-hunting could probably be simplied
19:33Lau_of_DKNevermind, I'll explain it tomorrow, sleep tight Chouser + the rest of the gang