I find the dynamic strings provided by <string.fs> very useful, but
sometimes it's annoying or inconvenient to make sure the variables have
been initialized before fetching them. That's why I usually redefine two
of the provided words:

  \ Safer alternatives for words of Gforth's string.fs
  warnings @  warnings off
  : $@len  ( a -- len )
    \ Return the length of a dynamic string variable,
    \ even if it's not initialized.
    @ dup if  @  then
    ;
  : $@  ( a -- ca len )
    \ Return the content of a dynamic string variable,
    \ even if it's not initialized.
    @ dup if  dup cell+ swap @  else  pad swap  then 
    ;
  warnings !

Just thought the idea could be useful for someone.

-- 
Marcos Cruz
http://programandala.net

Reply via email to