coercion automatically calling a user defined coercion multimethod in case of type mismatch with arguments passed to a type hinted function..

2010-11-29 Thread Sunil S Nandihalli
Hello everybody, I was just wondering if we could have functions automatically call a multimethod whose dispatch-value would be a vector typename of the current argument and required argument type. and accept the return value of that function as the argument in place of the current argument. I kno

Purpose of Macros

2010-11-29 Thread Andreas Kostler
I'm watching Richs' excellent Clojure for Java developers videos. One comment he makes puzzles me though. He is elaborating about how powerful macro abstraction is. The specific argument he gives is closing files in Java and how macros save you typing the exact thing. I don't quite get what he mean

Purpose of Macros

2010-11-29 Thread Andreas Kostler
I'm watching Richs' excellent Clojure for Java developers videos. One comment he makes puzzles me though. He is elaborating about how powerful macro abstraction is. The specific argument he gives is closing files in Java and how macros save you typing the exact thing. I don't quite get what he mean

Re: Purpose of Macros

2010-11-29 Thread Ken Wesson
In Java, you often have to pair things, e.g. opening a file and closing it, to avoid leaking resources like file handles. These pairings are among many cases where Java code contains structure that you can't extract and reify in your program. Macros make it possible to extract any such pattern, r

Re: Purpose of Macros

2010-11-29 Thread Petr Gladkikh
On Mon, Nov 29, 2010 at 3:29 PM, Ken Wesson wrote: > In Java, you often have to pair things, e.g. opening a file and > closing it, to avoid leaking resources like file handles. > > These pairings are among many cases where Java code contains structure > that you can't extract and reify in your pro

Re: Symbol evaluation error in let

2010-11-29 Thread Sunil S Nandihalli
That was really neat ken ... eval-with-local-vars.. I think it should be part of the core... Sunil. On Sun, Nov 28, 2010 at 8:02 AM, Ken Wesson wrote: > Caveat: since eval-with-local-vars is a macro you won't be able to > directly use it in HOFs. Wrapping it in a closure works, however: > > user

Re: Reusing Clojure libraries in Java/Jythom/Scala

2010-11-29 Thread Dilvan
Hi, From today, I will not receive updates from this group, so if anyone cares to answer this question, please send me an email: dil...@gmail.com. I do think that this is an important question to many people that liked a lot the Clojure concurrency model but cannot use Clojure in their day t

Re: Symbol evaluation error in let

2010-11-29 Thread Sunil S Nandihalli
Hi Ken, Just wrapping your macro with the following would save you the trouble of having to enumerate the local variables ... (defmacro eval-with-local-bindings [sexp] `(eval-with-local-vars ~(apply vector (keys &env)) ~sexp)) Sunil. On Mon, Nov 29, 2010 at 6:22 PM, Sunil S Nandihalli < sunil.na

Re: ANN: Dr. Evil - the evil web debugger

2010-11-29 Thread Constantine Vetoshev
On Nov 22, 6:43 pm, Miki wrote: > >Dr.Evilis a simple web debugger that provides a REPL to your web > > application in a "hidden" location. This is pretty useful, thanks! I tried adding Dr. Evil into a test app, but I'm having trouble switching namespaces in the REPL: => *ns* # => (in-ns 'cv-te

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Stuart Halloway
Performance. > why not change > < type compare functions do a compare on strings as > well? > > (defn > > ([x] true) > ([x y](if (string? x) >(. clojure.lang.Numbers (isPos (.compareTo x y))) >(. clojure.lang.Numbers (gt x y > ([x y & more] > (if (> x y

Re: dosync style

2010-11-29 Thread James Reeves
I'd say the former was more idiomatic Clojure. There's no need to make refs compatible with atoms (otherwise why have two different concurrency primitives in the first place). Additionally, earmuffs (like *this*) should only be used on vars that you expect to override in a binding, like *out* or *

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Alyssa Kwan
IMHO, any built-in string compare should support collations. I think this belongs in contrib in string. On Nov 29, 2:59 am, Tim Robinson wrote: > why not change > < type compare functions do a compare on strings as > well? > > (defn > >         ([x] true) >   ([x y](if (string? x) >             (

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Christian Vest Hansen
I think it will make more sense to branch on whether something is Comparable or IComparable, than a string. On Mon, Nov 29, 2010 at 08:59, Tim Robinson wrote: > why not change > < type compare functions do a compare on strings as > well? > > (defn > >        ([x] true) >  ([x y](if (string? x) >

Re: dosync style

2010-11-29 Thread Stuart Halloway
I must respectfully disagree with James's first point here. The first pattern (read-ponder-update) is not concurrency-friendly. It isn't about atom vs. ref, the important distinction is whether all the work can be done in a function that gets sent *to* the ref. The latter formulation also can b

Re: dosync style

2010-11-29 Thread Laurent PETIT
2010/11/29 Stuart Halloway > I must respectfully disagree with James's first point here. The first > pattern (read-ponder-update) is not concurrency-friendly. It isn't about > atom vs. ref, the important distinction is whether all the work can be done > in a function that gets sent *to* the ref.

Re: dosync style

2010-11-29 Thread Jozef Wagner
I think it is because concurrent stuff can happen between let and alter in the first example. Is it true that in that case, one would have to use "ensure" to make the operation correct? On Nov 29, 5:53 pm, Laurent PETIT wrote: > 2010/11/29 Stuart Halloway > > > I must respectfully disagree with

Re: dosync style

2010-11-29 Thread Laurent PETIT
2010/11/29 Jozef Wagner > I think it is because concurrent stuff can happen between let and > alter in the first example. Is it true that in that case, one would > have to use "ensure" to make the operation correct? > That's my point (at least the way I understand it, I do not use a lot of concu

Re: ANN: Dr. Evil - the evil web debugger

2010-11-29 Thread Miki
> This is pretty useful, thanks! Glad someone other than me likes it :) > I tried adding Dr. Evil into a test app, but I'm having trouble > switching namespaces in the REPL: > > => *ns* > # > => (in-ns 'cv-test-1.core) > # > => *ns* > # > > It seems to always reset the namespace to clojure.core. Y

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Tim Robinson
I dunno, Where is this arbitrary point people set where language improvements/ ease-of-use become less important than negligible performance impacts? I ran several benchmarks, with warm up and correct time measurements, and didn't get the impression the change was in anyway significant. Take the

Re: Why isn't there a fold-right?

2010-11-29 Thread Meikel Brandmeyer
Hi, Am 28.11.2010 um 21:33 schrieb Asim Jalis: > This looks like map rather than foldr. > > On Sun, Nov 28, 2010 at 7:40 AM, tpeng wrote: >> i have a one: >> (defn lazy-foldr [f coll] >>(lazy-seq >>(if-let [[x & xs] coll] >>(cons x (lazy-foldr f xs) >> >> it seems w

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread David Nolen
On Mon, Nov 29, 2010 at 2:28 PM, Tim Robinson wrote: > I dunno, > > Where is this arbitrary point people set where language improvements/ > ease-of-use become less important than negligible performance impacts? > I ran several benchmarks, with warm up and correct time measurements, > and didn't ge

Re: Purpose of Macros

2010-11-29 Thread Ken Wesson
On Mon, Nov 29, 2010 at 6:28 AM, Petr Gladkikh wrote: > On Mon, Nov 29, 2010 at 3:29 PM, Ken Wesson wrote: >> In Java, you often have to pair things, e.g. opening a file and >> closing it, to avoid leaking resources like file handles. >> >> These pairings are among many cases where Java code cont

Re: Symbol evaluation error in let

2010-11-29 Thread Ken Wesson
On Mon, Nov 29, 2010 at 8:31 AM, Sunil S Nandihalli wrote: > Hi Ken, > Just wrapping your macro with the following would save you the trouble of > having to enumerate the local variables ... > (defmacro eval-with-local-bindings [sexp] >   `(eval-with-local-vars ~(apply vector (keys &env)) ~sexp))

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Sean Corfield
+1 String comparisons that don't support i18n collations are next to useless, IMO. A bare < or > operator can't "do the right thing" in the general case for strings. Stuart's and David's points about performance are compelling too. On Mon, Nov 29, 2010 at 7:24 AM, Alyssa Kwan wrote: > IMHO, any

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Tim Robinson
huh? Making a change to the > function doesn't mean you *can't* write high performance data structures in Clojure. It just means, you *may* need to use a different fn name as opposed to the common one. Similarly I could simply use a different name to accomplish my own function that includes string

Re: dosync style

2010-11-29 Thread Stuart Sierra
On Nov 28, 5:36 pm, Takahiro Hozumi wrote: > Which style do you like? This one: > (defn dec-or-dissoc! [key] >   (dosync >    (alter *counts* >           (fn [m] >             (let [n (m key)] >               (if (< 1 n) >                 (assoc m key (dec n)) >                 (dissoc m key

Re: coercion automatically calling a user defined coercion multimethod in case of type mismatch with arguments passed to a type hinted function..

2010-11-29 Thread Stuart Sierra
Hi Sunil, This is one of those things that seems really useful for development, but ends up being a lot of trouble down the road. For one thing, it's hard to make it perform well. For another, it can lead to unexpected results when you add in inheritance hierarchies and overloaded methods. -S

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread David Nolen
But the facilities for what you want are already there. Define a more generic > < and exclude the ones from core. I'm constantly excluding fns from core which have names I'd rather use in my own source. David On Monday, November 29, 2010, Tim Robinson wrote: > huh? Making a change to the > func

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Tim Robinson
I already do that, but that doesn't help general masses of people who would benefit from consistent & intuitive language constructs. On Nov 29, 5:57 pm, David Nolen wrote: > But the facilities for what you want are already there. Define a more > generic > < and exclude the ones from core. > > I'

Re: will calling set on an existing set shortcircuit the call and return the same set or would it create a new one?

2010-11-29 Thread Ken Wesson
On Mon, Nov 29, 2010 at 8:07 PM, Sunil S Nandihalli wrote: > Hello everybody, >  I have a small doubt. Suppose > (def s #{1 2 3 4 5 6}) > (set s) > will calling set on an existing set shortcircuit the call and return the > same set or would it create a new one? I would like to extend the question

Re: dosync style

2010-11-29 Thread Ken Wesson
On Mon, Nov 29, 2010 at 7:42 PM, Stuart Sierra wrote: > On Nov 28, 5:36 pm, Takahiro Hozumi wrote: >> Which style do you like? > > This one: > >> (defn dec-or-dissoc! [key] >>   (dosync >>    (alter *counts* >>           (fn [m] >>             (let [n (m key)] >>               (if (< 1 n) >>    

Re: will calling set on an existing set shortcircuit the call and return the same set or would it create a new one?

2010-11-29 Thread Sunil S Nandihalli
Thanks Ken, I didn't realize I could test it so easily. But I would like it to ideally return the same collection .. Shouldn't be hard to write a wrapper .. But I think it should be the default behaviour. Thanks again, Sunil. On Tue, Nov 30, 2010 at 7:05 AM, Ken Wesson wrote: > On Mon, Nov 29,

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread David Nolen
On Mon, Nov 29, 2010 at 8:05 PM, Tim Robinson wrote: > I already do that, but that doesn't help general masses of people who > would benefit from consistent & intuitive language constructs. I've never wanted such a feature. But perhaps many people do. However from what I've seen the past couple

Re: coercion automatically calling a user defined coercion multimethod in case of type mismatch with arguments passed to a type hinted function..

2010-11-29 Thread Sunil S Nandihalli
Thanks Stuart. You are probably right. But may be there can be a modified defn-auto-coerce .. Thats just a thought .. May be I will try to implement it . .but would love to hear any pointers you may have in that direction before I go it myself.. I am still an ametuer when it comes to Clojure .. so

Re: Wolfram: 100 years since Principia Mathematica

2010-11-29 Thread Raoul Duke
On Sat, Nov 27, 2010 at 9:36 PM, Duane Searsmith wrote: > That doesn't make Wolfram a lunatic or a fraud.  Remember that > mathematicians like Mandelbrot where also considered frauds at first. mandelbrot came and talked at the place i was working ~5 year ago, during a book tour of his re fractals

will calling set on an existing set shortcircuit the call and return the same set or would it create a new one?

2010-11-29 Thread Sunil S Nandihalli
Hello everybody, I have a small doubt. Suppose (def s #{1 2 3 4 5 6}) (set s) will calling set on an existing set shortcircuit the call and return the same set or would it create a new one? I would like to extend the question to hash-map and vec.. thanks, Sunil. -- You received this message be

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Tim Robinson
2. I agree with having both. 3. Lol. I love that you asked your wife and kids that's where I always go. However, I don't think they represent a reasonable audience. When I say the general masses for intuition, I'm speaking about the average programmer whom reasonably would want to compare t

Re: sort-by reverse order?

2010-11-29 Thread Alex Baranosky
I had some fun with this and added assert-args: (defmacro assert-args [fnname pred msg & pred-msg-pairs] `(when-not ~pred (throw (IllegalArgumentException. ~(str fnname " requires " msg (when (seq pred-msg-pairs) (list* `assert-args fnname pred-msg-pairs))) (def ascending compare)

when to use io! macro?

2010-11-29 Thread Alex Baranosky
Hi guys, I've recently discovered the io! macro. Is this something to try to use all the time.. or only in certain situations? Alex -- 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 Note t

Re: why not change > < type compare functions do a compare on strings as well?

2010-11-29 Thread Laurent PETIT
I certainly from time to time have to rewrite some comparator for strings for GUI stuff (sort by label, etc.). Even there, sometimes I need to sort without caring about capital letters, sometimes I don't need ... But indeed having some ready to use string comparators in a str package could be int