Re: The IMMEDIATE mess
- From: "J Thomas" <jethomas5@xxxxxxxxx>
- Date: 30 Aug 2006 19:35:31 -0700
Neal Bridges wrote:
"David N. Williams" <williams@xxxxxxxxx> wrote in message
news:R8jJg.4016$tU.3783@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
J Thomas wrote:[snip]
> Even though the tools are there in any system which provides the Tools
> Extension wordset.
What about Wil Baden's COND ... THENS, et al.? As far as I
remember, they're not portably implementable because there's no
CS-DEPTH, or some such.
COND/THENS doesn't CS-DEPTH. They assume the data stack is the
control-flow stack, and COND leaves a sentinel value on it that THENS
terminates on.
THENS also assumes that nothing else leaves anything on the data stack
while the construction is going on.
Normally you can have that.
..... IF [ 3 ] ... IF ... THEN .... [ drop ] THEN ....
But you can't do that with THENS .
You could get almost as good a result with a variable.
variable #conds
: COND 0 #conds ! ; immediate
: IF 1 #conds +! postpone IF ; immediate
: THENS #conds @ 0 do postpone THEN loop ; immediate
This isn't as flexible because you can't nest THENS . I tend to think
that a word with nested THENS is too big, but still that's something
you can do with Wil's THENS that you can't do with mine. Mine ought to
be portable, though.
You could make Wil's version more portable with a little change.
: COND 0 ; immediate
: IF postpone IF 48813 ; immediate
: THEN drop postpone THEN ; immediate
: THENS
begin postpone THEN dup 48813 = while repeat drop ; immediate
I think this ought to work whether or not the controlflow stack uses
the data stack, but it's more complicated. It will give an undefined
result if you leave an extra 48813 on the data stack inside the THENS
code during compilation. And if you leave anything else it will
terminate early.
I expect Wil didn't make it more portable because he didn't care about
Forths that didn't use the data stack for the controlflow stack.
.
- Follow-Ups:
- Re: The IMMEDIATE mess
- From: Neal Bridges
- Re: The IMMEDIATE mess
- References:
- The IMMEDIATE mess
- From: J Thomas
- Re: The IMMEDIATE mess
- From: Andrew Haley
- Re: The IMMEDIATE mess
- From: J Thomas
- Re: The IMMEDIATE mess
- From: Andrew Haley
- Re: The IMMEDIATE mess
- From: J Thomas
- Re: The IMMEDIATE mess
- From: Elizabeth D Rather
- Re: The IMMEDIATE mess
- From: J Thomas
- Re: The IMMEDIATE mess
- From: Elizabeth D Rather
- Re: The IMMEDIATE mess
- From: J Thomas
- Re: The IMMEDIATE mess
- From: David N. Williams
- Re: The IMMEDIATE mess
- From: Neal Bridges
- The IMMEDIATE mess
- Prev by Date: Re: RfD - SYNONYM
- Next by Date: Re: The IMMEDIATE mess
- Previous by thread: Re: The IMMEDIATE mess
- Next by thread: Re: The IMMEDIATE mess
- Index(es):