vineri, 5 iunie 2015, 17:31:01 UTC+3, Alex McDonald a scris:
> on 05/06/2015 07:23:22, Raimond Dragomir wrote:
> >> I'd rather see you argue why you have this opinion, based on some
> >> experience. Packaging your opinion as "Forth philosophy" doesn't really
> >> help.
> >
> > I have this opinion based on my personal experience with Forth. If I
> > like something in Forth I say it, if I don't like something else I
> > also say it. I don't repeat anything from anyone else's opinions or
> > what I read here or on internet. And I don't feel the need to excuse
> > myself every two or three words with "IMO" and such things.
> > If what I say really helps someone, I don't know.
> >
>
> OK, but I asked you to explain, not to indulge in an unnecessary personal
> justification.
>
> You said (from the bit snipped earlier)
>
> <quote>
> I never mentioned classes. Only (simple) structures. I name "object" an
> entity wich is materialized in memory in some quantity. A variable is an
> object. An address or an offset isn't an object. So, a structure is a
> "type" which defines some offsets, that's all. But it's against the Forth
> philosophy to declare "types" or worse, to bind "types" to objects.
> </quote>
>
> A variable is an object, but an address isn't an object? Since a variable
> is a named address, I don't understand what you mean.
>
A variable is not a named address, it is a quantity in memory. It is
"allocated". I don't know how to explain it more... Lets take a forth
example:
create X
variable Y ( or create Y 1 cells allot )
X is an address. It is just an attribute of something (we don't know
what something is because we don't know it's size in the first place.
The size is zero, so the "object" doesn't exists). The name is another
attribute. Ok, the address and the name are related, associated, but
the object doesn't exist.
Y is an object. It exists because it occupies 4 bytes in memory. It's
address is just it's attribute. It's name is another attribute.
Types are attributes. They are associated with objects, that's the purpose
of types. A type that is only declared and not associated with any object
is just useless. And a type is not an address, it is at least a quantity
(size) and can possibly define some other behavioral aspects of the object.
Structures which defines named offsets are types, because they specify
a quantity (the offset is not an address, it's a size). They don't produce
any effects if they are not "applied" to some object.
Now, for the forth "philosophy": you (not you, a generic programmer) are
supposed to apply manually types over "generic" objects - in fact raw
memory. The compiler is not supposed to know that a variable is x bytes
or some field of an object is y bytes. That's why we need to @ or c@ or !
explicitly. You are allowed to allocate memory (creating "objects") but
all the "types" are in your head, the compiler has no clue about that.
For being such an ignorant compiler, it cannot provide anything else for
an "object" but it's address. In fact it doesn't know anything else: it
maps the name with the address, you give the name it gives the address
But the address it provides is not an object. You may say it is, because
in the end there must be something at that address... Well, it may be
or it may be not:
create x
create y
create z 1 cells allot
It is possible in forth isn't it? x y and z cannot be objects because they
occupy the same pysical space at the same time... Pretty impossible
with our laws of nature :)
> How does a collection of offsets in a structure make the structure a
> type? Type checking is where the compiler (although this might be done at
> run time) says "You can't do that operation Y on this type X". Structures
> and structure variables/offsets in Forth don't do that, and there's no
> "binding to objects" going on.
>
> This isn't about "Forth philosophy" (whatever that is) at all. I'm not
> attacking you here, I'm looking to understand.
That's why we can't have real types (in fact real objects) in forth, because
that's against it's philosophy - against it's "nature".
People wanted something more like a C variable with a clear "type", so
we have VALUE in forth. I don't know - for example - after many years of
forth usage why (or when) I should use VALUEs. It's a matter of personal
preference? It saves me a @ that's all? The result is that I never used
VALUEs.
Speaking of that, let's think, if the forth had had only VALUEs from the start,
how would it look like? How about byte variables (probably CVALUEs) how
about structures, how about arrays? arrays of structures? Do you think it
would have been even possible? Without a rigid syntax like C?
That's what I'm thinking about when I speak about the forth philosophy.