Re: Suggest fcase variant "pred-case"
On Oct 28, 4:13 pm, Martin DeMello <[EMAIL PROTECTED]> wrote: > On Oct 28, 6:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > > > > > My thoughts are that there should only be fcase > > PLT Scheme's pattern matching library might be a good source of > inspiration: > > http://download.plt-scheme.org/doc/352/html/mzlib/mzlib-Z-H-31.html#n... > Yes, I'm aware of that one, but it's more of a structural matcher than this predicate thing we've been discussing. I expect some sort of structural match facility is inevitable in Clojure, and something like the PLT one, plus some leverage of Clojure's data structure literals, would probably be nice. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: string interpolation
On Tue, Oct 28, 2008 at 7:27 PM, Graham Fawcett <[EMAIL PROTECTED]> wrote: > But for fun, here's an (i ...) macro, that will give you ${} > interpolation in strings (if it works at all, I test it very > thorougly!). Haha, nor did I spell- or grammar-check very thoroughly! I meant: I didn't test the code very thoroughly, so I hope it works at all. Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: string interpolation
On Mon, Oct 27, 2008 at 11:38 PM, Islon <[EMAIL PROTECTED]> wrote: > Is there any chance closure will get string interpolation? > > Do things like (prn "Hi ${someone}, my name is ${myname}") is nice, not > crucial of course, but nice. I'm personally not fond of string interpolation either. But for fun, here's an (i ...) macro, that will give you ${} interpolation in strings (if it works at all, I test it very thorougly!). (defn my-interleave [a b] "Like interleave, but uses all elements from both lists." (loop [acc [] a a b b] (if (and (nil? a) (nil? b)) acc (let [acc2 (if (nil? a) acc (conj acc (first a))) acc3 (if (nil? b) acc2 (conj acc2 (first b)))] (recur acc3 (rest a) (rest b)) (defn read-from-string [s] (read (java.io.PushbackReader. (java.io.StringReader. s (defn tokenize [s];; not pretty but it works. (let [positions (let [mm (re-matcher #"\\$\\{.*?\\}" s)] (loop [acc []] (if (.find mm) (recur (conj acc [(.start mm) (.end mm)])) acc))) intermed (conj (apply vector 0 (apply concat positions)) (.length s)) textposns (partition 2 intermed)] (my-interleave (map (fn [[a b]] [:text (.substring s a b)]) textposns) (map (fn [[a b]] [:pat (.substring s (+ a 2) (- b 1))]) positions (defmacro i [s] (apply list 'str (map (fn [[type value]] (if (= type :text) value (read-from-string value))) (tokenize s ;; test (let [greeting "Hello" name "Fred" age 33] (prn (i "${greeting}, my name is ${name} and my age is ${age}."))) -- Graham --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
On Tue, Oct 28, 2008 at 2:49 PM, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Oct 28, 10:29 am, Stuart Sierra <[EMAIL PROTECTED]> > wrote: >> I feel like "econdp" would be less clear, since you don't know what >> kind of exception should be thrown. Plain old Exception? Or >> RuntimeError? > > The kind of error is TBD, but it won't be random. It saves everyone a) > redundantly having to specify this, and b) specifying needlessly > different Exceptions and messages on no matching case. It's pretty > useful in CL. > >> >> > Finally there is the name, which has to follow the form and function. >> > If we go with something like the last above, I like condp/econdp. >> >> I'm not sure about condp, only because Clojure hasn't used the CL-ish >> "-p" suffix anywhere else. Ideas: condfn, fcond, cond-apply, cond- >> with, try-each,... > > This wouldn't match the use of trailing p in CL, which has been > replaced by ? in Clojure. I like leading with cond so it sorts > together to make people aware of the option. I don't think I like any > of those better - whatever it is should be short. > I also like it leading with cond, so condp or condf, but econdp doesn't fit, so condpe? Having a general naming convention like trailing F would be nice, I've needed that type of thing before - assuming this can be generalized. How about :error as the last clause (test with no expr, or optional expression) instead of a different macro? Though :error could be a conflict if that was really one of the tests, so maybe define clojure/error? I disliked looking up so many different macros for this in CL. Also, would you want an error variant or option for cond? -Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: commutes do not trigger validate-fn?
On Oct 28, 3:32 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Is this by design? It surprised me, as I expected all transactional > updates to be protected by validate-fn. > Fixed (svn 1085) - thanks for the report! Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
On Oct 28, 10:29 am, Stuart Sierra <[EMAIL PROTECTED]> wrote: > On Oct 27, 10:45 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > > > I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job, > > Stuart! > > Thanks! > > On Oct 28, 9:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > > > If you'd like, I think the effort would be better spent on making a > > version of fcase for the base library. > > Cool! > > > I'd like to save unadorned "case" for this meaning. > > Fine by me. > > > > > There is implicit arg ordering (pred clause-value test-value) which > > doesn't matter for some preds (=) but does for others (instance?). For > > the uses thus far, this order seems good - instance? and re-find work > > well, but there will be cases where people will want (pred test-value > > clause-value). The order of things in the macro structure might imply > > the latter: > ... > > (condp (= x _) ;doesn't matter > > (condp (instance? _ x) > > (condp (some #{x} _) > > How about just one argument, the predicate: (condp #(= x %) ...) > That would resolve the issue without adding syntax, no? > Well, condp *is* syntax, being a macro. This wouldn't add anything to the reader syntax or anything, just an interpretation of (pred expr _) or (pred _ expr). #(pred expr %) would cause expr to be evaluated every clause. > > As far as the default, providing a default value as odd last clause is > > ok, but subtle, and could use layout help, if we do that we should do > > the same for cond. > > I stole that idea from Arc's "if", which has the interesting quality > of unifying "if" and "cond". I often use the "else" clause to throw > an exception: > > (condp #(= x %) > 42 "The Meaning of Life" > 13 "Unlucky" > 1 "The loneliest number" > (throw (Exception. "Nothing matched.")) > > I feel like "econdp" would be less clear, since you don't know what > kind of exception should be thrown. Plain old Exception? Or > RuntimeError? The kind of error is TBD, but it won't be random. It saves everyone a) redundantly having to specify this, and b) specifying needlessly different Exceptions and messages on no matching case. It's pretty useful in CL. > > > Finally there is the name, which has to follow the form and function. > > If we go with something like the last above, I like condp/econdp. > > I'm not sure about condp, only because Clojure hasn't used the CL-ish > "-p" suffix anywhere else. Ideas: condfn, fcond, cond-apply, cond- > with, try-each,... This wouldn't match the use of trailing p in CL, which has been replaced by ? in Clojure. I like leading with cond so it sorts together to make people aware of the option. I don't think I like any of those better - whatever it is should be short. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Chimp Patch - MacroExpand command
On Tue, Oct 28, 2008 at 4:44 PM, mb <[EMAIL PROTECTED]> wrote: > > I added \me for macroexpand and \m1 for macroexpand-1. Great, thanks Meikel! - J. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: converting a sequence of map entries into a map
Excellent, that's exactly what I need. Thanks. On Oct 28, 12:09 pm, Matt Moriarity <[EMAIL PROTECTED]> wrote: > what you're looking for i believe is into > > > (into {} (list [:a 2] [:b 3])) > > {:b 3, :a 2} > > On Oct 28, 3:05 pm, samppi <[EMAIL PROTECTED]> wrote: > > > I'm new at Clojure, but I'm really liking it, though. I'm having > > trouble with using map on a map, and turning the resulting sequence of > > map entries into a new map. > > > In other words, how can you turn this: > > > ([:a 2] [:b 3]) ...into... {:a 2, :b 3}? > > > Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Chimp Patch - MacroExpand command
Hi, On 28 Okt., 19:52, "J. McConnell" <[EMAIL PROTECTED]> wrote: > For anyone using Meikel Brandmeyer's Chimp plugin for Vim, below is a > patch that adds a MacroExpand command, which sends a (macroexpand-1 > ...) for the inner s-expr. Hope someone finds it useful. Thank you for the patch. I added \me for macroexpand and \m1 for macroexpand-1. Changes are in the mercurial repository. http://kotka.de/repositories/hg/chimp Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
On Oct 28, 6:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > > My thoughts are that there should only be fcase PLT Scheme's pattern matching library might be a good source of inspiration: http://download.plt-scheme.org/doc/352/html/mzlib/mzlib-Z-H-31.html#node_chap_31 martin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
commutes do not trigger validate-fn?
Is this by design? It surprised me, as I expected all transactional updates to be protected by validate-fn. Stuart --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie question: converting a sequence of map entries into a map
what you're looking for i believe is into > (into {} (list [:a 2] [:b 3])) {:b 3, :a 2} On Oct 28, 3:05 pm, samppi <[EMAIL PROTECTED]> wrote: > I'm new at Clojure, but I'm really liking it, though. I'm having > trouble with using map on a map, and turning the resulting sequence of > map entries into a new map. > > In other words, how can you turn this: > > ([:a 2] [:b 3]) ...into... {:a 2, :b 3}? > > Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Newbie question: converting a sequence of map entries into a map
I'm new at Clojure, but I'm really liking it, though. I'm having trouble with using map on a map, and turning the resulting sequence of map entries into a new map. In other words, how can you turn this: ([:a 2] [:b 3]) ...into... {:a 2, :b 3}? Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Using a Java Debugger with Clojure
It should work. Before I had a debugging working in Eclipse with Groovy, I used JSwat, JEdit and Ant for project work with success. Scott Hickey Senior Consultant Object Partners, Inc. - Original Message From: Bill Clementson <[EMAIL PROTECTED]> To: clojure@googlegroups.com Sent: Tuesday, October 28, 2008 1:43:58 PM Subject: Re: Using a Java Debugger with Clojure Hi Peter, On Tue, Oct 28, 2008 at 11:27 AM, Peter Wolf <[EMAIL PROTECTED]> wrote: > > Hello all, > > I am new to Clojure, but not Java or LISP (I used to work at LMI). > > I am considering a project written in a mixture of Clojure, Java and > Groovy. Clojure for the concurrent inner loop. Groovy/Grails for the > Web UI. And lots of Java reused from other projects. > > How would I debug something like this? Can I compile Clojure so that a > standard Java debugger understands it? I don't know about Groovy, but some people have used standard Java debuggers to debug Clojure code. For example: 1. Read Rich's section on debugging in "Getting Started": http://clojure.org/getting_started#toc5 2. Have a look at my blog post: http://bc.tech.coop/blog/081023.html 3. There was a recent discussion on this group where another individual had some problems getting JSwat working: http://groups.google.com/group/clojure/browse_thread/thread/403e593c86c2893f# 4. A general search for "debugger" on this group will also bring up some other relevant threads. > Is there a better way? "Better" is subjective. ;-) You could use "traditional" lisp debugging techniques as well. I've covered some of these on my blog: http://bc.tech.coop/blog/040628.html Cheers, Bill --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Using a Java Debugger with Clojure
Hi Peter, On Tue, Oct 28, 2008 at 11:27 AM, Peter Wolf <[EMAIL PROTECTED]> wrote: > > Hello all, > > I am new to Clojure, but not Java or LISP (I used to work at LMI). > > I am considering a project written in a mixture of Clojure, Java and > Groovy. Clojure for the concurrent inner loop. Groovy/Grails for the > Web UI. And lots of Java reused from other projects. > > How would I debug something like this? Can I compile Clojure so that a > standard Java debugger understands it? I don't know about Groovy, but some people have used standard Java debuggers to debug Clojure code. For example: 1. Read Rich's section on debugging in "Getting Started": http://clojure.org/getting_started#toc5 2. Have a look at my blog post: http://bc.tech.coop/blog/081023.html 3. There was a recent discussion on this group where another individual had some problems getting JSwat working: http://groups.google.com/group/clojure/browse_thread/thread/403e593c86c2893f# 4. A general search for "debugger" on this group will also bring up some other relevant threads. > Is there a better way? "Better" is subjective. ;-) You could use "traditional" lisp debugging techniques as well. I've covered some of these on my blog: http://bc.tech.coop/blog/040628.html Cheers, Bill --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Chimp Patch - MacroExpand command
For anyone using Meikel Brandmeyer's Chimp plugin for Vim, below is a patch that adds a MacroExpand command, which sends a (macroexpand-1 ...) for the inner s-expr. Hope someone finds it useful. - J. Index: chimp.vim === --- chimp.vim (revision 3) +++ chimp.vim (working copy) @@ -2,7 +2,7 @@ "- " Copyright 2008 (c) Meikel Brandmeyer. " All rights reserved. -" +" " Permission is hereby granted, free of charge, to any person obtaining a copy " of this software and associated documentation files (the "Software"), to deal " in the Software without restriction, including without limitation the rights @@ -219,6 +219,19 @@ call chimp#SendMessage(s:ChimpId, '(println *e) (. *e printStackTrace)') endfunction + +function! s:SendMacroExpand() dict + call s:Connect() + call s:ChangeNamespaceIfNecessary() + + call chimp#SendMessage(s:ChimpId, "(macroexpand-1 '") + call s:WithSavedPosition({'f': function("s:SendSexp"), 'flags': self.flags}) + call chimp#SendMessage(s:ChimpId, ")") +endfunction + +function! s:MacroExpand() + call s:WithSavedPosition({'f': function("s:SendMacroExpand"), 'flags': ''}) +endfunction " [ }}} ] "## [ }}} ] @@ -234,6 +247,7 @@ call s:MakePlug('n', 'LookupDoc', 'LookupDoc("")') call s:MakePlug('n', 'FindDoc', 'FindDoc()') call s:MakePlug('n', 'PrintException', 'PrintException()') + call s:MakePlug('n', 'MacroExpand', 'MacroExpand()') call s:MapPlug('v', 'eb', 'EvalBlock') call s:MapPlug('n', 'es', 'EvalInnerSexp') @@ -245,6 +259,7 @@ call s:MapPlug('n', 'ld', 'LookupDoc') call s:MapPlug('n', 'fd', 'FindDoc') call s:MapPlug('n', 'pe', 'PrintException') + call s:MapPlug('n', 'me', 'MacroExpand') endif "## [ }}} ] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Using a Java Debugger with Clojure
Hello all, I am new to Clojure, but not Java or LISP (I used to work at LMI). I am considering a project written in a mixture of Clojure, Java and Groovy. Clojure for the concurrent inner loop. Groovy/Grails for the Web UI. And lots of Java reused from other projects. How would I debug something like this? Can I compile Clojure so that a standard Java debugger understands it? Is there a better way? Thanks in advance Peter --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Patch available: error message for bad prefix list in require/use
I intended to use a namespace declaration like this: user> (ns three-tier (:use clojure.contrib.sql)) nil but I mistakenly typed user> (ns three-tier (:use (clojure.contrib.sql))) nil The latter :use call accomplished nothing, but that bit of knowledge is hard to come by. The enclosed patch changes Clojure to check for such a malformed prefix list and throw an exception with a message that should help narrow down the problem: user=> (ns three-tier (:use (clojure.contrib.sql))) java.lang.Exception: found prefix clojure.contrib.sql, but no name(s) (NO_SOURCE_FILE:0) --Steve Index: src/clj/clojure/boot.clj === --- src/clj/clojure/boot.clj(revision 1081) +++ src/clj/clojure/boot.clj(working copy) @@ -3202,6 +3202,7 @@ (apply load-lib nil (prependss arg opts)) (let [[prefix & args] arg] (throw-if (nil? prefix) "prefix cannot be nil") + (throw-if (nil? args) "found prefix %s, but no name(s)" prefix) (doseq arg args (apply load-lib prefix (prependss arg opts --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
On Oct 28, 8:48 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Java does thread protect, but it is synchronized. Also java.math and > java.util's random number generator aren't pluggable with alternate > implementations. For that I would need SecureRandom. > > For my simple example I think I will use a per-thread > java.util.Random, note the issues, and point interested readers to the > literature. Does using a per-thread java.util.Random object guarantee that the threads' random streams are not correlated? If you pick the seeds unluckily then the threads' random streams might overlap, making the Monte Carlo method's results suspect. mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
Java does thread protect, but it is synchronized. Also java.math and java.util's random number generator aren't pluggable with alternate implementations. For that I would need SecureRandom. For my simple example I think I will use a per-thread java.util.Random, note the issues, and point interested readers to the literature. This has me wondering: should Clojure's rand and rand-int default to use a thread-bound instance of java.util.Random? Stuart > On Oct 27, 7:06 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: >> ; take samples, tracking number that land >> ; :in circle and :total number >> (defn sample-for-pi [count] >>(reduce (fn [{in :in total :total} point] >> {:in (if (in-circle? point) (inc in) in) >> :total (inc total)}) >> {:in 0 :total 0} >> (take count (repeatedly random-point > > You'll need to use a different pseudorandom number generator / > pseudorandom stream for each thread. Otherwise adding more threads > won't help performance much, because they will serialize on the PRNG. > (Hopefully Java thread-protects the PRNG's state -- the C library > doesn't, which makes for interesting errors ;-) .) Using Pthread > mutexes to protect the thread state, in a C implementation of a Monte > Carlo method on an 8-core 2-socket recent Intel box, I was only able > to get 2x speedup. (For game tree search I can get 8x speedup on the > same machine.) > > Check out the following parallel PRNG tutorial for more info: > > http://www.cs.berkeley.edu/~mhoemmen/cs194/Tutorials/prng.pdf > > mfh > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
On Oct 27, 7:06 pm, Stuart Halloway <[EMAIL PROTECTED]> wrote: > ; take samples, tracking number that land > ; :in circle and :total number > (defn sample-for-pi [count] > (reduce (fn [{in :in total :total} point] > {:in (if (in-circle? point) (inc in) in) > :total (inc total)}) > {:in 0 :total 0} > (take count (repeatedly random-point You'll need to use a different pseudorandom number generator / pseudorandom stream for each thread. Otherwise adding more threads won't help performance much, because they will serialize on the PRNG. (Hopefully Java thread-protects the PRNG's state -- the C library doesn't, which makes for interesting errors ;-) .) Using Pthread mutexes to protect the thread state, in a C implementation of a Monte Carlo method on an 8-core 2-socket recent Intel box, I was only able to get 2x speedup. (For game tree search I can get 8x speedup on the same machine.) Check out the following parallel PRNG tutorial for more info: http://www.cs.berkeley.edu/~mhoemmen/cs194/Tutorials/prng.pdf mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
Hi Stuart, A lot of parallel processing problems seem to lend themselves to a mapreduce approach. I've written a few blog entries on mapreduce in the past: http://bc.tech.coop/blog/060105.html http://bc.tech.coop/blog/070520.html http://bc.tech.coop/blog/070601.html Bill On Tue, Oct 28, 2008 at 8:08 AM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > Hi Bill, > > Thanks, that's a good point re: await. It would also be interesting to > have the agents run for a certain length of time, rather than a > certain number of iterations. > > What do you think of using a map argument to a reduce fn? Idiomatic > Clojure seems to prefer using a vector, but I am biased toward a map > based on Ruby experience. I haven't decided which is more readable. > > Stuart > >> Hi Stuart, >> >> On Mon, Oct 27, 2008 at 7:06 PM, Stuart Halloway >> <[EMAIL PROTECTED]> wrote: >>> >>> Hi all, >>> >>> The code below implements a Monte Carlo simulation to estimate the >>> value of pi. It works, and it was easy to reuse the original single- >>> threaded approach across multiple agents. >>> >>> How idiomatic is this use of agents? Other than bringing in ForkJoin, >>> are there other idiomatic ways to parallelize divide-and-conquer in >>> Clojure? >>> >>> Cheers, >>> Stuart >>> >>> (defn in-circle? [[x y]] >>> (<= (Math/sqrt (+ (* x x) (* y y))) 1)) >>> >>> (defn random-point [] >>> [(dec (rand 2)) (dec (rand 2))]) >>> >>> ; take samples, tracking number that land >>> ; :in circle and :total number >>> (defn sample-for-pi [count] >>> (reduce (fn [{in :in total :total} point] >>> {:in (if (in-circle? point) (inc in) in) >>>:total (inc total)}) >>> {:in 0 :total 0} >>> (take count (repeatedly random-point >>> >>> >>> (defn guess-from-samples [samples] >>> (assoc samples :guess (/ (* 4.0 (:in samples)) (:total samples >>> >>> ; guess pi by running Monte Carlo simulation count times >>> (defn guess-pi [count] >>> (guess-from-samples (sample-for-pi count))) >>> >>> ; guess pi by running Monte Carlo simulation count times >>> ; spread across n agents >>> (defn guess-pi-agent [n count] >>> (let [count (quot count n) >>> agents (for [_ (range n)] (agent count))] >>>(doseq a agents (send a sample-for-pi)) >>>(apply await agents) >>>(guess-from-samples (reduce (fn [a1 a2] >>> {:in (+ (:in @a1) (:in @a2)) >>> :total (+ (:total @a1) (:total >>> @a2))}) >>> agents >> >> I've not gotten around to playing with the concurrency features of >> Clojure yet, so I'm just commenting "theoretically" on your code. In >> "guess-pi-agent", you use "await" to wait for the results from the >> agents. If one of the agents "dies", won't your code wait forever? I >> would think that it would be preferable to use "await-for" (with a >> timeout) so that the result can still be guessed based on the samples >> that have come back from the other agents. If you plan to use a >> variation of this code in a multi-processor example, some degree of >> agent failure is even more likely. >> >> -- >> Bill Clementson >> >> > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: troubleshooting classloader problems
On Oct 28, 8:48 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > Hi all, > > When I am troubleshooting classloader problems I find myself wanting > to know the list of URLs currently on the classpath. I didn't find > this exposed anywhere, so I wrote the functions below. > > Usage: > > (take 3 (classpath-url-seq)) > -> ("file:/Users/stuart/relevance/personal/SHCLOJ_svn/Book/code/" > "file:/Users/stuart/repos/clojure-contrib/clojure-contrib.jar" > "file:/Users/stuart/devtools/java/joda-time-1.5.2/joda- > time-1.5.2.jar") > > Of course to be most helpful this needs to be in clojure.jar -- > otherwise you might have classloader problems loading the classloader > help code. :-) Not sure if this is general enough to deserve to be in > clojure.jar, but you're welcome to it if others find it useful. > > Stuart > > ; --- > (defn classloader-seq > ([] (classloader-seq (clojure.lang.RT/baseLoader))) > ([cl] > (loop [loaders (vector cl)] > (if (nil? (last loaders)) > (drop-last loaders) > (recur (conj loaders (.getParent (last loaders > > (defn classpath-url-seq [& args] > (map (memfn toExternalForm) > (reduce concat > (map (memfn getURLs) > (apply classloader-seq args) I like it. I think it is a good idea to put it in clojure.jar. It certainly helps troubleshooting. Allen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
Hi Bill, Thanks, that's a good point re: await. It would also be interesting to have the agents run for a certain length of time, rather than a certain number of iterations. What do you think of using a map argument to a reduce fn? Idiomatic Clojure seems to prefer using a vector, but I am biased toward a map based on Ruby experience. I haven't decided which is more readable. Stuart > Hi Stuart, > > On Mon, Oct 27, 2008 at 7:06 PM, Stuart Halloway > <[EMAIL PROTECTED]> wrote: >> >> Hi all, >> >> The code below implements a Monte Carlo simulation to estimate the >> value of pi. It works, and it was easy to reuse the original single- >> threaded approach across multiple agents. >> >> How idiomatic is this use of agents? Other than bringing in ForkJoin, >> are there other idiomatic ways to parallelize divide-and-conquer in >> Clojure? >> >> Cheers, >> Stuart >> >> (defn in-circle? [[x y]] >> (<= (Math/sqrt (+ (* x x) (* y y))) 1)) >> >> (defn random-point [] >> [(dec (rand 2)) (dec (rand 2))]) >> >> ; take samples, tracking number that land >> ; :in circle and :total number >> (defn sample-for-pi [count] >> (reduce (fn [{in :in total :total} point] >> {:in (if (in-circle? point) (inc in) in) >>:total (inc total)}) >> {:in 0 :total 0} >> (take count (repeatedly random-point >> >> >> (defn guess-from-samples [samples] >> (assoc samples :guess (/ (* 4.0 (:in samples)) (:total samples >> >> ; guess pi by running Monte Carlo simulation count times >> (defn guess-pi [count] >> (guess-from-samples (sample-for-pi count))) >> >> ; guess pi by running Monte Carlo simulation count times >> ; spread across n agents >> (defn guess-pi-agent [n count] >> (let [count (quot count n) >> agents (for [_ (range n)] (agent count))] >>(doseq a agents (send a sample-for-pi)) >>(apply await agents) >>(guess-from-samples (reduce (fn [a1 a2] >> {:in (+ (:in @a1) (:in @a2)) >> :total (+ (:total @a1) (:total >> @a2))}) >> agents > > I've not gotten around to playing with the concurrency features of > Clojure yet, so I'm just commenting "theoretically" on your code. In > "guess-pi-agent", you use "await" to wait for the results from the > agents. If one of the agents "dies", won't your code wait forever? I > would think that it would be preferable to use "await-for" (with a > timeout) so that the result can still be guessed based on the samples > that have come back from the other agents. If you plan to use a > variation of this code in a multi-processor example, some degree of > agent failure is even more likely. > > -- > Bill Clementson > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
Hi Stuart, On Mon, Oct 27, 2008 at 7:06 PM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > Hi all, > > The code below implements a Monte Carlo simulation to estimate the > value of pi. It works, and it was easy to reuse the original single- > threaded approach across multiple agents. > > How idiomatic is this use of agents? Other than bringing in ForkJoin, > are there other idiomatic ways to parallelize divide-and-conquer in > Clojure? > > Cheers, > Stuart > > (defn in-circle? [[x y]] > (<= (Math/sqrt (+ (* x x) (* y y))) 1)) > > (defn random-point [] > [(dec (rand 2)) (dec (rand 2))]) > > ; take samples, tracking number that land > ; :in circle and :total number > (defn sample-for-pi [count] > (reduce (fn [{in :in total :total} point] >{:in (if (in-circle? point) (inc in) in) > :total (inc total)}) > {:in 0 :total 0} > (take count (repeatedly random-point > > > (defn guess-from-samples [samples] > (assoc samples :guess (/ (* 4.0 (:in samples)) (:total samples > > ; guess pi by running Monte Carlo simulation count times > (defn guess-pi [count] > (guess-from-samples (sample-for-pi count))) > > ; guess pi by running Monte Carlo simulation count times > ; spread across n agents > (defn guess-pi-agent [n count] > (let [count (quot count n) >agents (for [_ (range n)] (agent count))] > (doseq a agents (send a sample-for-pi)) > (apply await agents) > (guess-from-samples (reduce (fn [a1 a2] > {:in (+ (:in @a1) (:in @a2)) > :total (+ (:total @a1) (:total @a2))}) >agents I've not gotten around to playing with the concurrency features of Clojure yet, so I'm just commenting "theoretically" on your code. In "guess-pi-agent", you use "await" to wait for the results from the agents. If one of the agents "dies", won't your code wait forever? I would think that it would be preferable to use "await-for" (with a timeout) so that the result can still be guessed based on the samples that have come back from the other agents. If you plan to use a variation of this code in a multi-processor example, some degree of agent failure is even more likely. -- Bill Clementson --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
On Tue, Oct 28, 2008 at 9:51 AM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > P.S. I think that is the second time you have had to tell me to stop > using "count" as a local name. Bad habits die slowly... :-) Ah, don't worry about it. I'm still catching myself using "seq" as an argument name. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
On Oct 27, 10:45 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job, > Stuart! Thanks! On Oct 28, 9:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > If you'd like, I think the effort would be better spent on making a > version of fcase for the base library. Cool! > I'd like to save unadorned "case" for this meaning. Fine by me. > There is implicit arg ordering (pred clause-value test-value) which > doesn't matter for some preds (=) but does for others (instance?). For > the uses thus far, this order seems good - instance? and re-find work > well, but there will be cases where people will want (pred test-value > clause-value). The order of things in the macro structure might imply > the latter: ... > (condp (= x _) ;doesn't matter > (condp (instance? _ x) > (condp (some #{x} _) How about just one argument, the predicate: (condp #(= x %) ...) That would resolve the issue without adding syntax, no? > As far as the default, providing a default value as odd last clause is > ok, but subtle, and could use layout help, if we do that we should do > the same for cond. I stole that idea from Arc's "if", which has the interesting quality of unifying "if" and "cond". I often use the "else" clause to throw an exception: (condp #(= x %) 42 "The Meaning of Life" 13 "Unlucky" 1 "The loneliest number" (throw (Exception. "Nothing matched.")) I feel like "econdp" would be less clear, since you don't know what kind of exception should be thrown. Plain old Exception? Or RuntimeError? > Finally there is the name, which has to follow the form and function. > If we go with something like the last above, I like condp/econdp. I'm not sure about condp, only because Clojure hasn't used the CL-ish "-p" suffix anywhere else. Ideas: condfn, fcond, cond-apply, cond- with, try-each,... -S --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: genclass error message
Hi, On 7 Okt., 01:57, Chouser <[EMAIL PROTECTED]> wrote: > Currently if you fail to provide or mis-name the main fn in a > gen-class implementation, you get an error like: > > Exception in thread "main" java.lang.UnsupportedOperationException: > net.n01se/main not defined > > This is wrong, since the name shouldn't be just "main". Attached is a > patch to change this error to: > > Exception in thread "main" java.lang.UnsupportedOperationException: > net.n01se/TestObj-main not defined > > --Chouser > > fix-genclass-error.patch > < 1KViewDownload I want to bring this back to mind. The message is still not fixed. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: genclass error message
On Oct 28, 9:51 am, mb <[EMAIL PROTECTED]> wrote: > Hi, > > On 7 Okt., 01:57, Chouser <[EMAIL PROTECTED]> wrote: > > > > > Currently if you fail to provide or mis-name the main fn in a > > gen-class implementation, you get an error like: > > > Exception in thread "main" java.lang.UnsupportedOperationException: > > net.n01se/main not defined > > > This is wrong, since the name shouldn't be just "main". Attached is a > > patch to change this error to: > > > Exception in thread "main" java.lang.UnsupportedOperationException: > > net.n01se/TestObj-main not defined > > > --Chouser > > > fix-genclass-error.patch > > < 1KViewDownload > > I want to bring this back to mind. The message is still not fixed. > Patch applied - thanks Chouser! Thanks for the reminder, Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
Hi Stephen, Rich, I haven't had my tea yet either, so I'll look at this some more later. -S On Oct 28, 9:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Oct 27, 10:45 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > > > I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job, > > Stuart! > > Yes, I haven't done enough poking around in contrib - fcase looks like > a promising candidate for boot.clj. > > > I have an idea for another fcase variant that I think is useful: > > My thoughts are that there should only be fcase (discussion on name > follows). The variants (re-case, instance-case etc) just pollute the > namespace and add complexity without any new semantics, nor any > significant concision. For the same reasons, we don't have specialized > versions of filter etc. I'd much rather people understand the > semantics of fcase and use it with any predicate they choose: > > (fcase instance? ... > > (fcase = ... > > (fcase re-find ... > > > (defmacro pred-case > > "Case where test values are predicates to be applied to the test > > value." > > [test-value & clauses] > > `(fcase (fn [pred# value#] (pred# value#)) ~test-value [EMAIL > > PROTECTED])) > > That could be: > > (fcase #(% %2) ... > > > Stuart, would you please consider adding pred-case to > > clojure.contrib.fcase? > > If you'd like, I think the effort would be better spent on making a > version of fcase for the base library. > > The issues I have are with the name, arg ordering and default/no-match > handling. > > While fcase is structurally similar to case, case is normally reserved > for equality testing against constant, unevaluated expressions, the > idea being the compiler could possibly leverage knowledge of the > constant values to do something fast. They often have order of test > promises, but I think that's wrong. I'd like to save unadorned "case" > for this meaning. > > This doesn't rule out the use of "case" somewhere in the name, but is > something to consider. Another way to look at fcase is like a > parameterized cond. > > There is implicit arg ordering (pred clause-value test-value) which > doesn't matter for some preds (=) but does for others (instance?). For > the uses thus far, this order seems good - instance? and re-find work > well, but there will be cases where people will want (pred test-value > clause-value). The order of things in the macro structure might imply > the latter: > > (fcase pred test-value > clause-value ... > > and it might be difficult for people to remember which it is. > > One possibility is to make it explicit in the macro syntax with a > placeholder (_): > > (fcase = x _ ;doesn't matter > ... > > (fcase instance? _ x > ... > > (fcase some #{x} _ > ... > > or maybe: > > (condp (= x _) ;doesn't matter > ... > > (condp (instance? _ x) > ... > > (condp (some #{x} _) > ... > > As far as the default, providing a default value as odd last clause is > ok, but subtle, and could use layout help, if we do that we should do > the same for cond. When no default is provided, there should be some > option for an exception on no match. That could either always be the > case, or a second variant of the macro (e.g. CL has ecase) > > Finally there is the name, which has to follow the form and function. > If we go with something like the last above, I like condp/econdp. > > I haven't finished my tea, so consider this idle, groggy speculation. > > Comment/discussion welcome. > > Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: idiomatic Clojure for agents?
I have not looked at pmap yet, but I expect it will be a better fit, since Monte Carlo is a good fit for Fork/Join. I am considering using this example across a variety of implementation strategies for the concurrency chapter in the book. Aside from agents and pmap, any other approaches spring to mind? Stuart P.S. I think that is the second time you have had to tell me to stop using "count" as a local name. Bad habits die slowly... :-) > On Mon, Oct 27, 2008 at 10:06 PM, Stuart Halloway > <[EMAIL PROTECTED]> wrote: >> >> The code below implements a Monte Carlo simulation to estimate the >> value of pi. It works, and it was easy to reuse the original single- >> threaded approach across multiple agents. >> >> How idiomatic is this use of agents? Other than bringing in ForkJoin, >> are there other idiomatic ways to parallelize divide-and-conquer in >> Clojure? > > Did you look at pmap? You might be able to use something like (pmap > (fn [_] (sample-for-pi count)) (range count)), and then use that in > your guess-from-samples reduce. I'm thinking this might be better > because it would handle more of the work: scaling to the number of > CPUs, launching the agents, waiting for the results. I'm not sure > it's a perfect fit -- perhaps pmap adds unneeded overhead. > > BTW, using "count" as a local name can cause surprises later when > someone tries to use the clojure/count function. > > --Chouser > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
troubleshooting classloader problems
Hi all, When I am troubleshooting classloader problems I find myself wanting to know the list of URLs currently on the classpath. I didn't find this exposed anywhere, so I wrote the functions below. Usage: (take 3 (classpath-url-seq)) -> ("file:/Users/stuart/relevance/personal/SHCLOJ_svn/Book/code/" "file:/Users/stuart/repos/clojure-contrib/clojure-contrib.jar" "file:/Users/stuart/devtools/java/joda-time-1.5.2/joda- time-1.5.2.jar") Of course to be most helpful this needs to be in clojure.jar -- otherwise you might have classloader problems loading the classloader help code. :-) Not sure if this is general enough to deserve to be in clojure.jar, but you're welcome to it if others find it useful. Stuart ; --- (defn classloader-seq ([] (classloader-seq (clojure.lang.RT/baseLoader))) ([cl] (loop [loaders (vector cl)] (if (nil? (last loaders)) (drop-last loaders) (recur (conj loaders (.getParent (last loaders (defn classpath-url-seq [& args] (map (memfn toExternalForm) (reduce concat (map (memfn getURLs) (apply classloader-seq args) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggest fcase variant "pred-case"
On Oct 27, 10:45 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote: > I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job, > Stuart! > Yes, I haven't done enough poking around in contrib - fcase looks like a promising candidate for boot.clj. > I have an idea for another fcase variant that I think is useful: > My thoughts are that there should only be fcase (discussion on name follows). The variants (re-case, instance-case etc) just pollute the namespace and add complexity without any new semantics, nor any significant concision. For the same reasons, we don't have specialized versions of filter etc. I'd much rather people understand the semantics of fcase and use it with any predicate they choose: (fcase instance? ... (fcase = ... (fcase re-find ... > (defmacro pred-case >"Case where test values are predicates to be applied to the test > value." >[test-value & clauses] >`(fcase (fn [pred# value#] (pred# value#)) ~test-value [EMAIL PROTECTED])) > That could be: (fcase #(% %2) ... > Stuart, would you please consider adding pred-case to > clojure.contrib.fcase? > If you'd like, I think the effort would be better spent on making a version of fcase for the base library. The issues I have are with the name, arg ordering and default/no-match handling. While fcase is structurally similar to case, case is normally reserved for equality testing against constant, unevaluated expressions, the idea being the compiler could possibly leverage knowledge of the constant values to do something fast. They often have order of test promises, but I think that's wrong. I'd like to save unadorned "case" for this meaning. This doesn't rule out the use of "case" somewhere in the name, but is something to consider. Another way to look at fcase is like a parameterized cond. There is implicit arg ordering (pred clause-value test-value) which doesn't matter for some preds (=) but does for others (instance?). For the uses thus far, this order seems good - instance? and re-find work well, but there will be cases where people will want (pred test-value clause-value). The order of things in the macro structure might imply the latter: (fcase pred test-value clause-value ... and it might be difficult for people to remember which it is. One possibility is to make it explicit in the macro syntax with a placeholder (_): (fcase = x _ ;doesn't matter ... (fcase instance? _ x ... (fcase some #{x} _ ... or maybe: (condp (= x _) ;doesn't matter ... (condp (instance? _ x) ... (condp (some #{x} _) ... As far as the default, providing a default value as odd last clause is ok, but subtle, and could use layout help, if we do that we should do the same for cond. When no default is provided, there should be some option for an exception on no match. That could either always be the case, or a second variant of the macro (e.g. CL has ecase) Finally there is the name, which has to follow the form and function. If we go with something like the last above, I like condp/econdp. I haven't finished my tea, so consider this idle, groggy speculation. Comment/discussion welcome. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: classpath problem on MacOSX
Thanks! It works! For someone like me, here is an example code. Case 1: clj file /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/duck- streams/duck-stream.clj (add-classpath "file:///Users/chanwoo/Documents/lisp/clojure/code/") (use 'clojure.contrib.duck-streams) Case 2: Test class in test.jar /Users/chanwoo/sandbox/temp/test.jar (add-classpath "file:///Users/chanwoo/sandbox/temp/") (import '(test Test)) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: classpath problem on MacOSX
Hi, On 28 Okt., 12:42, Chanwoo Yoo <[EMAIL PROTECTED]> wrote: > Thanks! mb. I did a stupid mistake. There no stupid mistakes. Unless you do them twice... ;) > "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clojure/code: > $CLASSPATH" Is this verbatim? The first " should be after the =. echo $CLASSPATH in a shell helps to find out, which value of CLASSPATH java actually sees when started from the shell. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: classpath problem on MacOSX
Ah, Java's classpath handling - a constant source of delight. Using $CLASSPATH is not a reliable way of adjusting your classpath, because its contents will only be considered if you don't specifiy anything else on the java command line, i.e. if you start clojure like this $ java -cp clojure.jar clojure.lang.Repl $CLASSPATH wil be ignored. I usually set up my classpaths from within clojure via (add- classpath ...), this seems to be the least painful way. Kind regards, achim Am 28.10.2008 um 12:42 schrieb Chanwoo Yoo: > > Thanks! mb. I did a stupid mistake. > > But It still doesn't work after correcting typing. > > canu-yuyi-macbook-air:duck_streams chanwoo$ pwd > /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ > duck_streams > canu-yuyi-macbook-air:duck_streams chanwoo$ ls > duck_streams.clj > > ~/.profile > "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clojure/code: > $CLASSPATH" > > user=> (use 'clojure.contrib.duck-streams) > java.io.FileNotFoundException: Could not locate Clojure resource on > classpath: clojure/contrib/duck_streams/duck_streams.clj > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: CLASSPATH problem on MacOSX
not sure but try renaming = ANGOL = -|[EMAIL PROTECTED], =|+^_^X++~_~,@- "The only thing worse than a hopeless romantic is a hopeful one" Magbasa bago Mamuna. Mag-isip bago mambatikos Without Truth there is no Justice, Without Justice, there is Tyranny Semper fi Proof of Desire is Pursuit www.onthe8spot.com [EMAIL PROTECTED] 09173822367 On Tue, Oct 28, 2008 at 5:56 PM, Chanwoo Yoo <[EMAIL PROTECTED]> wrote: > > Hi. > > When I try to use 'contrib' library, next error message occurs. > > user=> (use 'clozure.contrib.duck-streams) > java.io.FileNotFoundException: Could not locate Clojure resource on > classpath: clozure/contrib/duck_streams/duck_streams.clj > > My '.profile' file in home directory are as following: > "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/*clozure*/code: > $CLASSPATH" > > canu-yuyi-macbook-air:duck_streams chanwoo$ pwd > /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ > duck_streams > > canu-yuyi-macbook-air:duck_streams chanwoo$ ls > duck_streams.clj > > How can I fix this? Any help appreciated. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: classpath problem on MacOSX
Thanks! mb. I did a stupid mistake. But It still doesn't work after correcting typing. canu-yuyi-macbook-air:duck_streams chanwoo$ pwd /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ duck_streams canu-yuyi-macbook-air:duck_streams chanwoo$ ls duck_streams.clj ~/.profile "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clojure/code: $CLASSPATH" user=> (use 'clojure.contrib.duck-streams) java.io.FileNotFoundException: Could not locate Clojure resource on classpath: clojure/contrib/duck_streams/duck_streams.clj --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: string interpolation
I've always preferred a function like str to either of these options anyway. (str "Hi " someone ", my name is " myname) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: classpath problem on MacOSX
Hi, On 28 Okt., 08:42, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi. > > When I try to use 'contrib' library, next error message occurs. > > user=> (use 'clozure.contrib.duck-streams) > java.io.FileNotFoundException: Could not locate Clojure resource on > classpath: clozure/contrib/duck_streams/duck_streams.clj > > My '.profile' file in home directory are as following: > "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clozure/code: > $CLASSPATH" > > canu-yuyi-macbook-air:duck_streams chanwoo$ pwd > /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ > duck_streams > > How can I fix this? Any help appreciated. There are several z's flying around. Please check the correct typing: In your directory paths (as via pwd above) you use clo*j*ure, while in the use call you use clo*z*ure. (Stars for emphasis). Since the directory setup with for CLASSPATH looks correct, please try the following settings. in your .profile: export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clojure/code: $CLASSPATH" in clojure: (use 'clojure.contrib.duck-streams) (Note: the j in clojure compared to your original z in clozure.) Hope this helps. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: string interpolation
Hi Islon, On 28 Okt., 04:38, Islon <[EMAIL PROTECTED]> wrote: > Is there any chance closure will get string interpolation? > > Do things like (prn "Hi ${someone}, my name is ${myname}") is nice, not > crucial of course, but nice. There is format. user=> (def someone "World") #=(var user/someone) user=> (format "Hello %s!" someone) "Hello World!" Not exactly, what you want, but close. The format string syntax is described at java.util.Formatter in the Java docs. Sincerely Meikel --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
classpath problem on MacOSX
Hi. When I try to use 'contrib' library, next error message occurs. user=> (use 'clozure.contrib.duck-streams) java.io.FileNotFoundException: Could not locate Clojure resource on classpath: clozure/contrib/duck_streams/duck_streams.clj My '.profile' file in home directory is as following: "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clozure/code: $CLASSPATH" canu-yuyi-macbook-air:duck_streams chanwoo$ pwd /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ duck_streams How can I fix this? Any help appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
string interpolation
Is there any chance closure will get string interpolation? Do things like (prn "Hi ${someone}, my name is ${myname}") is nice, not crucial of course, but nice. Islon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
CLASSPATH problem on MacOSX
Hi. When I try to use 'contrib' library, next error message occurs. user=> (use 'clozure.contrib.duck-streams) java.io.FileNotFoundException: Could not locate Clojure resource on classpath: clozure/contrib/duck_streams/duck_streams.clj My '.profile' file in home directory are as following: "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clozure/code: $CLASSPATH" canu-yuyi-macbook-air:duck_streams chanwoo$ pwd /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ duck_streams canu-yuyi-macbook-air:duck_streams chanwoo$ ls duck_streams.clj How can I fix this? Any help appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
classpath problem on MacOSX
Hi. When I try to use 'contrib' library, next error message occurs. user=> (use 'clozure.contrib.duck-streams) java.io.FileNotFoundException: Could not locate Clojure resource on classpath: clozure/contrib/duck_streams/duck_streams.clj My '.profile' file in home directory are as following: "export CLASSPATH=.:/Users/chanwoo/Documents/lisp/clozure/code: $CLASSPATH" canu-yuyi-macbook-air:duck_streams chanwoo$ pwd /Users/chanwoo/Documents/lisp/clojure/code/clojure/contrib/ duck_streams How can I fix this? Any help appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---