On 16/03/2024 4:15 pm, dxf wrote:
On 16/03/2024 5:37 am, Paul Rubin wrote:
...
At least in gforth, VARIABLEs are initialized to 0. That seems like a >>>> good thing for implementations to do ingeneral.
That's something I'd do for VALUEs should I move to omit the numeric
prefix at creation. By automatically initializing VALUEs with 0, I can
pretend - if only to myself - that VALUEs are different from VARIABLEs.
... and CONSTANTs
I don't know who first coined 'VALUE' but based on his 1984 handout:
https://pastebin.com/p5P5EVTm
Martin Tracy seems as good a suspect as any. Tracy promoted IS as
the mechanism for changing a VALUE. Why he didn't use TO is unclear.
Perhaps it was to avoid clashing with Bartholdi's TO which was aimed
squarely at VARIABLEs. Rather than Bartholdi's radical changing of
VARIABLE, Tracy introduced a new data type - that of VALUE.
Unlike Bartholdi's VARIABLE, Tracy's new data type had aspects more
in common with CONSTANT - namely supplying a value at definition time:
n VALUE name
And it's quite misleading.
Agree. It would be better to have VALUE ( "name" -- )
And the initial value for "name" should be 0.
But, "VALUE" does not imply a new *data type*, but only a new
type/subtype of named Forth definitions, if you like.
[...]
AFAICS Tracy made the correct choice of introducing a new data type
rather than trying to redefine VARIABLE. Where he got it wrong IMO,
is in making VALUE appear as a CONSTANT - something ANS went along
with, presumably as it was by then 'common practice'. While I don't
see Standard Forth changing it as it would literally break every
program written using VALUE, I have fewer such qualms besides which
a mistake is a mistake.
Another name only can be introduced.
Ruvim
On 2024-03-19 04:48, dxf wrote:
On 16/03/2024 4:15 pm, dxf wrote:
On 16/03/2024 5:37 am, Paul Rubin wrote:
...
At least in gforth, VARIABLEs are initialized to 0. That seems like a >>>> good thing for implementations to do ingeneral.
That's something I'd do for VALUEs should I move to omit the numeric
prefix at creation. By automatically initializing VALUEs with 0, I can >>> pretend - if only to myself - that VALUEs are different from VARIABLEs.
... and CONSTANTs
I don't know who first coined 'VALUE' but based on his 1984 handout:
https://pastebin.com/p5P5EVTm
Martin Tracy seems as good a suspect as any. Tracy promoted IS as
the mechanism for changing a VALUE. Why he didn't use TO is unclear.
Perhaps it was to avoid clashing with Bartholdi's TO which was aimed
squarely at VARIABLEs. Rather than Bartholdi's radical changing of
VARIABLE, Tracy introduced a new data type - that of VALUE.
Unlike Bartholdi's VARIABLE, Tracy's new data type had aspects more
in common with CONSTANT - namely supplying a value at definition time:
n VALUE name
And it's quite misleading.
Agree. It would be better to have VALUE ( "name" -- )
And the initial value for "name" should be 0.
But, "VALUE" does not imply a new *data type*, but only a new
type/subtype of named Forth definitions, if you like.
[...]
AFAICS Tracy made the correct choice of introducing a new data type
rather than trying to redefine VARIABLE. Where he got it wrong IMO,
is in making VALUE appear as a CONSTANT - something ANS went along
with, presumably as it was by then 'common practice'. While I don't
see Standard Forth changing it as it would literally break every
program written using VALUE, I have fewer such qualms besides which
a mistake is a mistake.
Another name only can be introduced.
I think introducing an overloaded parsing word TO was a much bigger
mistake.
Much simpler is eliminating TO by exploiting Forth's
redefinition rules ...
https://pastebin.com/p5P5EVTm...
Rather than Bartholdi's radical changing of
VARIABLE, Tracy introduced a new data type - that of VALUE.
Unlike Bartholdi's VARIABLE, Tracy's new data type had aspects more
in common with CONSTANT - namely supplying a value at definition time:
n VALUE name
I think introducing an overloaded parsing word TO was a much bigger...
mistake.
TO can't be
postponed in ANS Forth.
What do you do when your application restarts? The values assigned at creation-time have likely changed.
On 20/03/2024 4:21 am, Anton Ertl wrote:
Unfortunately, Forth-79 standardized VARIABLE to create an
uninitialized variable, and later standards kept this mistake. So now
I always have to write something like
VARIABLE name n name !
What do you do when your application restarts? The values assigned at >creation-time have likely changed.
dxf wrote:
[..]
What do you do when your application restarts? The values assigned at
creation-time have likely changed.
That's a good point I've not seen addressed yet. In my current circuit simulation work, I need variables that either reset to their 'boot' value (e.g., 0), or retain the value computed during the last run (e.g. variables updated by other applications|computing nodes started by my own program).
I think introducing an overloaded parsing word TO was a much bigger
mistake. Much simpler is eliminating TO by exploiting Forth's
redefinition rules:
: val create , ;
111 val a
: a! a ! ; \ Replaces TO a
: a+! a +! ; \ Replaces +TO a
: a a @ ; \ Hide the CREATEd a
a 222 a! a 99 a+! a ( -- 111 222 321 ) .s
The CREATEd value a can be hidden in a separate wordlist if you dislike
the order of the definitions.
Postponing versions can be defined for compilation. TO can't be
postponed in ANS Forth.
Incidentally I'd like to see VALUEs extended much as described in N J Nelson's papers in EuroForth 2020 and 2022
http://www.euroforth.org/ef20/papers/nelson.pdf
http://www.euroforth.org/ef22/papers/nelson-values.pdf
but that still uses a parsing operator -> instead of TO
dxf <dxforth@gmail.com> writes:
On 20/03/2024 4:21 am, Anton Ertl wrote:
Unfortunately, Forth-79 standardized VARIABLE to create an
uninitialized variable, and later standards kept this mistake. So now
I always have to write something like
VARIABLE name n name !
What do you do when your application restarts? The values assigned at >>creation-time have likely changed.
I typically restart the application by restarting the Forth system and >reloading the application source.
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
Gerry Jackson wrote:
I think introducing an overloaded parsing word TO was a much bigger
mistake.
Water under the bridge, anyhow
- in most tokenized systems a compiled TO doesn't parse
(but interpreted yes, so it's not a real win)
- more unfortunate imo is that locals and global values
are also written with TO
Much simpler is eliminating TO by exploiting Forth's
redefinition rules ...
With VALUEs "as ojects" (with 3 data actions, using Rosen's wording)
you don't need to redefine TO with every new value type: F.ex. in
MinForth complex number values are defined thru:
: ZVALUE \ ( r: r1 r2 <name> -- ) double fp-number value
['] z@ ['] z! ['] z+ _(value) f, f, ;
That's all. Ready to use. No need to adapt TO or +TO.
With VALUE DVALUE FVALUE LOCAL DLOCAL FLOCAL etc. and message FROM TO
+TO CLR etc. I devoted a chapter of tforth (1993, nowadays probably present in iforth) to explain that these are in effect considered messages to objects.
Polymorphism is the excuse to use the same message for different objects. That is the only reason I came to terms with this.
The value-something is an object and to-etc are messages.
On 2024-03-19 21:21, Anton Ertl wrote:
Unfortunately, Forth-79 standardized VARIABLE to create an
uninitialized variable, and later standards kept this mistake. So now
I always have to write something like
VARIABLE name n name !
And most likely n is 0, isn't it?
Therefore, a requirement to systems to
initialize variables by zero simplifies programs.
If an uninitialized variable is required by a program, it can be defined >using "BUFFER:".
To define a variable with an explicitly specified initial value, why not >create a word like this:
: in-var ( n "name" -- )
variable
latest-name name> execute !
;
Another observation. "DEFER" (which is similar to "VALUE") does not
accept an initial value. Well, in most use cases this value yet unknown.
But a non-zero initial value is also unknown for many use cases of
"VALUE" and "VARIABLE".
If the value is not yet known, the deferred word must not be called.
So a good initialization value produces an exception. In Gforth it
produces a warning for now, but after >15 years of warnings, it's time
to actually produce an exception.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (3 / 13) |
Uptime: | 43:00:26 |
Calls: | 6,709 |
Calls today: | 2 |
Files: | 12,243 |
Messages: | 5,353,935 |