gforth
[Top][All Lists]
Advanced

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

Re: [gforth] If then else in interpreted mode


From: Marcos Cruz
Subject: Re: [gforth] If then else in interpreted mode
Date: Thu, 2 May 2013 00:57:56 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

En/Je/On 2013-05-01 23:15, John Allsup escribió / skribis / wrote :

Hi John, welcome!

As you show, execution tokens (on the stack, in lists or any other data
structure), can be used to make decisions based on calculations. That's
a powerful feature of Forth.

>     : jif 0 = if 0 else 1 then ;

A simpler alternative:

        : jyf 0<> abs ;

Usually in Forth a calculation can be used instead of a condition.

> so as to have two nicely named words: jiffy and jemmy that do the
> work of interpret time conditional execution.

You can use also '[if]', '[else]' and '[then]'. They work quite
differently than 'if', 'else' and 'then', but they provide the same
syntax.

> As to taking this much further, we hit a place where it is really
> nice to have more stacks (since you ideally want an operator stack
> to do the picking from rather than the data stack 

There are several Forth extra stack tools you can use. I think they are
not hard to find on the web. Anyway the simpler implementations need
only a few lines of code.

Cheers,

Marcos

-- 
http://programandala.net



reply via email to

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