Hi 4tH-ers!
I've been busy! Well, I seem to bump into more and more situations where changing individual characters is required. And that's annoying. uBasic/4tH has a small heap (16K) for strings and that means that if I have to compose a new string from two halves and a single character - especially if that action is embedded in a loop - the interpreter quickly runs out of space due to fragmentation.
Now, I've always denied the world access to individual characters, because it is dangerous in such an environment. But this weekend I got a brainwave - what if I treated the problem just like PEEK(). That one allows safe access to a string by truncating the access boundaries of that string.
I still didn't like access to transient strings, but by only allowing string variables, the risk could be reduced. So I designed this command:
: exec_poke ( --)
get_var, @ string@ get_exp get, dup rot < over 0< 0= and
get_exp swap >r -rot r> if [] c! ;then E.BADSUBS throw
; \ check variable and index
It gets a variable, fetches it's value - and then checks if it's a string. If so, it checks the boundaries to see if they're within limits. If so, the ASCII value is poked in that location. If not, you get an appropriate error message.
Due to this design it was quite easy to test:
- Does it bomb when the variable is not a variable;
- Does it bomb when the variable does not contain a string;
- Does it bomb when the position is invalid.
And it does. I already converted all programs (sauf un) that used the _Poke() function - and all is well. I included the changed documentation and highlight files (KDE and GTK). Code in SVN.
Hans Bezemer