Closed wboeke closed 2 months ago
Hello Mr. Boeke, thank you for taking interest in eForth.
Hello Chochain, Thanks for the reply. I tried your lessons420 and it works perfectly. However I'm not very smart, so I need a simple example. Here is a demo for an array:
\ forth:
\ : inc cells ;
\ eforth:
: inc 2* ;
create arr 10 inc allot
136 arr !
arr @ .
137 arr 2 inc + !
arr 2 inc + @ .
Thus there are 2 inc's, one for standard forth, one for eforth. The assignment of 136 works okay, but the assignment of 137 to the 2nd array member causes a crash in eforth. In your example you are using a normal variable. Maybe that is needed in eforth?
Ah, dynamic array is at fault again. Since it's no more a continuous block of bytes, accessing an array element needs a new word.
So, try whether these work (in fact, that's how I do string look up in lessens420 itself, too).
create arr 10 allot \ this gets you 10 elements
see arr \ shows you the array with 10 zeros
136 arr ! \ treat arr as a regular variable (or array with only 1 element)
see arr \ shows 136 taking the arr[0]
137 arr 2 array! \ this should fill the arr[2]
see arr
arr 2 array@ \ this gets you the arr[2] back
Unfortunately, eForth is still pretty fragile against these memory exception. It crashes. By setting CC_DEBUG to 1 in config.h can catch some of them. In the mean time, thank you very much for your feedback and do enjoy if you can. Chochain
BTW, I like the 'th' used by 4tH, a dialect of Forth, as the array access word, i.e. 137 arr 2 th ! and arr 2 th @. I might do just that.
Thanks, it works!
Hello, Something goes wrong in the following code:
The value of the 2nd 'here' should be 8 bigger than the value of the 1st 'here'. But the difference appears to be only 1. Could you have a look at this? Maybe it's a good idea to give some demo programs illustrating more advanced forth code, like create ... does> ... and array@ ? The provided test programs are nice but rather basic.