Re: Tryclojure - A Call To Action
really like the site. i like the tutorial section. it would be nice if the site would focus more on examples. On Nov 4, 5:49 pm, Rayne disciplera...@gmail.com wrote: http://blog.acidrayne.net/?p=25 I wrote this blog post in the hopes that I can motivate people to contribute to tryclojure.http://try-clojure.orgis a relatively important website that is unfortunately subpar. I hope that with the community's help, we can turn it into something spectacular. -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Java gotchas now clojure gotchas
Math/abs doesn't always return positive numbers. example: user= (def min-int -2147483648) #'user/min-int user= min-int -2147483648 user= (Math/abs min-int) -2147483648 user= (def min-int+1 (+ 1 min-int)) #'user/min-int+1 user= min-int+1 -2147483647 user= (Math/abs (- min-int+1 1)) -2147483648 (Math/abs (- Integer/MIN_VALUE 1)) 2147483649 so, in order to solve this problem, clojure needs it's own ABS, or it needs to convert a negative int approaching Integer/MIN_VALUE to something else before it reaches Integer/MIN_VALUE. so, does it sound sane for clojure to fix java's surprises? -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java gotchas now clojure gotchas
this is on clojure 1.1 (current ubuntu stable rep) so, the code below shows ABS returning 2 different values for the 'same' input in clojure. input being Integer.MIN_VALUE. of course one input is an int and the other is a bigint, but we can't see the difference in clojure, and as the code shows at the end, clojure says they are the same input. @CuppoJava: to take more care in how we code is a good idea, but i feel that rich hickey doesn't want users of clojure to be thinking about if a certain function is going to act a certain way for inputs that clojure says are the same, but java says are different. i think this type of problem is on the same level as managing the memory of your application. user= (def min-int-1 (+ -1 min-int)) #'user/min-int-1 user= min-int-1 -2147483649 user= (- min-int-1 min-int) -1 user= (Math/abs (+ 1 min-int-1)) 2147483648 user= (Math/abs min-int) -2147483648 user= (= (+ 1 min-int-1) min-int) true @Sean Corfield: I haven't tried this on clojure 1.3. is it part of the clojure road map to eliminate the surprises built into the java language? I think that it would be easy to eliminate a majority of them. a good resource is the book 'java puzzlers' http://www.javapuzzlers.com/ which provides the code in the book for free on their website. not all of the surprises will apply to clojure because they'll be avoided by avoiding the use of java, but some will still apply, and they should be considered in the definition of the language, and when using interop code. so, in summary, ABS in java has a bug/surprise. clojure uses this directly. so clojure has a bug in abs. it's really unlikely that someone will pass abs an Integer.MIN_VALUE, but maybe it should be considered. i think the more likely thing to happen is that abs will be passed a number that is a result of another number being manipulated. so one solution would be to change to a bigint earlier than the language does now. or maybe closure could make a safe abs wrapper. I know it's not a big deal, but when you write a program that uses all integers (quite easy to program in clojure), and also uses abs, and it breaks when it hits this bug... Rich hickey's answer to why he made clojure was that he wanted to write programs without going crazy, fixing some of the stuff that is broken in java, that clojure uses, seems like it follows that spirit. On Nov 2, 9:33 pm, Sean Corfield seancorfi...@gmail.com wrote: On Tue, Nov 2, 2010 at 3:22 PM, box somethingital...@gmail.com wrote: Math/abs doesn't always return positive numbers. example: Have you tried this on 1.3.0-master-SNAPSHOT? user= (def min-int -2147483648) #'user/min-int user= (Math/abs min-int) 2147483648 user= (def min-int+1 (+ 1 min-int)) #'user/min-int+1 user= min-int+1 -2147483647 user= (Math/abs (- min-int+1 1)) 2147483648 user= (Math/abs (- Integer/MIN_VALUE 1)) 2147483649 -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. --http://getrailo.com/ An Architect's View --http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java gotchas now clojure gotchas
sorry, i wrote too soon. (Math/abs (- Long/MIN_VALUE 1)) java.lang.IllegalArgumentException: No matching method found: abs (NO_SOURCE_FILE:0) so, maybe this is a good time to start a clojure math library. or at least have some warning when using math libs in clojure. On Nov 2, 10:32 pm, Paul Iannazzo somethingital...@gmail.com wrote: user= (Math/abs (- Long/MIN_VALUE 1) this hung my clojure repl, clojure 1.1 ~~ Paul Joseph Iannazzo. On Tue, Nov 2, 2010 at 10:09 PM, ataggart alex.tagg...@gmail.com wrote: In a two's-complement system, values always have one more negative number than positive number. -2147483648 (being the most negative int) has no positive equivalent that can be expressed as an int (Math/abs overloads on primitive type). Sean's example using 1.3.0-SNAPSHOT works because literal numbers are now read in as longs or doubles. This is also why the original (Math/ abs (- Integer/MIN_VALUE 1)) gave the desired result as the int was converted to a long via the subtraction function. Of course, the same problem would arise if one tried to use the most negative long: user= (Math/abs Long/MIN_VALUE) -9223372036854775808 The unsurprising behavior might be for a clojure abs function to instead throw an ArithmeticException, since 9223372036854775808 cannot be expressed as a long. -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Java gotchas now clojure gotchas
http://richhickey.github.com/clojure-contrib/math-api.html i just found this. i guess i wasn't paying attention because i didn't see it stated before as a solution. thank you. On Nov 2, 10:45 pm, Mark Engelberg mark.engelb...@gmail.com wrote: On Tue, Nov 2, 2010 at 7:35 PM, box somethingital...@gmail.com wrote: so, maybe this is a good time to start a clojure math library. or at least have some warning when using math libs in clojure. To reiterate what was said earlier in this thread, clojure.contrib.math extends basic math functionality to Clojure's full numeric tower. Specifically, clojure.contrib.math/abs will do what you expect it should do. This library is broken by the alpha releases of 1.3, but should work fine with any of the officially released versions of Clojure. -- 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 that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en