A mathematical foundation of reflexion?
Wed, 12 Jan 2000 22:21:26 +0100
Laurent Martelli wrote:
> >>>>> "John" == John Carter <firstname.lastname@example.org> writes:
> John> I think Joy lays bare that special something about Forth and
> John> Postscript. The homomorphism between syntatic concatenation
> John> and functional composition. If that homomorphism exists, then
> John> reasoning about the program becomes very much easier, and if
> John> reasoning becomes easier it is much easier to write bug free
> John> programs.
> I'm not so sure. I think that the absence of named parameters can make
> it difficult to understand programs.
> Laurent Martelli
Not if used correctly. The following articles refer to Forth, a
prototipical programming environment based on anonymous parameters
(stack); it's an interactive interpreter/compiler: you type a
definition and immediatly the environment compile it and you can
test it. The cited articles report the ideas of Charles Moore, the
inventor of Forth, a perfectionist and minimalist. If you are
familiar with programs written in Forth, probably you complain
of a bad programming style, like long word(procedure) definitions.
In reading these definitions you often lost the stack picture. But
this is *not* the intended use of the language (at least from his
Forth is highly factored code. I don't know anything else to say
except that Forth is definitions. If you have a lot of small
definitions you are writing Forth. In order to write a lot of
small definitions you have to have a stack.
You factor. You factor, you factor, you factor and you throw away
everything that isn't being used, that isn't justified.
["Factor definitions until most definitions are one or two lines."
What is a definition? Well classically a definition was colon
something, and words, and end of definition somewhere.
: some ~~~ ;
I always tried to explain this in the sense of this [a word] is an
abbreviation, whatever this string of words you have here that you
use frequently you have here you give it a name and you can use it
more conveniently. But its not exactly an abbreviation because it
can have a parameter perhaps or two. And that is a problem with
programmers, perhaps a problem with all programmers; too many
input parameters to a routine. Look at some 'C' programs and it
gets ludicrous. Everything in the program is passed through the
calling sequence and that is dumb.
A Forth word should not have more than one or two arguments.
This stack which people have so much trouble manipulating should
never be more than three or four deep. [so avoiding troubles to
interpret a stack picture]
A truly interesting reading is also:
Stacks are great (for Forth) so use them. Chuck has said "Don't
use locals." You have a stack for data, this is Forth, locals are
for a whole different picture.
[remember that a colon definition is a procedure difinition]
As a metric I did some analysis of code examples Chuck has
provided. The numbers I find most interesting is that the length
of the average colon definition is 44 characters. The length of
the longest colon definition was 70 characters. This is a sign
that he has factored, factored, factored. How big are the average
definitions in your code? Smaller definitions are easier to code,
easier to test, etc.