Sujet : Re: value-flavoured structures
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 04. Oct 2024, 04:00:35
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <46519f18ba08e088b940ee517313db099de97788@i2pn2.org>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
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# ;