From: Matthew Kerwin Date: 2013-04-06T08:36:31+09:00 Subject: [ruby-core:54039] Re: [ruby-trunk - Feature #8191] Short-hand syntax for duck-typing --047d7b3432fa650f2604d9a58e51 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Apr 5, 2013 11:20 PM, "rosenfeld (Rodrigo Rosenfeld Rosas)" < rr.rosas@gmail.com> wrote: > > > Issue #8191 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas). > > > phluid61 (Matthew Kerwin) wrote: > > =3D=3D=3D=3D Incidentally > > > > > In CoffeeScript, something that helps a lot and I'd love to see in Ruby > > > is that it allows us to declare a variable in a post-if and use that > > > variable in the statement: > > > > > > console.log a if a =3D b.length > > > > This already works, as long as ((|a|)) is already defined in scope as a variable: > > =3Dend > > This is exactly the point, Matthew. I don't want to have to use "a =3D ni= l" before just for the sake of having a declared variable. I believe the post-if should declare a variable that could be used by the statement if the variable doesn't exist yet, since that code should be executed before the statement anyway. This is off track for this thread, but to have it do what you want you'd have to reengineer the parser to use look-aheads. This is not a trivial change. Currently by the time it sees `a=3D=B4 it's already had to make a decision about whether the a in `p a=B4 is a variable or method. There are other tickets about this topic (I can't link them from my phone) but this part of the discussion would be better had over there. --047d7b3432fa650f2604d9a58e51 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Apr 5, 2013 11:20 PM, "rosenfeld (Rodrigo Rosenfeld Rosas)"= <rr.rosas@gmail.com> wrote= :
>
>
> Issue #8191 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas). >
>
> phluid61 (Matthew Kerwin) wrote:
> > =3D=3D=3D=3D Incidentally
> >
> > =A0> In CoffeeScript, something that helps a lot and I'd l= ove to see in Ruby
> > =A0> is that it allows us to declare a variable in a post-if a= nd use that
> > =A0> variable in the statement:
> > =A0>
> > =A0> console.log a if a =3D b.length
> >
> > This already works, as long as ((|a|)) is already defined in scop= e as a variable:
> > =3Dend
>
> This is exactly the point, Matthew. I don't want to have to use &q= uot;a =3D nil" before just for the sake of having a declared variable.= I believe the post-if should declare a variable that could be used by the = statement if the variable doesn't exist yet, since that code should be = executed before the statement anyway.

This is off track for this thread, but to have it do what you want you&#= 39;d have to reengineer the parser to use look-aheads.=A0 This is not a tri= vial change.=A0 Currently by the time it sees `a=3D=B4 it's already had= to make a decision about whether the a in `p a=B4 is a variable or method.=

There are other tickets about this topic (I can't link them from my = phone) but this part of the discussion would be better had over there.

--047d7b3432fa650f2604d9a58e51--