3 ms·
> Out of the box, out of the standard, there no real structured data type ala records, there's no strings, there's no modular coding construct. All of those can
by veltas 4y ago
> Out of the box, out of the standard, there no real structured data type ala records, there's no strings, there's no modular coding construct. All of those can be added, but that's the trick. They have to be added.
There are structures, strings, etc in standard forth. And if you're using an older forth without structures here is a structures library in 2 lines:
: +FIELD OVER + SWAP CREATE , DOES> @ + ;
: FIELD: ALIGNED 1 CELLS +FIELD ;
Usage:
\ Shape struct
0
FIELD: SHAPE.WIDTH
FIELD: SHAPE.HEIGHT
FIELD: SHAPE.AREA
CONSTANT %SHAPE
\ Example shape
CREATE SQUARE
1 , 1 , 1 ,
\ Get height
SQUARE SHAPE.HEIGHT ?
\ Get area
SQUARE SHAPE.AREA ?
\ Set width
2 SQUARE SHAPE.WIDTH !
2 SQUARE SHAPE.AREA !