HOM - Higher Order Messages

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

HOM - Higher Order Messages

Francisco Garau-2
Hi,

During our first UK Smalltalk meeting, Marcel Weiher presented the ideas
behind Higher Order Messages [1]. With them your collection code looks much
nicer. Compare:

Without HOM:

    #(1 2 3) collect: [:e | e + 1]
    #(1 2 3) inject: 0 into: [:a :b | a + b]
    #(1 2 3) addAll: #(4 5)

With HOM:

    #(1 2 3) collect + 1
    #(1 2 3) reduce + 0
    #(1 2 3) add: #(4 5) all

Has anybody implemented them Squeak?
Marcel mentioned a port to VW, but he also mentioned that it is quite easy
to implement.

The APL guys at the meeting where very excited about the #reduce message
(which they denote by / ). They didn't like that you have to specifiy the
initial value. I think that with some double dispatching, we could avoid
having that initial value. We could have code like this: #(1 2 3) / +

Cheers,
Francisco

[1] http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf 


Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

ccrraaiigg

        Those are neat, but I find the originals more readable (especially for
newcomers).


-C

p.s.

        I'm enjoying stuff like "18 April 2006" a lot more. :)  Quoth is full
of things like that (e.g., "1 second, 3rd g sharp, 60 percent volume,
2nd channel").

--
Craig Latta
improvisational musical informaticist
www.netjam.org
Smalltalkers do: [:it | All with: Class, (And love: it)]



Reply | Threaded
Open this post in threaded view
|

RE: HOM - Higher Order Messages

Blaine Buxton
In reply to this post by Francisco Garau-2
Hello,
I have a package on SqueakMap called "LazyCollections". The idea originally
was to implement the common collection protcols to lazy evaluate. But, when
I read the HOM paper, I decided to try it out. It turned out to be trivial
to implement in "LazyCollections".

For an example, see LazyCollectionTest>>testIterator. The LazyIterator class
is where the magic begins. I didn't implement everything in the HOM paper. I
mainly did LazyCollections as an experiment. If you get anything out of it,
please let me know.
------------------------------------------------
Blaine Buxton, Mad Scientist In Training
http://www.blainebuxton.com




>From: "Francisco Garau" <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: "Squeak List" <[hidden email]>
>Subject: HOM - Higher Order Messages
>Date: Tue, 18 Apr 2006 22:25:40 +0100
>
>Hi,
>
>During our first UK Smalltalk meeting, Marcel Weiher presented the ideas
>behind Higher Order Messages [1]. With them your collection code looks much
>nicer. Compare:
>
>Without HOM:
>
>    #(1 2 3) collect: [:e | e + 1]
>    #(1 2 3) inject: 0 into: [:a :b | a + b]
>    #(1 2 3) addAll: #(4 5)
>
>With HOM:
>
>    #(1 2 3) collect + 1
>    #(1 2 3) reduce + 0
>    #(1 2 3) add: #(4 5) all
>
>Has anybody implemented them Squeak?
>Marcel mentioned a port to VW, but he also mentioned that it is quite easy
>to implement.
>
>The APL guys at the meeting where very excited about the #reduce message
>(which they denote by / ). They didn't like that you have to specifiy the
>initial value. I think that with some double dispatching, we could avoid
>having that initial value. We could have code like this: #(1 2 3) / +
>
>Cheers,
>Francisco
>
>[1] http://www.metaobject.com/papers/Higher_Order_Messaging_OOPSLA_2005.pdf
>
>

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

Francisco Garau-2
In reply to this post by ccrraaiigg
Craig said:
> "Those are neat, but I find the originals more readable (especially for
> newcomers)"

But you are not a newcomer!! How do you know they are more readable?

In Marcel's paper, there is some justification as to why the code with HOM
is more readable. Without HOM, you have explicit iteration and when reading
such expressions, you are forced to jump between two layers of abstractions.
You have to think about the collection and about the elements of the
collection. Too bad.

Taking the example of Marcel and Stef's paper, if Sally and Alice are two
objects representing a manager with its employees, and Sally leaves the
company, we need to add Sally's reports to Alice's. Your code would look
like:

    sally reports do: [ :each | alice addReport:each ]

The main subject of this expression (Alice) is now in the middle. You
mentally jump inside and outside of the block. Of course, experienced
Smalltalkers do this without noticing. But it would be more natural to
express the same thing with HOM:

    alice addReport: sally reports all

Beautiful, isn't it?

-Francisco

----- Original Message -----
From: "Craig Latta" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, April 18, 2006 11:47 PM
Subject: Re: HOM - Higher Order Messages


>
>
>
> -C
>
> p.s.
>
> I'm enjoying stuff like "18 April 2006" a lot more. :)  Quoth is full of
> things like that (e.g., "1 second, 3rd g sharp, 60 percent volume, 2nd
> channel").
>
> --
> Craig Latta
> improvisational musical informaticist
> www.netjam.org
> Smalltalkers do: [:it | All with: Class, (And love: it)]
>
>
>


Reply | Threaded
Open this post in threaded view
|

RE: HOM - Higher Order Messages

Alan L. Lovejoy
In reply to this post by ccrraaiigg


Craig: "I'm enjoying stuff like "18 April 2006" a lot more. :)"

Grin.  By they way, "18 April 2006" just happens to be the 100-year
anniversary of the Great San Francisco Earthquake.  Hope that doesn't "shake
you up." :-)

So far, my main focus with Chronos has been correctly modeling and
implementing dates and times, and providing a rich time model.

Adding "syntactic sugar" can be done later. And of course, the
"method-selector-competitition among libraries" issue must be considered,
whenever convenience methods are added, since they usually involve adding
methods to fundamental classes of the base Smalltalk class library.

--Alan



Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

Andreas.Raab
In reply to this post by Francisco Garau-2
Francisco Garau wrote:
>    alice addReport: sally reports all
>
> Beautiful, isn't it?

Unusual for sure. Beautiful? I don't know. The statement "sally reports
all" means something entirely different in english than in it does in
the above (which is largely because the above violates basic english
language structure making "reports" a noun where in english it can only
be a verb). If we take it from plain english we might get something like
"alice adds each of sally's reports" which we might translate as "alice
add: each_of sally reports" or so but that's not exactly beautiful
either. Unusual, for sure ;-)

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

RE: HOM - Higher Order Messages

Trygve
In reply to this post by ccrraaiigg
And what does this wonderful compiler do with 7/4/2006 ?
It is 7 April here, 4th July there. >:-o

A programming language should be precise and simple, not "intelligent". No
surprises, please. :-)

Cheers
--Trygve

At 09:35 19.04.2006, you wrote:


>Craig: "I'm enjoying stuff like "18 April 2006" a lot more. :)"
>
>Grin.  By they way, "18 April 2006" just happens to be the 100-year
>anniversary of the Great San Francisco Earthquake.  Hope that doesn't "shake
>you up." :-)
>
>So far, my main focus with Chronos has been correctly modeling and
>implementing dates and times, and providing a rich time model.
>
>Adding "syntactic sugar" can be done later. And of course, the
>"method-selector-competitition among libraries" issue must be considered,
>whenever convenience methods are added, since they usually involve adding
>methods to fundamental classes of the base Smalltalk class library.
>
>--Alan


--

Trygve Reenskaug      mailto: [hidden email]
Morgedalsvn. 5A       http://heim.ifi.uio.no/~trygver
N-0378 Oslo           Tel: (+47) 22 49 57 27
Norway



Reply | Threaded
Open this post in threaded view
|

RE: HOM - Higher Order Messages

Alan L. Lovejoy

Trygve: "And what does this wonderful compiler do with 7/4/2006 ?
It is 7 April here, 4th July there. >:-o"

Good point.

In the VW and Dolphin versions of Chronos, there are instance methods of
String such as #mdyAsDate, #dmyAsDate and #ymdAsDate, that parse a
YearMonthDay (a "date") from a String.  The method selector should make it
clear what the expected interpretation of '7/4/2006' is:

        '7/4/2006' dmyAsDate => 2006-April-07
        '7/4/2006' mdyAsDate => 2006-July-04

--Alan




Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

ccrraaiigg
In reply to this post by Francisco Garau-2

 > > Those are neat, but I find the originals more readable (especially
 > > for newcomers)"
 >
 > But you are not a newcomer! How do you know they are more readable?

        I teach newcomers.


-C

--
Craig Latta
improvisational musical informaticist
www.netjam.org
Smalltalkers do: [:it | All with: Class, (And love: it)]



Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

timrowledge

On 19-Apr-06, at 8:33 AM, Craig Latta wrote:

>
> > > Those are neat, but I find the originals more readable (especially
> > > for newcomers)"
> >
> > But you are not a newcomer! How do you know they are more readable?
>
> I teach newcomers.
Don't you mean
Newcomers allStudents do:[:newcomer| Craig teach: newcomer]


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: BOZO: Use Multics operating system



Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

Darius Clarke
> Newcomers allStudents do:[:newcomer| Craig teach: newcomer]

I guess that depends. Does he teach them in sequence or in parallel?

.. and how do we overload ">" in the above message quotes?

;)
Darius

Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

Darius Clarke
And how many students in a Class definition?

Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

Lothar Schenk
In reply to this post by timrowledge
tim Rowledge wrote:

> On 19-Apr-06, at 8:33 AM, Craig Latta wrote:
>
> > I teach newcomers.
>
> Don't you mean
> Newcomers allStudents do:[:newcomer| Craig teach: newcomer]

Why should the newcomers have to do anything, if Craig does the teaching?

Lothar

Reply | Threaded
Open this post in threaded view
|

Re: HOM - Higher Order Messages

timrowledge

On 20-Apr-06, at 5:21 AM, Lothar Schenk wrote:

> tim Rowledge wrote:
>
>> On 19-Apr-06, at 8:33 AM, Craig Latta wrote:
>>
>>> I teach newcomers.
>>
>> Don't you mean
>> Newcomers allStudents do:[:newcomer| Craig teach: newcomer]
>
> Why should the newcomers have to do anything, if Craig does the  
> teaching?

Well in *my* day (me being so old and creaky that my tutors were pre-
hominid) the students were expected to do a great deal of work. To  
the point of burning out about 40% by the middle of second year and  
another 10% or so before the commencement of third year.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Useful Latin Phrases:- Estne volumen in toga, an solum tibi libet me  
videre? = Is that a scroll in your toga, or are you just happy to see  
me?