#clojure logs

2008-03-27

09:52Chouserrhickey: if you don't mind sharing, is that corporate or academic work?
09:53rhickeyI work for myself
10:05Chouseryou've found customers for your work, or you have sufficient capital you don't need customers yet?
10:06ChouserI don't mean to pry, I'm just very curious.
10:06rhickeythat's something I can't discuss
10:06Chouserok
10:07Chouserwell, I'm sure glad you've taken the time to work on Clojure. :-)
10:07cgrandMaybe it's old news to you but I just noticed this morning that the Eclipse debugger is able to step into clojure code (highlighting current line etc.).
10:08rhickeyme too - I finally get to develop software the way that I want to, and have huge libraries at hand
10:08rhickeycgrand: can you set breakpoints? last time I tried I couldn't
10:09rhickeyClojure emits the right stuff for debugging, local variable names etc
10:10Chouserrhickey: that's how the stack traces from exceptions work, right?
10:11rhickeythat's how the line numbers get in there, but there's more to it, you need a SourceDebugExtension to map to the source files, which Clojure also emits, and locals entries in the bytecode, also there
10:12cgrandYeah I saw that you emit smap strings. With a rudimentary plugin (never played with eclipse dbugger api) I can set breakpoints
10:12rhickeycool
10:13cgrandwhich source files? Clojure emits java source files?
10:14rhickeyno the smap is a mapping from Clojure to non-existent Java files, which is the bridge
10:14rhickeyFull Clojure plugin for Netbeans is coming, if you haven't seen this: http://groups.google.com/group/clojure/msg/4dfb4566c2187704
10:14cgrandI saw
10:15rhickeythey had to do some work to get Netbeans to debug Clojure
10:17rhickeyI'd love to see Eclipse support too
10:19cgrandThe editor framework is a bit complex...
10:19rhickeyI guess Cusp would provide good editing support, but native debugging is preferable to custom protocol
10:20rhickeydoes Cusp do debugging anyway?
10:22cgrandNot sur but I think so
12:01sanityanyone here familiar with SISC? http://sisc-scheme.org/
12:02Chousersomeone recommended it to me when I was looking for a JVM lisp. Of course I ended up using Clojure instead, so I know nothing useful.
12:04sanityChouser: i only ask because a friend of mine created it
12:05sanityChouser: although i think, unlikely Clojure, it is interpreted, rather than compiled
12:05sanitys/unlikely/unlike
12:05Chouserinteresting.
14:27wabashIf I have a multicore cpu, like 8 cores, how would I parallelize a clojure app? Would I start a separate JVM on each core? And, would threads on separate JVMs be able to communicate via some sore of message passing?
14:27wabashlike Erlang?
14:28rhickeyA single JVM can address multiple cores
14:28rhickeyClojure agents will get distributed among them
14:28wabashrhickey: wow, sweet!
14:29wabashI'm sorry to ask such basic questions. I just found out about clojure like, last week. The more I find out, the more interested I am.
14:29rhickeyClojure fns are Callable and Runnable, and will work with the java.util.concurrent.Executors framework as well
14:30wabashWhat is the clojure way of thread communication? And, are threads expensive like Java or are they cheap like Erlang? is msg passing expensive like sockets or cheap like shared mem?
14:30wabashrhickey: Are all Java libs and classes basically available?
14:30rhickeyErlang processes are not threads
14:31rhickeythey may or may not map to threads depending on how you have Erlang SMP set up
14:31wabashrhickey: Sorry, I got semantically lazy.
14:31rhickeyErlang w/o SMP mode runs on one core
14:31rhickeybut does its own scheduling
14:32wabashRight, I just misused a term.
14:32rhickeyClojure agents use a fixed thread pool on message sends
14:32rhickeythe pool size is related to the number of cores
14:32wabashlinearly related?
14:32rhickeyAgent state can be read directly w/o messages
14:33rhickeyagent state gets changes via actions, functions of their state that get executed asynchronously
14:33rhickeyit's a different model than Erlang's
14:33wabashHow do you read stat directly? Is it some sort of polling? is an agent like a process?
14:33wabashOh, I see.
14:33wabashIt's a very different way of thinking about hings.
14:33wabashis the state reading quick between cores?
14:34rhickeyErlang's can be transparently distributed, but getting at state requires send/ack & blocking
14:34wabashCan clojure be transparently distributed?
14:34rhickeyClojure is a single memory space, reading agent state is like any other object access
14:35rhickeyNo, I don't believe in transparent distribution, but may add distributed actors at some point
14:35wabashIs the single mem space a problem for concurrency then? How is that abstracted? Erlang seems so elegant......
14:36rhickeyClojure agent states are immutable
14:36wabashI get it now.
14:36wabashThank you.
14:36rhickeyimmutable objects are no problem for multicore
14:37wabashrhickey: I appreciate your time. Learning something new, I'm always faced with the paradox of what to ask when I don't know enough to formulate questions.
14:37rhickeyI don't think send/ack message pairs to read state is elegant at all, just a necessary evil of distribution
14:37rhickeyvs RPC
14:38wabashRPC is more elegant than message pairs?
14:38rhickeyno, message pairs is less evil
14:38rhickeydistribution is simply very hard
14:39rhickeywhy incur the complexity unless you really are distributed?
14:39wabashpremature scalability, I suppose.
14:40rhickeybut the constant factors are different - you can make it look the same, but the same payloads and chatter rate that worked locally can totally fall down when distributed
14:40wabashYes, I understand and agree.
14:41wabashThat's kind of what I was getting at with spreading over cores; will the constants be high for communicating between (threads/processes) on different cores.
14:41rhickeyhttp://research.sun.com/techrep/1994/smli_tr-94-29.pdf
14:41wabashIn Clojure, then, you think in terms of "agents"?
14:41wabashthank you for the link. I will read it after lunch.
14:42rhickeyagents are one of several tools for MT programming. There are also refs and STM
14:43wabashI see. If I may ask an over-general question, if I run Clojure on an 8 core machine, will the communications overhead be small enough that the distribution will be even? Will I have to worry about which core is closer to which?
14:43wabashOr if I have a small cluster of separate machines, will I have to adjust my algorithms to match the architechture?
14:44rhickeythat totally depends on the granularity of your work units. Overhead/work is what matters
14:44wabashI see.
14:44rhickeyseparate machines is a totally different architecture in my book, and where Erlang's model makes the most sense
14:44wabashRight.
14:45rhickeyI'm thining about doing distribution for Clojure using Shoal: https://shoal.dev.java.net/
14:45wabashYou seem to have a lot of experience with different languages/models. Is your work research oriented? Or are you lucky enough to have a corporate job doing all these things?
14:46rhickeyI'm just old
14:46rhickey:)
14:46rhickeyBut lots of MT in my experience
14:46wabashMT?
14:47rhickeymultithreading
14:47wabashGot it.
14:47wabashThanks for the discussion. It is useful, significant to me.
14:47rhickeysure
14:48wabashI went to an average school, got wrapped up in some programming jobs, got ejected, dejected, discouraged, but now have discovered higher level languages, and FP, and think that programming is fun again, a bit.
14:48wabashwell, must have lunch. thanks for sharing your knowledge and experience.
16:14jgracinhi all! this place is getting more crowded with each day. :-)
16:14rhickey:)
17:24ChouserI'm not sure this is the right question, but if I wanted to make something that acts exactly like a hash-map, but also generated some Actor dispatches, how would I do that? "implements"? multi-methods?
17:26Chouserok, that's not quite right. I want something that acts like ref. You can call set-ref on it, and it does that but also it dispatches and Actor function.
17:26ChouserIf this were some other language, I'd sub-class Ref.
17:28rhickeywhy not just use a map as the state of an agent?
17:28rhickeyor of a ref?
17:29rhickeyagent actions anf ref alter/commute functions can be multimethods
17:35ChouserI'm right at the edge of my understand here, so bear with me... I've got a function that calls (ref-set db (assoc ...)). It currently expects db be to a ref to a map, but I'd like to also allow db to be one of these new things I'm making. Are you suggesting that I change my set-ref to be (alter db foo) and then make foo a multi-method that can handle either standard ref-maps, or my new thnigs?
17:36rhickeyright, in your first case, (ref-set db (assoc... you could have used (alter db assoc...
17:36rhickeynow swap foo in for assoc...
17:36rhickeymake foo a multimethod that can distinguish the things you might out in db
17:37rhickeyput
17:37rhickeyare your new things going in refs?
17:37Chouserok, I think I follow.
17:38ChouserI don't *think* so. I think they will act like refs.
17:38rhickeyhmm...
17:38ChouserMaybe I didn't understand the question.
17:38rhickeywhy can't they be refs?
17:39ChouserI'm thinking I'll make a thing that acts like a ref, but whenever it gets set it will ask an actor to write its new value out to disk.
17:40rhickeyI see, I've thought about connecting on-commit and validate fns to refs as a general solution for that kind of thing
17:41rhickeybut refs are special, don't try to derive...
17:41rhickeyyou can have your mutating fns send an agent action, but not automatically... could use a macro to define the mutating fns
17:43Chouserbut the solution you outlined above should still work, right? I'll use (alter db db-assoc ...), and db-assoc will either just assoc, or assoc and dispatch.
17:44ChouserThis will be my first agent.
17:44ChouserAnd my first multi-method. ;-)
17:44rhickeyoh boy
17:45rhickeyyes, if db-assoc sends an action, that will only happen if the transaction commits
17:47Chouserwhew, good point. I hadn't thought about the assoc getting rolled back. Ok, I'll try to do this.
17:48rhickeythat's the beauty of the agent/transaction coordination, there's no other way to get run-once-only side-effects in a transaction
22:14ChouserOk, I don't think I really need a multimethod.
22:14ChouserIs there any way to refer to an agent action, or do I have to wrap the call to it in a function.
22:15rhickey?
22:15rhickeyagent action are functions, or are you talking about the agent's state?
22:17Chouserhm, no I was misunderstanding how they work. Let me read that docs page again...
22:18rhickeyyou can make one-off agents just to execute side-effects:
22:19rhickey(send (agent nil) (fn [_] (side-effect)))
22:20Chousersend is the same as ! ?
22:20Chouserhuh. ok, I think that's exactly what I want.
22:21rhickeyyes, send is the new !, there is also send-off for potentially blocking actions
22:21Chouseroh, is ! going away?
22:21rhickeyyes ! is going away
22:22rhickeytry it
22:22rhickeyit's gone
22:22Chouserheh, ok.
22:45Chousershould I avoid multiple deref in a transaction?
22:46ChouserI've got @foo all over the place, but I could put it in a local symbol instead.
23:16rhickeymultiple deref of refs is no problem, should be same result throughout unless transaction itself changes ref