quick Forth question
Richard A. Smith
richard at laptop.org
Mon Jan 25 12:29:43 EST 2010
On 01/25/2010 10:59 AM, Daniel Drake wrote:
> Can anyone help me with a tiny Forth script? Can never quite get my
> head around the language.
> I'm trying to set up an if-else based on whether a mfg tag exists (or
> whether writing a mfg tag succeeded or not)
> I'm trying:
> add-tag ak 0 catch if 2drop ." Laptop already activated" cr then
add-tag is look ahead word (so it can parse your argument) which doesn't
work like you expect and catch needs a reference to what you are trying
to run. Plus if the tag does not exist then add-tag is going to reboot.
I'm not sure exactly how to make it work using add-tag.
I'll have to ask Mitch.
> But, if ak already exists, it simply says:
> Tagname already exists
> ...rather than executing my conditional code.
> Also experimented with find-tag but couldn't figure it out.
find-tag is much better. find-tag leaves success or failure on the stack
and if its true then has the string value of the tag.
The following will do what you want
" ak" find-tag if 2drop ." Laptop already activated" cr then
Richard A. Smith <richard at laptop.org>
One Laptop per Child
More information about the Devel