Fantastic!

Thank you very much for the detailed reply.

The bit on the right-to-left leaving the receiver on the top of the stack makes perfect sense in Smalltalk idioms, for we talk to objects when we code.

cordially,




---- On Fri, 19 Jan 2024 13:44:26 -0500 Jecel Assumpcao Jr <jecel@merlintec.com> wrote ---


gettimothy wrote on Fri, 19 Jan 2024 10:27:45 -0500
> Thanks for the replies on how to begin to think about a Context. vs Environments.
>
> Next up in the SICP study are the terms. applicative order evaluation where the
> operands are evaluated first and  normal order evaluation, the operands are not
> evaluated until their values are needed.

We have both in Smalltalk using blocks. Evaluated arguments:

z foo: (3+4) bar: (z/2)

Non evaluated arguments (#foo:bar: must explicitly send #value to the
arguments when it wants them to finally be evaluated):

z foo: [3+4] bar: [z/2]

Note that this is something that has changed quite a bit from
Smalltalk-72 to -76 to -80. In Smalltalk-72 the code would look like

z foo (3+4) bar (z/2)

in both cases and you would have to look at the code in z's class to
tell which one you are dealing with. The colon character would fetch
evaluated arguments while the open colon character the unevaluated
arguments. As the language evolved we passed most of the control for
this from the receiver to the sender, though the receiver still has to
do the right thing.

> I vaguely remember Eliot relying on Squeak strict Right to Left (or is it Left to Right)
> evaluation rule in an email from some years ago.

We have had both left-to-right and right-to-left Smalltalks. It is a bit
like the choice between starting array indexes at 0 or at 1. One option
is more newbie friendly while the other makes more sense at the
implementation level.

People read code from left to right so evaluating the arguments in that
order leads to fewer surprises. But doing it right to left has the
advantage of leaving the first argument, which is the receiver to which
we want to send the message, always at the top of the stack. Evaluating
left to right leaves the receiver buried under the arguments and forces
you to have separate "send", "send1", "send2", etc bytecodes. A right to
left Smalltalk can get by with a single "send" bytecode.

Squeak evaluates left to right and uses 1 as the first array index. Self
evaluates right to left and uses 0 as the first array index.

But note that I consider code that gives different results when
evaluated in different orders badly written, if not exactly buggy. Such
code will be a problem if you want to have a more parallel Smalltalk.

-- Jecel