[comp.lang.forth] Merits of Forth

lowry@src.honeywell.com (Dave Lowry) (03/22/91)

With all this discussion of the merits of Forth, I wonder if somebody
could comment on the usefulness of a language that merrily accepts
things like:

: 1 2 ;

resulting in:

1 1 + . 4 ok

Nick_Janow@mindlink.UUCP (Nick Janow) (03/22/91)

lowry@src.honeywell.com (Dave Lowry) writes:

> With all this discussion of the merits of Forth, I wonder if somebody could
> comment on the usefulness of a language that merrily accepts things like:
> 
> : 1 2 ;
> 
> resulting in:
> 
> 1 1 + . 4 ok

It means that the language is powerful and flexible.  It also means that you
don't have a huge bloated compiler that takes a long time to load, a long time
to run, crashes frequently, has "bug fixes" offered every month and _still_
doesn't manage to catch all the errors that you make "because the compiler
checks all that stuff".

It also mean that you have to learn good programming practices.  Of course, you
should do that anyways.  :)

wmb@MITCH.ENG.SUN.COM (Mitch Bradley) (03/22/91)

> With all this discussion of the merits of Forth, I wonder if somebody could
> comment on the usefulness of a language that merrily accepts things like:
>
> : 1 2 ;
>
> resulting in:
>
> 1 1 + . 4 ok

In C, you can redefine library routines to do crazy things, e.g.:

        double exp(x) double x; { return (x-1); }

but nobody does that because it is stupid.  The linker will happily use
your exp() routine in place of the one in the library.  You can also do
a fair amount of redefining in C using the preprocessor.

The ability to substitute custom versions of "standard" routines is a
valuable tool, if used with care.

The difference between Forth and other languages in this respect is not
qualitative, but rather one of degree.  The dividing line between what
is under the programmer's control and what is not is simply in a different
place.

In Forth, this dividing line is very close to one end of the spectrum;
the programmer can change nearly everything if he wishes.  In C, the
dividing line in C is somewhat arbitrary: you can redefine things that
are invoked with function call syntax, and you cannot easily redefine
things that are invoked with infix syntax.  The choice of whether to
use infix or subroutine syntax for particular operators is pretty much
up to the whim of the language designer.  For instance, C uses infix
syntax for the logical OR operator (i|j), but FORTRAN uses subroutine
syntax (IOR(I,J)).  Basic has in infix exponentiation operator, but
C uses a subroutine.

Most languages with simple syntax (Forth, LISP, PostScript) allow you
to change most things.  That is because those languages use the same
syntax for user-supplied extensions and for built-in functions.  Languages
in the FORTRAN/Algol mold have a firewall between "first-class citizens"
(infix functions) and "second-class citizens" (subroutines).

Mitch

REEVES@SLACVM.SLAC.STANFORD.EDU (Terry Reeves) (03/22/91)

In article <1991Mar21.192611.28487@src.honeywell.com>, lowry@src.honeywell.com
(Dave Lowry) says:
>
>With all this discussion of the merits of Forth, I wonder if somebody
>could comment on the usefulness of a language that merrily accepts
>things like:
>
>: 1 2 ;
>
>resulting in:
>
>1 1 + . 4 ok

I don't get it. How does accepting : 1 2 ; make a language useless? There
are some computers that allow me to accomplish the same thing using FORTRAN.
I still find FORTRAN to be a useful language because I perform useful
calculations with it. I think the more important questions are related to
"Can I use technique x with language y in the context of situation z to
accomplish the task at hand?" It should be noted that situation z includes
things like the computer, it's operating system, language availability, what
everyone else is using (and is it important for me to use the same thing),
time to complete the task, etc. In some cases, it may be that the best
language for the task is RPG II (otherwise known as chicken scratch heaven).

                                                  Terry Reeves

Disclaimer: These are my opinions. They are not necessarily related to the
            official or unofficial policies of SLAC, Stanford University,
            the DOE, or of the U.S. government.

eaker@sunbelt.crd.ge.com (Charles E Eaker) (03/22/91)

In article <1991Mar21.192611.28487@src.honeywell.com> lowry@src.honeywell.com (Dave Lowry) writes:
>With all this discussion of the merits of Forth, I wonder if somebody
>could comment on the usefulness of a language that merrily accepts
>things like:
>
>: 1 2 ;
>
>resulting in:
>
>1 1 + . 4 ok

You need the language to tell you that : 1 2 ; is a stupid definition?
or to prevent you from stringing together lexemes into structures that
represent semantic nonsense? Every language allows any manner of
semantic blathering. Try teaching a first programming course in Pascal
or C.

Few languages can protect programmers from nonsense.  But very few even
allow you to express the kind of nonsense found in : 1 2 ; The
alternative is to introduce restrictions on what characters can appear
in a word's name and where they may appear in the name. If : 1 2 ; is
ruled out, so is : 1 1 ; Many of us would argue that the cure is
clearly worse than the disease. (Although the disease can be close
to fatal when FEED is accepted by the interpreter when the base is
hex, and the word named FEED is not, contrary to your expectations,
in the search order.)

The fact that Forth accepts kinds of nonsense that can't be expressed
in most other languages says nothing about Forth's usefulness.  It is
merely a side-effect of Forth's lack of restrictions on names.
--
Chuck Eaker / P.O. Box 8, K-1 3C12 / Schenectady, NY 12301 USA
eaker@crd.ge.com        eaker@crdgw1.UUCP       (518) 387-5964

lowry@SRC.Honeywell.COM (Dave Lowry) (03/23/91)

In article <17792@crdgw1.crd.ge.com> eaker@sunbelt.crd.ge.com (Charles E Eaker) writes:
>
>You need the language to tell you that : 1 2 ; is a stupid definition?
>or to prevent you from stringing together lexemes into structures that
>represent semantic nonsense? Every language allows any manner of
>semantic blathering. Try teaching a first programming course in Pascal
>or C.
>

First, a clarification.  "usefulness" was a bad word to use, because it
implies I think Forth is *useless*.  I do not.  I like Forth.

No, I don't need the language to tell me that : 1 2 ; is stupid.  I also
don't need my circular saw to tell me that it's stupid to stick my 
fingers in the blade, but I leave the blade guard on anyway.

Yes, all languages will allow input of semantic garbage.  The difference
with Forth is that the semantic garbage instantly becomes system garbage.
And, IMHO, it is vastly easier to shhot yourself in the head with Forth
than with any other language.  I understand the arguments about freedom
of expression (semantic, that is) = power in a language.  It just seems
to me that Forth is too "powerful" for its own good.


As always, opinions expressed are my own, and not necessarily that of my
employer.

hasan@ut-emx.uucp (David A. Hasan) (03/23/91)

In article <1991Mar22.161424.5517@src.honeywell.com> lowry@SRC.Honeywell.COM (Dave Lowry) writes:

>No, I don't need the language to tell me that : 1 2 ; is stupid.  I also
>don't need my circular saw to tell me that it's stupid to stick my 
>fingers in the blade, but I leave the blade guard on anyway.
>

This is indeed a compelling argument and no doubt the kernel
of the motivation for strong typing in other languages.
However, consider this (just to play with the analogy for a
second):  the blade guard, as useful as it is, is not the saw.
It is a feature.  If you want the protection it provides, 
make sure you get a saw that has a guard on it.

I suppose this is *exactly* what lint is supposed to provide
for C programmers (one of which I am _not_).   If I wanted to
benefit from this degree of protection in FORTH, I'd hack with
the words the read the input stream.  But just because *I*
wanted that kind of protection doesn't necessarily mean that I
should impose it on others.  

Of course, a large software organization may have very strict
guidelines which amount to constraints on the order of a blade
guard.  I suspect such an organization would not be using
FORTH in the first place.

Don't get me wrong.  I'm not against the kind of protection
you're talking about.  But a key feature of FORTH is its
extensibility.  I suppose that's my answer to the question
that started this thread (which was "what do you think of a
language which allows redefinition of "one" to be "two" as in
: 1 2 ;).  The fact that the language allows this kind
of abomination reflects a prejudice in favor of letting the
programmer define his/her own safety constraints.
-- 
 |   David A. Hasan
 |   hasan@emx.utexas.edu 

dcp@world.std.com (David C. Petty) (03/26/91)

In article <1991Mar21.192611.28487@src.honeywell.com>,
lowry@src.honeywell.com (Dave Lowry) writes:

``With all this discussion of the merits of Forth, I wonder if somebody
``could comment on the usefulness of a language that merrily accepts
``things like:

My favorite, in a system with constants that store their value in the
first cell of their bodies and in which 1 CONSTANT 1 exists at a low
level, is: 2 ' 1 >BODY !  (One of the first things I did when I was first
learning Forth.  It is fortunate that I never did much chemistry in
school, or I probably would have burned down the lab.)

Actually, I am not sure of the spirit of Mr. Lowry's posting.  Is it
meant to ridicule or revere Forth?  Personally I wouldn't program in a
language that did _not_ allow the equivalent of : DOWN  UP ;
-- 
 David C. Petty | dcp@world.std.com | ...!{uunet,bu.edu}!world!dcp /\
      POBox Two | CIS: 73607,1646   | BIX, Delphi, MCIMail: dcp   /  \
 Cambridge,  MA | `It must've been some-other-body,              /    \
02140-0001  USA |  uh uh babe it wasn't me...'                  /______\