Re: Changing State Pattern - Better Options?

2009-01-18 Thread Konrad Hinsen
On 18.01.2009, at 20:55, DavidH wrote: > The gist is that a function is applied to each member of a sequence, > like map, except that the function also takes a changing state. The > change to the state is described by a second function. You might want to look at the state monad, defined in cl

Re: Inheritance & multiple inheritance using structs

2009-01-18 Thread David Nolen
Of course it might be the case that not many people are interested in the implementing ideas from CLOS for Clojure especially since there's a lot of exciting new functional ground to cover in Clojure first ;) I come from a UI background so I'm interested in the OO implications/possiblities of Cloj

Re: odd error with a dosync (not (empty? @someref))

2009-01-18 Thread Timothy Pratley
> What still riddles me is why the above > script with the first formula (with the deref problem) doesn't always > cause a problem, but maybe one in every 5 times I run it. Sometimes it manages to queue up all the send functions before the exception is thrown, but sometimes the exception is throw

Inheritance & multiple inheritance using structs

2009-01-18 Thread David Nolen
After a couple of days of hacking it's clear that Clojure can support OO structures really, really, well. I've whipped up a little thing, jokingly called CLJOS. I'm curious to know what people think. It's a fairly simple affair combining structs, hierarchies, and some helper functions. It's my f

Re: Changing State Pattern - Better Options?

2009-01-18 Thread Chouser
On Sun, Jan 18, 2009 at 2:55 PM, DavidH wrote: > > In the code I'm writing, I seem to run into a certain pattern a lot. > Often enough anyway that I thought there must be a different way of > doing it - otherwise there would be a macro or function for it. > > The gist is that a function is applie

Re: How to make function that derefs vars and refs?

2009-01-18 Thread Stuart Sierra
On Jan 18, 6:56 pm, Anand Patil wrote: > Would it make any sense to make @ polymorphic so that @x return x's > value when x is a var rather than raising an error? Actually, it already is: user> (def x 5) #'user/x user> (deref (var x)) 5 user> @(var x) 5 @x is just shorthand for (deref x), whic

JScrollPane + JTextPane trouble.

2009-01-18 Thread Christian Vest Hansen
Hi! Now, I know this is more related to Swing than Clojure, but they won't be able to read my code in a general Java forum. I have a JTextPane [1] inside a JScrollPane [2] and I would like to have horizontal scrollbars rather than word-wrapping. I try to disable word-wrapping by overriding the J

Re: How to make function that derefs vars and refs?

2009-01-18 Thread Anand Patil
Timothy, Stephen and Stuart, Thanks for three very informative and understandable responses! It's very encouraging to see that such support is available when approaching a new language. I look forward to further exploration of Clojure. The var/value/symbol relationship continues to be a bit slip

Re: Changing State Pattern - Better Options?

2009-01-18 Thread Phil Jordan
DavidH wrote: > In the code I'm writing, I seem to run into a certain pattern a lot. > Often enough anyway that I thought there must be a different way of > doing it - otherwise there would be a macro or function for it. > > The gist is that a function is applied to each member of a sequence, > l

Re: Changing State Pattern - Better Options?

2009-01-18 Thread Stuart Sierra
You might be able to write this using "reduce", but I'm not sure exactly what you're trying to achieve here. Do you have a more concrete example? -S On Jan 18, 2:55 pm, DavidH wrote: > In the code I'm writing, I seem to run into a certain pattern a lot. > Often enough anyway that I thought ther

clojure eclipse plugin status (clojuredev)

2009-01-18 Thread lpetit
Hello, Just a brief message to let you know the status of clojure-dev. It's still in its infancy, but already usable to eclipse user that currently have nothing but a shell to work with. Please see the screenshots : http://code.google.com/p/clojure-dev/wiki/ScreenShots And also consult the do

Re: Clojure-dev Eclipse Wizard issues

2009-01-18 Thread lpetit
Well, I think it not a good idea to upload the stack trace for clojure- dev in clojure's google group files. The files section is dedicated to sharing usable working clojure code with others. At least it is the way I understand it. For debugging session, we could indeed do it in the more dedica

Re: Clojure.zip/next behavior

2009-01-18 Thread Greg Harman
Christophe, thanks for your explanation. I certainly agree that is what is happening but I find it unintuitive, especially when the structure I was walking was an S-expression in which the first member of a list is understood to be an operator to which the following members are passed as arguments

Re: Clojure.zip/next behavior

2009-01-18 Thread Christophe Grand
Greg Harman a écrit : > Take the following data structure, wrapped up with clojure.zip/seq- > zip: '(+ (- 1 2) (* 3 4)) > > Repeatedly calling clojure.zip/next produces these "nodes": > > + > (- 1 2) > - > 1 > 2 > ... > > The (- 1 2) is what's throwing me off. Drawing out a tree structure, I > see

Changing State Pattern - Better Options?

2009-01-18 Thread DavidH
In the code I'm writing, I seem to run into a certain pattern a lot. Often enough anyway that I thought there must be a different way of doing it - otherwise there would be a macro or function for it. The gist is that a function is applied to each member of a sequence, like map, except that the f

Re: why (into [] [1 2 3]) works, but not (into [] (1 2 3))?

2009-01-18 Thread wubbie
thanks, I forgot about that. sun On Jan 18, 4:00 pm, "Nick Vogel" wrote: > You need to do (into [] '(1 2 3)) otherwise it will be read as calling the > function 1 with arguments 2 and 3. > > On Sun, Jan 18, 2009 at 3:56 PM, wubbie wrote: > > > Hi, > > > Why into does not work for second argume

Re: post on test-is and testing styles

2009-01-18 Thread James Reeves
On Jan 18, 4:24 pm, Stuart Sierra wrote: > After thinking a while about the discussion about test-is groups.google.com/group/clojure/browse_thread/thread/59e9cebbe67cab3f/ > 508f1e8de753455c>, here's a short article with my current thoughts: > > http://stuartsierra.com/2009/01/18/tests-are-code

Re: why (into [] [1 2 3]) works, but not (into [] (1 2 3))?

2009-01-18 Thread Nick Vogel
You need to do (into [] '(1 2 3)) otherwise it will be read as calling the function 1 with arguments 2 and 3. On Sun, Jan 18, 2009 at 3:56 PM, wubbie wrote: > > Hi, > > Why into does not work for second argument of list? > > user=> (into [] (1 2 3)) > java.lang.ClassCastException: java.lang.Inte

Re: Clojure-dev Eclipse Wizard issues

2009-01-18 Thread T. Ettinger
I just installed via the update site, and I got (almost) the same bug, in the same place, upon the same action. "The selected wizard could not be started. Plug-in clojuredev was unable to load class clojuredev.wizards.NewClojureProjectWizard. An error occurred while automatically activating b

why (into [] [1 2 3]) works, but not (into [] (1 2 3))?

2009-01-18 Thread wubbie
Hi, Why into does not work for second argument of list? user=> (into [] (1 2 3)) java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IFn (NO_SOURCE_FILE:0) user=> (into [] [1 2 3]) [1 2 3] thanks -Sun --~--~-~--~~~---~--~~ You received

Re: post on test-is and testing styles

2009-01-18 Thread Daniel Jomphe
Stuart Sierra wrote: > http://stuartsierra.com/2009/01/18/tests-are-code > > Comments welcome here or on the blog. That's funny Stuart; The question I asked about 'reduce' and 'and' was exactly for this purpose. The first programming exercise I gave myself to start learning Clojure was to build

Re: Calling a mapreduce job from inside another

2009-01-18 Thread lpetit
And please reply ;-) On Jan 18, 7:12 pm, "Stephen C. Gilardi" wrote: > On Jan 18, 2009, at 12:48 PM, aimhier wrote: > > > Is it possible to call a map-reduce job from inside another. If yes > > how. > > > Also is it possible to disable the reducer completely, i.e I wish to > > stop immediately a

Re: Clojure-dev Eclipse Wizard issues

2009-01-18 Thread lpetit
Hello, Welcome, second external user of clojure-dev ! :-). You will find clojure-dev developers in this mailing list. And, if others think the discussions become too clojure-dev centric, we can still continue this on the user group for clojure-dev. First of all, let me say there's an update sit

how to know which version of clojure?

2009-01-18 Thread wubbie
Hi, Just tried a piece of code from here... (defn my-deref [x] (if (or (isa? clojure.lang.Ref (class x)) (isa? clojure.lang.Agent (class x)) (isa? clojure.lang.Atom (class x))) @x x)) java.lang.ClassNotFoundException: clojure.lang.Atom (NO_SOURCE_FILE: 22) But I thin

Re: Calling a mapreduce job from inside another

2009-01-18 Thread Stephen C. Gilardi
On Jan 18, 2009, at 12:48 PM, aimhier wrote: Is it possible to call a map-reduce job from inside another. If yes how. Also is it possible to disable the reducer completely, i.e I wish to stop immediately after the mapper is applied. This appears not to be a question about Clojure. I see that

Calling a mapreduce job from inside another

2009-01-18 Thread aimhier
Is it possible to call a map-reduce job from inside another. If yes how. Also is it possible to disable the reducer completely, i.e I wish to stop immediately after the mapper is applied. Please reply, Regards, Aditya Desai --~--~-~--~~~---~--~~ You received thi

Re: Runtime exception when agent calls sort

2009-01-18 Thread Stephen C. Gilardi
On Jan 18, 2009, at 12:11 PM, mbrodersen wrote: (defn html-write-cmd [out cmd] (doseq [key (keys cmd)] (.write out (format "\"%s\" => \"%s\"" key (cmd key) I gather this is a command you're sending to the agent via "send-off". The first ar

Re: odd error with a dosync (not (empty? @someref))

2009-01-18 Thread bOR_
Thanks for the pointers both. What still riddles me is why the above script with the first formula (with the deref problem) doesn't always cause a problem, but maybe one in every 5 times I run it. @Timothy - double thanks for your clarifications. I am changing my program from a ref-based to a sen

Clojure.zip/next behavior

2009-01-18 Thread Greg Harman
Take the following data structure, wrapped up with clojure.zip/seq- zip: '(+ (- 1 2) (* 3 4)) Repeatedly calling clojure.zip/next produces these "nodes": + (- 1 2) - 1 2 ... The (- 1 2) is what's throwing me off. Drawing out a tree structure, I see that my nodes are + - 1 2 * 3 4 and the struct

Re: Mysterious performance anomalies

2009-01-18 Thread e
I see. From wikipedia: "A Jazelle-aware Java Virtual Machine(JVM) will attempt to run Java bytecodes in hardware, while returning to the software for more complicated, or lesser-used bytecode operations. ARM claim that approximately 95% of bytecod

Runtime exception when agent calls sort

2009-01-18 Thread mbrodersen
Hi The following agent code works fine: (defn html-write-cmd [out cmd] (doseq [key (keys cmd)] (.write out (format "\"%s\" => \"%s\"" key (cmd key) but if I change (keys cmd) to (sort (keys cmd)) then the following runtime exception is trigger

Re: Mysterious performance anomalies

2009-01-18 Thread e
That's a great argument. I need arguments like these. I work with people who dismiss JVM. Even though there are many non-Sun JVM's, folks say, "Sun is dead -> java is dead -> jvm is dead." . even though Java is the most popular language right now. http://www.tiobe.com/index.php/content/paper

Re: A quasiquote for Clojure?

2009-01-18 Thread Rich Hickey
On Jan 17, 5:02 am, Meikel Brandmeyer wrote: > Hi Jason, > > Am 16.01.2009 um 00:36 schrieb Jason Wolfe: > > > I like this a lot. Any chance of getting the same treatment for > > unquote-splicing? > > > user> '~x > > (clojure.core/unquote x) > > user> '~...@x > > ; Exception: can't embed objec

post on test-is and testing styles

2009-01-18 Thread Stuart Sierra
Hi folks, After thinking a while about the discussion about test-is , here's a short article with my current thoughts: http://stuartsierra.com/2009/01/18/tests-are-code Comments welcome here or on the blog. -Stuart Sierra --~--~-~--~~~---~--~~ You received this

Re: How to make function that derefs vars and refs?

2009-01-18 Thread Stuart Sierra
Hi Anand, You don't normally need to dereference vars because the compiler does it for you. user> (def x 5) #'user/x This creates a var bound to the symbol "x". But now, whenever you type "x" the compiler will automatically look up the var and return its value. user> x 5 So wh

Re: How to make function that derefs vars and refs?

2009-01-18 Thread Stephen C. Gilardi
On Jan 18, 2009, at 5:11 AM, anand.prabhakar.patil wrote: I'm new to Java, Lisp and Clojure, so please be patient. I'm trying to make a function that behaves as follows: (my-deref x) returns x if x is a var, or @x if x is a ref. However none of the obvious options seem to be working. -

Re: How to make function that derefs vars and refs?

2009-01-18 Thread Timothy Pratley
> - First, it seems from the api documentation that @x will work fine even if > x is a var. I don't understand the following: > Why isn't x a var? vars automatically resolve to their value for convenience, however you can access the var using (var x) or use the shorthand #' notation which does th

Re: odd error with a dosync (not (empty? @someref))

2009-01-18 Thread Timothy Pratley
> (defn death >   [host] >   (dosync >    (if (not (empty? @host)) >      nil))) The agents initial value is a ref. Sometimes you set it to nil. nil cannot be dereferenced. Perhaps you meant to set the ref to nil (if (not-empty @host) (ref-set host nil)). However I think you've gone a little of

Re: odd error with a dosync (not (empty? @someref))

2009-01-18 Thread Meikel Brandmeyer
Hi, Am 18.01.2009 um 15:24 schrieb bOR_: I'm running into an odd error that occasionally pops up. Here is the ugly script and the two functions, one for which it does, and one for which it does not pop up. Anyone has a clue? (defn death [host] (dosync (if (not (empty? @host)) nil))) (

odd error with a dosync (not (empty? @someref))

2009-01-18 Thread bOR_
Hi all. I'm running into an odd error that occasionally pops up. Here is the ugly script and the two functions, one for which it does, and one for which it does not pop up. Anyone has a clue? (defn death [host] (dosync (if (not (empty? @host)) nil))) (defn death [host] (dosync

How to make function that derefs vars and refs?

2009-01-18 Thread anand.prabhakar.patil
Hi all, I'm new to Java, Lisp and Clojure, so please be patient. I'm trying to make a function that behaves as follows: (my-deref x) returns x if x is a var, or @x if x is a ref. However none of the obvious options seem to be working. - First, it seems from the api documentation that @x will work

Clojure-dev Eclipse Wizard issues

2009-01-18 Thread T. Ettinger
I stumbled upon Clojure in a search for a scripting language for the JVM that was more functional in style than the rest, and although it isn't really a "scripting language," I really, really like its feature set. Unfortunately, I really, really dislike emacs (every option for the Mac I use i

Re: Clojure blog post about laziness

2009-01-18 Thread Mark Engelberg
On Fri, Jan 9, 2009 at 6:00 AM, Rich Hickey wrote: > When I had lazy-seq in play, many of those were defined that way. The > real cost is explaining either why lazy-seq is private, or, if public, > when/how to use it. I'd certainly make use of lazy-seq if it were public. But assuming it's not m

Re: Eval with local bindings

2009-01-18 Thread Christophe Grand
Christophe Grand a écrit : > You also can do something like this: > > (defmacro let-eval [vars expr] > (let [bindings (mapcat #(list (list `quote %) %) vars)] > `(eval (list 'let [...@bindings] ~expr > Hmm... not quite: user=> (let [x [2 3]] (let-eval [x] '(rest x))) (3) user=> (let