[racket] Style and Performance question
Thanks for the summary. I was going to post something similar shortly. As
always, thanks to the community for your help.
Pat
On May 10, 2011 7:51 PM, "Matthew Flatt" <mflatt at cs.utah.edu> wrote:
I think all of your questions have been covered in the thread, but I'll
answer them again to offer a few extra opinions and to summarize the
discussion...
At Mon, 9 May 2011 18:38:41 -0500, Patrick King wrote:
> I now show the "approved" solution, and my...
For generic arithmetic on values other than fixnums, the local binding
is likely worthwhile, mostly because it avoids repeated boxing of the
arithmetic result. (At least for now; see below on plans for CSE.)
I also find the code easier to read with the local binding.
> Question 1a: How creeped are you by my changing the meaning of error for
> these few lines? I ...
It didn't bother me or even occur to me that you were shadowing the
usual `error' binding. Still, it's probably better to avoid shadowing
bindings like `error' when you notice.
> Question 2: The approved solution favored (/ ... (+ x x)) over my (/ ... 2
> x). Cost of division...
The "strength" of arithmetic operations --- such as devision versus
addition --- is unlikely to matter. The big effects are (1) using
inexacts versus exact rationals, where inexacts tend to be faster, (2)
mixing inexacts and exacts, which is slower than just inexacts, and (3)
using flonum-specific operations (or Typed Racket with the `Float'
type) versus generic operations, where flonum-specific operations can
be much faster because they enable unboxing in the compiler.
> With multiple recalls of the same value?
The Racket compiler does not currently perform common-subexpression
elimination (CSE). As it happens, I've been thinking about adding a CSE
pass, but it's difficult to predict whether that will happen next week
or next year.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110511/85e1f07d/attachment.html>