Use of -> in Pharo Code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Use of -> in Pharo Code

bprior
I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?
Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

Pharo Smalltalk Users mailing list
Hi Bruce,

good to see you around, again!

The arrow is an Association in short...

Sebastian


Am 29.11.2016 um 18:48 schrieb Bruce Prior:
I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?


Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

Martin McClure-2
In reply to this post by bprior
On 11/29/2016 06:48 PM, Bruce Prior wrote:
I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?

As Sebastian said, #-> is a message that creates an Association, with the receiver as the key and the argument as the value of the Association. This has actually been around a very long time, though perhaps it's getting more widely used these days. It doesn't appear to be in the Blue Book, but I think it was probably actually in the Smalltalk-80 image 1 release.

I'm not *quite* curious enough to verify that by rooting around in my basement for the machine that actually runs that version and seeing if it will still power up after all these years. :-)

Regards,

-Martin

Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

philippeback
Would be nice to have a video with that.

Phil

On Wed, Nov 30, 2016 at 6:25 AM, Martin McClure <[hidden email]> wrote:
On 11/29/2016 06:48 PM, Bruce Prior wrote:
I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?

As Sebastian said, #-> is a message that creates an Association, with the receiver as the key and the argument as the value of the Association. This has actually been around a very long time, though perhaps it's getting more widely used these days. It doesn't appear to be in the Blue Book, but I think it was probably actually in the Smalltalk-80 image 1 release.

I'm not *quite* curious enough to verify that by rooting around in my basement for the machine that actually runs that version and seeing if it will still power up after all these years. :-)

Regards,

-Martin


Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

David T. Lewis
In reply to this post by Martin McClure-2
On Tue, Nov 29, 2016 at 09:25:18PM -0800, Martin McClure wrote:

> On 11/29/2016 06:48 PM, Bruce Prior wrote:
> >I have been away from smalltalk coding for a while. On returning to
> >the fold, I often see the use of a right arrow in code. Is this
> >something new?
> >
> >Today in a Teapot app example, I saw,
> >
> >Teapot on GET: '/welcome' -> 'Hello World!'; start.
> >
> >What is the arrow for?
>
> As Sebastian said, #-> is a message that creates an Association, with
> the receiver as the key and the argument as the value of the
> Association. This has actually been around a very long time, though
> perhaps it's getting more widely used these days. It doesn't appear to
> be in the Blue Book, but I think it was probably actually in the
> Smalltalk-80 image 1 release.
>
> I'm not *quite* curious enough to verify that by rooting around in my
> basement for the machine that actually runs that version and seeing if
> it will still power up after all these years. :-)
>
> Regards,
>
> -Martin
>

It is present in the Squeak 1.13 image of 1996, which I think is fairly
close to Blue Book.

You can run that original image from this web page:

 http://try.squeak.org

Dave
 

Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

stepharo
In reply to this post by bprior
Hi bruce

welcome and I hope that you have fun. 

What I noticed is that we get used really fast to supercool tools. Last year I had to work on a VW 2.5 version 
and I thought someone had cut my hands. I ws so slow with senders and implementors and rudimentary inspectors :)

Stef

I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?



--
Using Opera's mail client: http://www.opera.com/mail/
Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

bprior
In reply to this post by bprior
Hi Stef,

Thanks for the welcome back. I always have fun with Smalltalk in the Winter but each year Summer seems to get in the way.

I appreciate your reminiscences, but I still don't understand what the right aero (->) does.

Bruce


On 2016-11-30 12:21 PM, stepharo wrote:
Hi bruce

welcome and I hope that you have fun. 

What I noticed is that we get used really fast to supercool tools. Last year I had to work on a VW 2.5 version 
and I thought someone had cut my hands. I ws so slow with senders and implementors and rudimentary inspectors :)

Stef

I have been away from smalltalk coding for a while. On returning to the fold, I often see the use of a right arrow in code. Is this something new?

Today in a Teapot app example, I saw,

Teapot on GET: '/welcome' -> 'Hello World!'; start.

What is the arrow for?



--
Using Opera's mail client: http://www.opera.com/mail/

Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

Pharo Smalltalk Users mailing list
Hi Bruce,

in hsort again ;-)
This was your code:
Teapot on GET: '/welcome' -> 'Hello World!'; start.

Imagine it this way with brackets:

Teapot on GET: ('/welcome' -> 'Hello World!'); start.

This is the same as writing:

Teapot on GET: ( Associtation key: '/welcome' value: 'Hello World!') ; start.

Shorter:

 (x -> y) = (Association key: x value: y)

 The -> is the short version of the Association constructor.

I hope this makes things a little clearer.
Sebastian


Reply | Threaded
Open this post in threaded view
|

Re: Use of -> in Pharo Code

Ben Coman
In reply to this post by bprior
On Thu, Dec 1, 2016 at 8:12 AM, Bruce Prior <[hidden email]> wrote:
> don't understand what the right-arrow (->) does.

hi Bruce,

Its a message.  Select it and hit <ctrl-m> to view its implementation.

cheers -ben