This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Temporary Values in Constructors Retained As Fields

1 reply
Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.

On Sunday March 15 2009, Ismael Juma wrote:
> On Sun, 2009-03-15 at 11:42 -0700, Jorge Ortiz wrote:
> > Neverming, it seems that doesn't actually help.
>
> For the ones who haven't checked, the reason why it doesn't help is
> that the tuple returned from the block is stored as a synthetic
> field. It does help in cases where one needs to use some locals in
> the process of computing a single result. e.g.:
>
> val numer = {
> val g = gcd(n.abs, d.abs)
> n / g
> }
>
> In this case, g is not stored as a field.

True, but you're back to calling gcd twice, once to compute the reduced
numerator and once for the denominator.

> Ismael

Randall Schulz

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: Temporary Values in Constructors Retained As Fields

On Sun, 2009-03-15 at 12:26 -0700, Randall R Schulz wrote:
> On Sunday March 15 2009, Ismael Juma wrote:
> > On Sun, 2009-03-15 at 11:42 -0700, Jorge Ortiz wrote:
> > > Neverming, it seems that doesn't actually help.
> >
> > For the ones who haven't checked, the reason why it doesn't help is
> > that the tuple returned from the block is stored as a synthetic
> > field. It does help in cases where one needs to use some locals in
> > the process of computing a single result. e.g.:
> >
> > val numer = {
> > val g = gcd(n.abs, d.abs)
> > n / g
> > }
> >
> > In this case, g is not stored as a field.
>
> True, but you're back to calling gcd twice, once to compute the reduced
> numerator and once for the denominator.

I know and hence why I said "It does help in cases where one needs to
use some locals in the process of computing a single result."

Your case requires storing locals in the process of computing more than
one result, so this solution doesn't help (at least until the tuple
storage bug is fixed).

Best,
Ismael

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland