- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Temporary Values in Constructors Retained As Fields
Sun, 2009-03-15, 22:26
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
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