====== array ====== Statische Arrays an zu legen ist ein häufig geübter, aber im ANS Forth nicht standardisierter Vorgang. Die wohl weit verbreitete "klassische" Form ist so: : Array ( n -- ) CREATE CELLS ALLOT DOES> ( n -- addr ) SWAP CELLS + ; \ Kann so benutzt werden: \ 10 array DATA \ 1 data ! . \ 2 data ! . \ ... \ 1 data @ . \ 2 data @ . Die andere Form ist die des [[http://www.taygeta.com/fsl/docs/fsl_arrays.html|Forth Scientific Library (FSL)]]: : } ( addr n -- n-addr ) cells + ; 10 constant size create data{ size cells allot \ data{ ( -- addr ) data{ size 0 fill \ Kann so benutzt werden: \ 15 data{ 0 } ! \ 60 data{ 1 } ! \ 25 data{ 2 } ! \ \ data{ 1 } ? \ : tt cr ." I am " data{ 1 } ? ." years old!" cr ; Wobei die Vorschläge des FSL über diese simple Form hinaus dafür plädieren, auch die Größe eines Datenelementes im Header des Arrays mit abzulegen. Damit ein } immer richtig in das Array hineingreift. ---- Tags: ANS-Forth data-structures