[comp.lang.forth] postfix

boris@prodigal.psych.rochester.edu (Me) (08/09/90)

In article <9008081745.AA29723@ucbvax.Berkeley.EDU> Mitch Bradley <wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV> writes:

>exists in the language and is essentially unavoidable.  Some language
>theoretician once proved that a language needs at least 1 "look-ahead"
>construct.

I'm curious why.  Can you give an intuitive version of the proof, or
failing that a reference?

>The Right Way is to have exactly one method for creating a colon
>definition and a general purpose postfix method for giving something
>a name.  e.g.
>
>{ HERE . }  " FOO"  DEF   instead of   : FOO  HERE  .  ;
>VAR         " V1"   DEF   instead of   VARIABLE V
>5 CONSTANT  " C1"   DEF   instead of   5 CONSTANT C1

I've always liked this idea.  Is there a language (other than
PostScript and HP-28s calculatorese) that does things this way?

Bng
Boris Goldowsky                        The only way you'll end up in a corner
                                        Is by walking in too straight of a li
boris@prodigal.psych.rochester.edu        --Claudia Schmidt                 n
boris%prodigal@uordbv.BITNET                                                e

wmb@MITCH.ENG.SUN.COM (08/10/90)

> > Some language
> > theoretician once proved that a language needs at least 1 "look-ahead"
> > construct.

> I'm curious why.  Can you give an intuitive version of the proof, or
> failing that a reference?

How about a plausibility argument?

a) You need a look ahead construct
in order to distinguish between normal operations and "literals".
By literal, I mean something like a string, where instead of executing
it, you collect it verbatim and do something with it later.

Here's an example from English:

	The phrase hello world has 11 letters.      (incorrect)

	The phrase "hello world" has 11 letters.    (correct)

You need the quotes to denote that you are talking about the phrase itself,
rather than including the meaning of the phrase as part of the meaning of
the sentence.

b) I believe that I can design a language with EXACTLY 1 look ahead
   construct.  I will attempt to demonstrate this by showing how you
   could map all of Forth's look-ahead constructs into just one.  The
   one I will choose is  "   (collect a string).

	"  ( -- string )			! The look-ahead word
		Look ahead in the input stream and collect
		a string delimited by a closing "  Push that
		string on the stack (the issue of how a string
		is represented on the stack is irrelevant to
		this discussion)

	COMPILE-STRING  ( string -- cfa )
		Create an execution token "cfa" which can be later used with
		EXECUTE , so that later execution has the same effect as
		if the contents of "string" were interpreted.

	DEFINE  ( cfa string -- )
		Associate the name "string" with the execution token "cfa"

	LOOKUP  ( string -- cfa )
		Returns the execution token "cfa" named by "string"

	NUMBER  ( string -- n )
		Return the number "n" represented by the string "string"

	MAYBE   ( cfa flag -- )
		Execute cfa if flag is true.

	CHOOSE  ( cfa1 cfa2 flag -- )
		Execute cfa1 if flag is true, or cfa2 otherwise.

I think this pretty much does it.  Some embellishments are needed for
various things, but those can all be done in postfix ways.


> I've always liked this idea.  Is there a language (other than
> PostScript and HP-28s calculatorese) that does things this way?

REPTIL comes to mind.  REPTIL is a (sort of) Forth-like language
developed by Israel Urieli and described at length in a series of
papers presented at Rochester Forth conferences over the years.  The
papers are published in the proceedings of same.

Mitch