Compiling a role name into a message to self

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

Compiling a role name into a message to self

Trygve
I am just completing an experiment where I am programming with roles. A role name stands for one or more objects; the actual binding occur at run time.  Example:
        (self playerForRole: #currentStar) displayLarge
It would be much more readable if I could write something like
       ¤currentStar displayLarge  or §currentStar displayLarge or  :-) currentStar displayLarge or ...
currentStar is a role name, self playerForRole: searches down the stack to find the appropriate object binding .

I suppose I have to choose an appropriate syntax and doctor the compiler. Any ideas?

Thanks
--Trygve
-- 

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


Reply | Threaded
Open this post in threaded view
|

Re: Compiling a role name into a message to self

Tom Phoenix
On 11/19/07, Trygve Reenskaug <[hidden email]> wrote:

>  I am just completing an experiment where I am programming with roles. A
> role name stands for one or more objects; the actual binding occur at run
> time.  Example:
>          (self playerForRole: #currentStar) displayLarge
>  It would be much more readable if I could write something like
>         ¤currentStar displayLarge  or §currentStar displayLarge or  :-)
> currentStar displayLarge or ...
>  currentStar is a role name, self playerForRole: searches down the stack to
> find the appropriate object binding .

When does it search down the stack? You said "at run time," but
there's more than one possibility. For example, if I wrote code like
this:

  ¤currentPresident say: 'I hate my job.'.
  ¤currentPresident resign.
  ¤currentPresident takeOathOfOffice.

...would you want to search three times to identify the target object?
It would be a nice optimization to search only once, but it might
surprise somebody when the object changes. The King is dead, long live
the King!

If you wish to make that optimization, here's a fairly easy way to
implement it: Compile the method as if it had one extra named variable
for each ¤rolePlayer. Set each of these variables at the top of the
method code. Treat ¤rolePlayer more-or-less as a read-only variable
after that.

If you would have it look up the ¤rolePlayer each time, you'll simply
do it without the variables. In either case, you'll be sending "secret
messages" that the user didn't write, such as #playerForRole:, so you
should consider what you'll do to make it easy to handle the situation
when you can't identify the ¤currantPersident, or some such, at run
time.

If one ¤rolePlayer can mean many objects, but it's usually just one,
things get more complex. Could it also mean no objects at all? How can
end-user applications, which don't include debugging facilities, deal
with RoleNotFilled errors at run time? Do you need a RolePlayer class
to manage these things?

And the biggest question of all: Is the benefit of roles sufficient to
outweigh this added complexity? It might be....

Good luck with it!

--Tom Phoenix

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a role name into a message to self

Trygve
In reply to this post by Trygve
No response on my first SOS.

  • I am now in my first dive into the compiler; there's a lot to learn.
  • I first found the pragmas, but they do not seem to fit my purpose.
  • I next found the message selector macro facility in  MessageNode/special . Very neat, but I need to do something with a variable name, not a selector.

There are a host of different kinds of variables- local, instance, class, pool, ... It would be nice with yet another one: "computed" or "aliased". A special syntax for a variable name that will lead to  inlining a  method for finding the object currently accessed through the name.

I would really appreciate help from someone familiar with compiler work.

Thanks
--Trygve.


On 19.11.2007 19:03, Trygve Reenskaug wrote:
I am just completing an experiment where I am programming with roles. A role name stands for one or more objects; the actual binding occur at run time.  Example:
        (self playerForRole: #currentStar) displayLarge
It would be much more readable if I could write something like
       ¤currentStar displayLarge  or §currentStar displayLarge or  :-) currentStar displayLarge or ...
currentStar is a role name, self playerForRole: searches down the stack to find the appropriate object binding .

I suppose I have to choose an appropriate syntax and doctor the compiler. Any ideas?

Thanks
--Trygve
-- 

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


-- 

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


Reply | Threaded
Open this post in threaded view
|

Re: Compiling a role name into a message to self

Vassili Bykov-2
Modifying the compiler may be too much work for what you are
describing. Smalltalk message sends are already late-bound enough.
Have a variable named something like "player", used like so:

  player currentStar displayLarge

Meaning "player" would hold an instance of something called, say,
PlayerAgent, whose responsibility is to manage the mapping of roles to
players and return players in response to messages naming their roles.
How exactly it does that depends on how the roles are used. If there
are few roles known in advance, the agent can simply have instance
variables with accessors, one per role. For too many roles this can
become tedious, so the agent can instead hold the players in a
Dictionary and look them up in response to #doesNotUnderstand:.

Cheers,

--Vassili

On Nov 21, 2007 1:19 PM, Trygve Reenskaug <[hidden email]> wrote:

>
>  No response on my first SOS.
>
>
>
> I am now in my first dive into the compiler; there's a lot to learn.
> I first found the pragmas, but they do not seem to fit my purpose.
> I next found the message selector macro facility in  MessageNode/special .
> Very neat, but I need to do something with a variable name, not a selector.
>  There are a host of different kinds of variables- local, instance, class,
> pool, ... It would be nice with yet another one: "computed" or "aliased". A
> special syntax for a variable name that will lead to  inlining a  method for
> finding the object currently accessed through the name.
>
>  I would really appreciate help from someone familiar with compiler work.
>
>  Thanks
>  --Trygve.
>
>
>  On 19.11.2007 19:03, Trygve Reenskaug wrote:
> I am just completing an experiment where I am programming with roles. A role
> name stands for one or more objects; the actual binding occur at run time.
> Example:
>          (self playerForRole: #currentStar) displayLarge
>  It would be much more readable if I could write something like
>         ¤currentStar displayLarge  or §currentStar displayLarge or  :-)
> currentStar displayLarge or ...
>  currentStar is a role name, self playerForRole: searches down the stack to
> find the appropriate object binding .
>
>  I suppose I have to choose an appropriate syntax and doctor the compiler.
> Any ideas?
>
>  Thanks
>  --Trygve
>  --
>
> Trygve Reenskaug mailto: [hidden email]
> Morgedalsvn. 5A http://folk.uio.no/trygver
> N-0378 Oslo Tel: (+47) 22 49 57 27
> Norway
>
>
>
>  --
>
> Trygve Reenskaug mailto: [hidden email]
> Morgedalsvn. 5A http://folk.uio.no/trygver
> N-0378 Oslo Tel: (+47) 22 49 57 27
> Norway
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Compiling a role name into a message to self

Karl-19
In reply to this post by Trygve
There is a example in MorphicExtension where layout and other stuff etc
are held, and messages sent to Morph are sent to the extension.
Karl

Trygve Reenskaug wrote:

> No response on my first SOS.
>
>     * I am now in my first dive into the compiler; there's a lot to
>       learn.
>     * I first found the pragmas, but they do not seem to fit my purpose.
>     * I next found the message selector macro facility in
>       MessageNode/special . Very neat, but I need to do something with
>       a variable name, not a selector.
>
>
> There are a host of different kinds of variables- local, instance,
> class, pool, ... It would be nice with yet another one: "computed" or
> "aliased". A special syntax for a variable name that will lead to  
> inlining a  method for finding the object currently accessed through
> the name.
>
> I would really appreciate help from someone familiar with compiler work.
>
> Thanks
> --Trygve.
>
>
> On 19.11.2007 19:03, Trygve Reenskaug wrote:
>> I am just completing an experiment where I am programming with roles.
>> A role name stands for one or more objects; the actual binding occur
>> at run time.  Example:
>>         /(self playerForRole: #currentStar) displayLarge/
>> It would be much more readable if I could write something like
>>        /¤currentStar displayLarge / or /§currentStar displayLarge/
>> or / :-) currentStar displayLarge /or ...
>> /currentStar /is a role name, /self playerForRole:/ searches down the
>> stack to find the appropriate object binding .
>>
>> I suppose I have to choose an appropriate syntax and doctor the
>> compiler. Any ideas?
>>
>> Thanks
>> --Trygve
>> --
>>
>> Trygve Reenskaug      mailto: [hidden email]
>> Morgedalsvn. 5A       http://folk.uio.no/trygver
>> N-0378 Oslo           Tel: (+47) 22 49 57 27
>> Norway
>>  
>
>
> --
>
> Trygve Reenskaug      mailto: [hidden email]
> Morgedalsvn. 5A       http://folk.uio.no/trygver
> N-0378 Oslo           Tel: (+47) 22 49 57 27
> Norway
>  
> ------------------------------------------------------------------------
>
>
>  


Reply | Threaded
Open this post in threaded view
|

Re: Compiling a role name into a message to self

Tom Phoenix
In reply to this post by Trygve
On 11/21/07, Trygve Reenskaug <[hidden email]> wrote:
>
>  No response on my first SOS.

Does that mean you didn't see my response?

    http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-November/122779.html

Cheers!

--Tom Phoenix