gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] two alternative definitions for <string.fs>


From: Bernd Paysan
Subject: Re: [gforth] two alternative definitions for <string.fs>
Date: Fri, 08 Nov 2013 18:18:26 +0100
User-agent: KMail/4.10.5 (Linux/3.7.10-1.16-desktop; KDE/4.10.5; x86_64; ; )

Am Freitag, 8. November 2013, 17:39:08 schrieb Marcos Cruz:
> 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
> 
>   : address@hidden  ( 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.

Yes, makes sense.  I've added a few more of those checks to the git HEAD 
version, so that $+! on an uninitialized string works, too.  Or $del/$ins.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

Attachment: signature.asc
Description: This is a digitally signed message part.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]