Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 94:25:51 |
Calls: | 290 |
Calls today: | 1 |
Files: | 904 |
Messages: | 76,378 |
Ruvim <ruvim.pinka@gmail.com> writes:
Such dialects, or better said, descendants, already exist.
For example: Factor, StrongForth.
Probably useless for embedded applications.Agreed.
Factor is sort of a Lisp dialect that is garbage collected, I think. So maybe
not great for embedded. StrongForth, I thought, was like regular Forth but >with a type system. That shouldn't be a problem unless there are other >issues. Ada is strongly typed, and C++ is sort-of-strongly typed, and both >are used in embedded apps all the time.
Rust has unsafe modules but I don't remember Ada having them. Ada does
have an Unchecked_Conversion function but I don't know where this is
really needed or how well specified it is in the language standard.
A strong type system is not a problem for embedded applications, as long
as there is a means to defeat the type system.
Ada was designed with this in mind, making distinction between safe and unsafe modules. Remember that c++ was an afterthought after c that was
not well designed in the first place.
Strong typing can be annoying. I remember wasting time passing a filename
to function that expected a `const char *` or something, and it is
by no means obvious what you have to do, so you are lured into casting.
A lot of people do not understand that casting is a means to defeat the
type system, so that you loose the advantages.
On 2024-10-04 22:04, Anton Ertl wrote:
Ruvim <ruvim.pinka@gmail.com> writes:
On 2024-10-04 15:52, Anton Ertl wrote:...
It can be defined: Gforth has SET-TO
I wonder why a kind of "TO" is not used to set this field/property, and
*maybe* a kind of "ACTION-OF" to get this property.
Interesting idea. Maybe in some future version.
What advantages do you see in *using* the to-based setters?
int: noop
comp: default-name>comp
string: named>string
link: named>link ok
The lack of flexibility of standard TO has not deterred them from
using that.
This statement contains the logical fallacy "Survivorship bias" [1].
There are different use cases. In some use cases the discussed
flexibility is not needed, in other — it is needed.
For example, it could be a defining word "val" that is used as "val x"
and creates the getter "x" and the setter "set-x".
Such a word "val" can be defined like this:
[undefined] name> [if]
: name> ( nt -- xt )
name>interpret dup if exit then
drop [: -14 throw ;]
;
[then]
: val ( "name" -- )
create 0 , [: does> @ ;] execute
0. <# latest-name name>string holds s" set-" holds #>
['] : execute-parsing
latest-name name> >body lit,
postpone ! postpone ;
;
\ Re "latest-name" see [2]
\ test
t{ val x -> }t
t{ x -> 0 }t
t{ 3 set-x -> }t
t{ x -> 3 }t
\ Let's redefine the setter "set-x"
: set-x ( u -- )
dup 10 u> abort" too big value for x"
set-x
;
t{ 4 set-x x -> 4 }t
t{ 11 ' set-x catch 2drop x -> 4 }t
Could you show how to implement that in Gforth when the to-based setter
"to x" is used?
NB: the solution must not change the original "x", it must redefine "x".
The difference is that the new definition *can* be in a different word
list, in which case both definitions (old and new) can be used depending
on the context.
This shows that some people don't like the to-based approach.
Does it? Are they using getters and setters instead? No.
How do you know this?
For example, it's impossible to change n to d, n to r, or vice versa,
without changing all the code accessing those fields.
Similar for the word `to` — `to` applies to the words created with
`value`, `fvalue`, `2value`. But the source code around `to foo` (and
`foo`) depends on the kind of `foo`, so the kind of `foo` cannot be
changed without changing the source code around where it is used.
Higher level (more polymorphic) source code in Forth is possible when
all values are boxed [1]
I don't know what compiler you use, but my values and locals
are certainly not boxed. TO et al (+TO *TO := *= ++ += *+) will
inspect their type and generate the appropriate machine code
without me having to change the source code if I change the type.
Introduce variant data-types, as some BASIC compilers have,
you really have to invent a new 'Forthish' dialect. Probably
useless for embedded applications.
I said about the source code *around* the usage places.
Such dialects, or better said, descendants, already exist.
For example: Factor, StrongForth.
Probably useless for embedded applications.Agreed.
Is it not the endless comparison between forth and other languages
that invites all these 'innovations'?
1. From the lexical point of view, "to foo" and "set-foo" are almost the >same. "to foo" can even be considered a separate fancy word with a
space in its name.
3. "set-foo" can be easily redefined (for example, if you want to check
the assigned value to prevent some bugs in advance).
"to foo" *cannot* be redefined. Although, one can redefine "to" to check
its argument and have a special action when its argument is "foo" — this
is very cumbersome.
4. "set-foo" can be accessed using qualified names, such as
mymodule::set-foo or mymodule( set-foo )
A variant like "to mymodule::foo" could work,
a variant like "to mymodule( set-foo )" cannot work.
Bottom line: I don't see any advantages in *using* a to-based setter
over a separate setter.
On 2024-10-04 15:52, Anton Ertl wrote:...
It can be defined: Gforth has SET-TO
I wonder why a kind of "TO" is not used to set this field/property, and >*maybe* a kind of "ACTION-OF" to get this property.
However, lots of Forth programmers have defined VALUEs, and barely any
have defined getters and setters.
Do you mean that this is due to some advantages in *using*?
I think, this is because `VALUE` (and co.) is a very old technique that
is provided out of the box by many systems.
In contrast, to use
separate getters and setters you need to create your own tool to define
them.
The discussions have been aboyt
values vs. variables, not about values vs. getters and setters.
This shows that some people don't like the to-based approach.
I seen that some implementers provide "value" and "to" only for third
party programs and don't use them themselves.
On 4/10/2024 2:32 am, Anton Ertl wrote:
minforth@gmx.net (minforth) writes:
Introduce variant data-types, as some BASIC compilers have,
you really have to invent a new 'Forthish' dialect. Probably
useless for embedded applications.
Joerg Voelker works on embedded projects and found value-flavoured
fields useful already in 2017
<https://wiki.forth-ev.de/doku.php/events:tagung-2017:forth-in-grossen-projekten>.Nick Nelson works on (bigger) embedded projects and also finds
value-flavoured fields useful. See
<http://www.euroforth.org/ef22/papers/nelson-values.pdf>
<http://www.euroforth.org/ef22/papers/nelson-values-slides.pdf>
<https://www.youtube.com/watch?v=UHcLqxG7UI4>
I wonder whether classic structures fit the forth paradigm? Whether by >chance or lack of schooling they seem to have passed me by.
According to Moore:
"Forth is definitions. If you have a lot of small definitions you are
writing Forth."
Structures claim to avoid 'magic numbers'. But are numbers 'magic' when
the name of the definition containing them identifies what they are?
Example:
\ copy memory data (ofs) to target (a)
: SET.S ( a ofs -- ) dbuf + count rot >target place ;
: SET.W ( a ofs -- ) dbuf + @ swap >target ! ;
: SET.B ( a ofs -- ) dbuf + c@ swap >target c! ;
hex
: THIL ( -- ) 1C2 5B set.s ; \ hilight video
: TNOR ( -- ) 1C8 61 set.s ; \ normal video
: TEOL ( -- ) 1BC 69 set.s ; \ clear to end-of-line
: TINS ( -- ) 1AE 6F set.s ; \ insert line
: TDEL ( -- ) 1B4 75 set.s ; \ delete line
: TCR ( -- ) 168 7B set.w ; \ # cols rows
decimal
\ modify data
: SET$ ( ofs size -- )
over .str change? if cr ." : " get$ rot !str end 2drop ;
: SET# ( ofs -- )
dup @byt . change? if ." : " get# swap !byt end drop ;
: ?DEL ( -- ) cr ." DELETE LINE command: " $75 5 set$ ;
: ?INS ( -- ) cr ." INSERT LINE command: " $6F 5 set$ ;
: ?EOL ( -- ) cr ." ERASE TO EOL command: " $69 5 set$ ;
: ?BOLD ( -- ) cr ." BOLD VIDEO command: " $5B 5 set$ ;
: ?NORM ( -- ) cr ." NORMAL VIDEO command: " $61 5 set$ ;
: ?ROWS ( -- ) cr ." Number of screen rows: " $7C set# ;
: ?COLS ( -- ) cr ." Number of screen cols: " $7B set# ;