Re: Today's clojure trick question

2010-08-19 Thread Mark Shroyer
Sean Corfield writes: > On Wed, Aug 18, 2010 at 10:28 AM, Shantanu Kumar > wrote: >> Would suggest to consider this: >> >> (let [ x (true? (new java.lang.Boolean false)) ] (if x "trouble" >> "ok")) > > Ah, but that wouldn't work for a new Boolean set to true: > > (let [ x (true? (new java.lang.B

Re: Today's clojure trick question

2010-08-19 Thread Armando Blancas
I copy that. Thanks for the explanation. On Aug 18, 1:22 pm, Matt Fowles wrote: > Armando~ > > Libraries that target JRE 1.2 compatibility, will not call > `Boolean.valueOf(var)` internally.  Instead they will call `new > Boolean(var)`.  If they return those results to modern java code, it will >

Re: Today's clojure trick question

2010-08-19 Thread Matt Fowles
Armando~ Libraries that target JRE 1.2 compatibility, will not call `Boolean.valueOf(var)` internally. Instead they will call `new Boolean(var)`. If they return those results to modern java code, it will unbox correctly into either true or false and thus work as expected in constructs of the for

Re: Today's clojure trick question

2010-08-18 Thread joegallo
> However, if you do (let [x (java.lang.Boolean/getBoolean "false")] (if > x :trouble :ok)) you're fine, which obviously isn't helpful in your > situation. Boolean.getBoolean() is pretty evil, too. It was featured in one of Joshua Bloch's java puzzlers (which might have been borrowed from somewhe

Re: Today's clojure trick question

2010-08-18 Thread Armando Blancas
I don't see what the concern may be. Can you elaborate? On Aug 18, 10:04 am, Matt Fowles wrote: > All~ > > Boolean.valueOf() was added in 1.4.  While that seems ancient, some older > libraries use 'new Boolean()' because they maintain 1.2 compatibility.  It > seems like Clojure should take more c

Re: Today's clojure trick question

2010-08-18 Thread Matt Fowles
All~ Boolean.valueOf() was added in 1.4. While that seems ancient, some older libraries use 'new Boolean()' because they maintain 1.2 compatibility. It seems like Clojure should take more care when it unboxes Booleans... Matt On Wed, Aug 18, 2010 at 12:57 PM, Nicolas Oury wrote: > I am not an

Re: Today's clojure trick question

2010-08-18 Thread Sean Corfield
On Wed, Aug 18, 2010 at 10:28 AM, Shantanu Kumar wrote: > Would suggest to consider this: > > (let [ x (true? (new java.lang.Boolean false)) ] (if x "trouble" > "ok")) Ah, but that wouldn't work for a new Boolean set to true: (let [ x (true? (new java.lang.Boolean true)) ] (if x "ok" "trouble"))

Re: Today's clojure trick question

2010-08-18 Thread Shantanu Kumar
Would suggest to consider this: (let [ x (true? (new java.lang.Boolean false)) ] (if x "trouble" "ok")) Regards, Shantanu On Aug 18, 10:05 pm, Chas Emerick wrote: > No, you can put a breakpoint on any class, regardless of where it's > been loaded from. > > In this case, I'd suggest not relying

Re: Today's clojure trick question

2010-08-18 Thread Chas Emerick
No, you can put a breakpoint on any class, regardless of where it's been loaded from. In this case, I'd suggest not relying on the line numbers shown in source dumps. At least in my experience, line numbers in the standard library source differ from what is shown at runtime. All three Java IDEs

Re: Today's clojure trick question

2010-08-18 Thread Nicolas Oury
I am not an expert. Is it possible on some JDK to put a breakpoint on Boolean constructor and look at the stack? Or you can't put a breakpoint on standard library? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cl

Re: Today's clojure trick question

2010-08-18 Thread David Nolen
On Wed, Aug 18, 2010 at 11:58 AM, Brian Hurt wrote: > For the record, no where in my code am I deliberately creating Boolean > objects. Why the hell would I write (new java.lang.Boolean false) when I > can just as easily write false? And I have looked through the code to see > if something stup

Re: Today's clojure trick question

2010-08-18 Thread Andrew Gwozdziewycz
On Wed, Aug 18, 2010 at 11:09 AM, Brian Hurt wrote: > Consider the following bit of code: > > (let [ x (new java.lang.Boolean false) ] (if x "trouble" "ok")) I consider the fact that Boolean has a public constructor a bug. It can only ever represent 2 values. However, if you do (let [x (java.lan

Re: Today's clojure trick question

2010-08-18 Thread Brian Hurt
On Wed, Aug 18, 2010 at 11:34 AM, David Nolen wrote: > On Wed, Aug 18, 2010 at 11:09 AM, Brian Hurt wrote: > >> This is, however, more than a little bit surprising and depressing. >> Somewhere, in my 10K lines of clojure code, boolean values are getting boxed >> in exactly that way. I've fixed t

Re: Today's clojure trick question

2010-08-18 Thread Chouser
On Wed, Aug 18, 2010 at 11:09 AM, Brian Hurt wrote: > Consider the following bit of code: > > (let [ x (new java.lang.Boolean false) ] (if x "trouble" "ok")) The Javadoc for Boolean has something to say on this subject[1] as does the following excerpt from Fogus' book The Joy of Clojure: Don't c

Re: Today's clojure trick question

2010-08-18 Thread David Nolen
On Wed, Aug 18, 2010 at 11:09 AM, Brian Hurt wrote: > This is, however, more than a little bit surprising and depressing. > Somewhere, in my 10K lines of clojure code, boolean values are getting boxed > in exactly that way. I've fixed the current problem (dropping in a call to > .booleanValue in

Re: Today's clojure trick question

2010-08-18 Thread Nicolas Oury
(defmacro fat-if) On Wed, Aug 18, 2010 at 4:09 PM, Brian Hurt wrote: > Consider the following bit of code: > > (let [ x (new java.lang.Boolean false) ] (if x "trouble" "ok")) > > As you might guess from the fact that I'm calling it's a trick question, the > above code returns "trouble", not "