[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

postfix



>From the replies, I realized that I am mixing two different ideas:
concatenative programming and postfix syntax.

The issue here is that concatenative programming is more or less
incompatible with infix syntax.  However I don't think it is
a problem if you structure the language correctly.

On 30 Nov 2001 jmarshall@mak.com wrote:
> "S. Alexander Jacobson" <alex@shop.com> writes:
> > What about postfix?
> You can rearrange its indentation and whitespace, but you can't
> rearrange it to read left to right.

Perhaps you can. Or perhaps you prefer a concatenative prefix language.
You could do a transformation to prefix that included reversing arguments.
So:
concat
  [2 3 4 5]
  map
    [add 1]
    range 1 10

would be the same as postfix.:
[2 3 4 5] [add 1] 1 10 range map concat

Guy Steele thinks the former is easier to read.  The conversions
are trivial.  The point is that in either case you eliminate variables and
scoping issues.

> A particular language that uses postfix syntax (for instance Forth)
> may not have `variables' in the sense of arguments, but they *do* have
> `variables' in the sense of `identifiers' that map to a meaning.

Yes, but that is hugely different.  Without variables you don't have to
figure out scoping rules.  variables are just lists of stack operations.
When you use them, they apply to whatever is on top of the stack then.

> > So you immediately eliminate the large class of errors that come from
> > destructive updates to shared data structures without having to jump
> > through all the hoops that functional programming languages force on you.
>
> Postfix syntax doesn't do squat for aliasing.  The syntax of the
> language is unrelated to whether there are primitives within the
> language that support destructive updates.

Perhaps there is a distinction here between postfix and concatenative.
The point is that all functions are presumed to consume all their
arguments.  So there is no sharing, period.  For example executing
"head [1 2 3 4]" leaves 1 on the stack. The rest of the list is gone.
If you want to use the rest of the list, you want something like:

"delist [1 2 3 4]" which results in the stack "1 [2 3 4]"

Henry Baker did a version of this concept in lisp at some point, but
it seemed hard to read/understand in that format.

> > You also eliminate all errors associated with variable scope because you
> > get rid of variables.
>
> You also eliminate lexical scoping.  The baby has been thrown out with
> the bath water.

Using the stack means you get the locality of lexical scope without the
confusion.

> In addition, you *increase* the ease at which wrong number of argument
> errors are generated and propagated.

This is indeed an added problem, but I think there are various automated
type-checking schemes that can verify that those mistakes don't happen
at runtime.

> Don't get me wrong, I love my HP calculator, but a postfix language
> isn't a panacea.

I think I am not talking about postfix, but rather a purely destructive
language (that therefore doesn't need variables).  You could implement
the language prefix as well (and I think Guy is right, it looks better).

But I don't think you could implement such a language infix.

-Alex-

___________________________________________________________________
S. Alexander Jacobson			i2x Media
1-917-783-0889 voice			1-212-697-1427 fax