Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
27
Task/Array-length/Forth/array-length-1.fth
Normal file
27
Task/Array-length/Forth/array-length-1.fth
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
: STRING, ( caddr len -- ) \ Allocate space & compile string into memory
|
||||
HERE OVER CHAR+ ALLOT PLACE ;
|
||||
|
||||
: " ( -- ) [CHAR] " PARSE STRING, ; \ Parse input to " and compile to memory
|
||||
|
||||
\ Array delimiter words
|
||||
: { ALIGN 0 C, ; \ Compile 0 byte start/end of array
|
||||
: } ALIGN 0 C, ;
|
||||
|
||||
\ String array words
|
||||
: {NEXT} ( str -- next_str) \ Iterate to next string
|
||||
COUNT + ;
|
||||
|
||||
: {NTH} ( n array_addr -- str) \ Returns address of the Nth item in the array
|
||||
SWAP 0 DO {NEXT} LOOP ;
|
||||
|
||||
: {LEN} ( array_addr -- n) \ count strings in the array
|
||||
0 >R \ Counter on Rstack
|
||||
{NEXT}
|
||||
BEGIN
|
||||
DUP C@ \ Fetch length byte
|
||||
WHILE \ While true
|
||||
R> 1+ >R \ Inc. counter
|
||||
{NEXT}
|
||||
REPEAT
|
||||
DROP
|
||||
R> ; \ return counter to data stack
|
||||
1
Task/Array-length/Forth/array-length-2.fth
Normal file
1
Task/Array-length/Forth/array-length-2.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
CREATE Q { " Apples" " Oranges" } q {len} . 2 ok
|
||||
Loading…
Add table
Add a link
Reference in a new issue