[squeak-dev] Block argument syntax

Eliot Miranda eliot.miranda at gmail.com
Sat Mar 2 01:01:40 UTC 2013


On Fri, Mar 1, 2013 at 7:05 AM, Frank Shearar <frank.shearar at gmail.com>wrote:

> Hi Ron,
>
> Oh dear. Here I was hoping it was just a Squeak bug, because that
> would be easy to fix. You can't define a method "foo : arg" after all;
> the : is part of the selector.
>

But you can define foo:arg.  The point is that the : is part of the
selector, and whitespace after the colon and before the formal variable is
allowed.  So [:a:b:c| is analogous to a selector :::.  It's more obvious if
one writes _: a _: b _: c, etc.  This syntax was thought about carefully.

BTW, you can also define a method that looks like

"comment" foo ^self


> I stumbled upon this because I noticed that Haskell's type identifiers
> - like "add :: Int -> Int -> Int" are very nearly valid Smalltalk.
> It's just the "::" that's not valid because we don't permit :s in
> binary selectors.
>
> frank
>
> On 1 March 2013 14:48, Ron Teitelbaum <ron at usmedrec.com> wrote:
> > Hi Frank,
> >
> > I know this is true for a number of Smalltalk implementations.  I found
> it
> > very surprising also.  Someone I worked with always formatted their code
> > this way.  He said it made it easier to double click and highlight the
> > variable.  I wasn't sure that was enough reason to do it but he did.
> >
> > Ron
> >
> >> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
> >> bounces at lists.squeakfoundation.org] On Behalf Of Frank Shearar
> >>
> >> I was rather surprised to learn that the following is valid syntax:
> >>
> >>     [ : x | x + 1]
> >>
> >> (Note the space before the argument name.)
> >>
> >> In fact, this is too:
> >>
> >>     [ : "This is a really long comment in a very, very strange place.
> >> It makes it very hard to see that the : before this comment turns the
> > token after
> >> this comment into a block argument." x | x + 1]
> >>
> >> Is that intentional? Does ANSI Smalltalk define it?
> >>
> >> frank
> >>
> >
> >
> >
>
>


-- 
best,
Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20130301/7892bb7e/attachment.htm


More information about the Squeak-dev mailing list