if then else

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 - 3 | Next >

if then else

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Good evening,

I can’t find an ‘else’ so how does one construct an if-then-else? Should
it really be done in two words:

: word1 if ... ; then ... ;
: word2 stuff-before word1 stuff-after ;

Thanks,
Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Parent Message unknown Re: if then else

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Jason Kemp <jason.kemp@...>:

>... " Good evening,
>... "
>... " I can’t find an ‘else’ so how does one construct
>... " an if-then-else? Should
>... " it really be done in two words:
>... "
>... " : word1 if ... ; then ... ;
>... " : word2 stuff-before word1 stuff-after ;
>... "
>... " Thanks,
>... " Jason
>... "
>... "
Nick here:  I always get confused by logic so I made up
a simple example.  Word1 does nothing but observe
whether n was 1 or else 2, then (whatever the number)
word2 adds 10: is this if-else-then?

 ( n) : word1 dup ( nn) -1

"If" jumps to the next "then" while " ; " returns to
the
calling word (word2).  One can concatenate " ; " for
instance word1 has 3 alternatives - the final one drops
any numbers other than 1 or 2, and replaces them by 3,
so the only results from word2 are 11, 12 and 13.

  I think one can also omit intermediate " ; " (but
not the final return ;) to make this crude one-word
form of if-else-then

  ( n)  : word1 dup ( nn) -1 + drop ( n) 0if ( n,f)
drop
1 ( no ";" ) then ( n/1) dup ( nn/11) -2 + drop 2 then
(
still no ";") 3 + ;

   Results from this word1 are 0>>3 1>>4 2>>5  n>>n+3.
The recognized n 1 and 2 can be manipulated - but,
without their own individual ";" to call each one back
home they will be further processed while passing
along the chain of ifs to the final common return ";".

Caritas,
Nick

   

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Nick,

( n)  : word1 dup ( nn) -1 + drop ( n) 0if ( n,f) drop 1 ( no ";" ) then ( n/1) dup ( nn/11) -2 + drop 2 then (still no ";") 3 + ;


But each ‘then’ has to match an ‘if’ so this can’t work can it?

‘if’ and ‘then’ are macros.  ‘if’ compiles a JZ into the dictionary,
leaving space for the offset byte (you know—the byte telling it how far
to jump) and using ‘here’ to put the next free dictionary address on the
stack (ie into eax).  ‘then’ first copies the top of return stack to
list (don’t know why—for later optimisation?) Next it calculates the
offset to this location (H) (ie where the ‘then’ is) from the ‘if’ (the
next location after which is held in eax) and places this offset in the
empty byte following the ‘JZ’ of the ‘if’.

It's just as hard to explain it as I’m sure it is to read!

 From the kernel:-
then:
        mov [list], esp ;esp is byte pointer to TOR
        mov edx, [H]    ;H is the pointer to the end of the code space
        sub edx, eax     ; edx := edx-eax offset for if to jump
        mov [eax-1], dl  ; location to store offset (directly after jz)
        DROP             ; location after if
        ret


 From Block 24
 macro
 if 74h 2, here ;
 comment: jz, flags set, max 127 bytes, leave address

So I can create an ‘else’ macro as:
: else eb 2, here swap then ;

eb is dark green, then is cyan.  eb is the opcode for JMP rel8. This can
then be used:

: test w1 if w2 else w3 then w4 ;

w1 goes first, then either w2 is executed and then w4 or w3 and then
w4.  This seems to work, but there must be a reason why Mr Moore didn't
put an ‘else’ in.  Any idea why?  Is it optimisation?  Does having to
use two lines make it more readable or better factored?

Jason



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Parent Message unknown Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Jason Kemp <jason.kemp@...>:

>... " Hi Nick,
>... "
>... " ( n)  : word1 dup ( nn) -1 + drop ( n) 0if (
>... " n,f) drop 1 ( no ";" ) then ( n/1) dup ( nn/11)
>... " -2 + drop 2 then (still no ";") 3 + ;
>... "
>... "
>... " But each ‘then’ has to match an ‘if’ so this
>... " can’t work can it?
>... "

Nick here:  Sorry for the typo, of course it can't
work!
 Here (I hope) is a correct version: this one should
act
to yield 1 if
n is 1 or else yield 2 if n is 2, then for any other
value of n it should yield n+3.

    ( n)  : word1 dup ( nn) -1 + drop ( n) 0if ( n,f)
drop -2 ( no ";" ) then ( n/1) dup ( nn/11) -2 + drop
0if -1 (still no ";") then  3 + ;

    But is this what is meant by "if-else-then" ?

    Thank you for the explanation of how "if" works.  I
shall try to digest it then post an example with 2
words as you suggest - this time with a " ; " between
"if" and "then" (if;else;then ?).

     Also, re 'then' has to match an 'if', there are 2
'then' matched with only 1 'if' in the definition of '
+! ' (on block 26 of CF05).  I have noticed such multi
concatenations elsewhere in CF.  Perhaps the structure
of 'if' in CF is different from previous Forth,
allowing one to build multi choice equivalents  of
'if;else;then' or 'case' ?


Caritas,

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Jason Kemp <jason.kemp@...>:

>... " Hi Nick,
>... "
>... " [snip]  ‘then’ first copies the
>... " top of return stack to
>... " list (don’t know why—for later optimisation?)
>...  

Nick here:  The optimization is explained in Karig's
Commentary (see
Compiler, and follow the leads to 'list' 'then' and
'semi').  Inclusion of TORS in 'list' by 'then' allows
'semicolon ;' to make an 'if' recursive by jumping back
on its calling word.  

>... " [snip]
>... " So I can create an ‘else’ macro as:
>... " : else eb 2, here swap then ;
>... "
>... " eb is dark green, then is cyan.  eb is the
>... " opcode for JMP rel8. This can
>... " then be used:
>... "
>... " : test w1 if w2 else w3 then w4 ;
>... "
>... " w1 goes first, then either w2 is executed and
>... " then w4 or w3 and then
>... " w4.  This seems to work, but there must be a
>... " reason why Mr Moore didn't
>... " put an ‘else’ in.  Any idea why?  ...
>... "
>... " Jason
>... "
 
Nick here:  Perhaps the word 'Jump' (together with the
ability to concatenate if;then;then; makes other multi
choice constructions unnecessary?  Karig explains
'jump' also.  I have not tried it, but it would seem to
act like 'case' ie choose one out of any number of
options by setting n.

   Anyway, for what it's worth, here is my two-word
if;else;then.  Word1 returns 1 if n=1, else 2 if n=2,
else 3 for any other value of n.  Then word2 adds 10
so, whatever the value of n, the bottom line is limited
to 11, 12 or 13.  

  ( n)  : word1  dup -1 + ( n n/0) drop 0if ( n=1)
; then ( n) dup -2 + drop 0if ( n=2) ; then ( n) drop 3
;

  ( n)  : word2  word1 10 + ;  

Caritas,

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Nick

> Nick here:  Sorry for the typo, of course it can't
> work!
>  Here (I hope) is a correct version: this one should
> act
> to yield 1 if
> n is 1 or else yield 2 if n is 2, then for any other
> value of n it should yield n+3.
>
>     ( n)  : word1 dup ( nn) -1 + drop ( n) 0if ( n,f)
> drop -2 ( no ";" ) then ( n/1) dup ( nn/11) -2 + drop
> 0if -1 (still no ";") then  3 + ;
>
>     But is this what is meant by "if-else-then" ?
Not quite what I mean.  This is so hard to explain and I have spent
literally hours over this.  I have never given ‘if’s any thought in
other languages.  Who says colorForth is simple?

in this example
   : w1 if w2 then w3 ;
the if the ZF is not set then w2 will execute and then w3 will too.  If
the ZF is set then only w3 goes.

in this one:
   : w1 if w2 ; then w3 ;
the if the ZF is not set then only w2 will execute.  If the ZF is set
then only w3.  This is what I think of as an if-then-else (or
if-else-then in Forths) but you cannot include any more after this as
anything you put between the ‘w3’ and the ‘;’ will only execute if the
ZF is set.

However, if you want to execute w4 directly after as part of w1 then you
have to do this:
   : w1 if w2 w4 ; then w3 w4 ;
which duplicates some code.

or this:
   : w5 if w2 ; then w3 ;
   : w1 w5 w4 ;
Which takes two words.

So I thought of this:
   : w1 if w2 else w3 then w4 ;
the if the ZF is not set then only w2 will execute.  If the ZF is set
then only w3.  w4 will execute afterwards regardless. Pygmy has an
‘else’ that, I think, works like this.

Now I am beginning to see that colorForth encourages all sorts of
‘factoring’ and also that you are not restricted by rules.  Yours is an
example of this in that what happens if the first ‘if’ executes (ie. if
ZF=1) changes what the second ‘if’ does to achieve the effect you want.  
I'm looking for something that makes the two parts (what goes when ZF
set and what when it isn’t) independent and then allows more to follow
within the same word definition.  My colorForth understanding is so
limited that I have no examples and I am unable to contrive something
satisfactory either.  I'm ignoring recursion at the moment too.

What I wonder now though is if I will find, with more experience, that
there is no need for an if-else-then construct;  I suspect there might
be no ‘else’ because Mr Moore has no need for it.  Also you have not
needed it yet.
>     Thank you for the explanation of how "if" works.  I
> shall try to digest it then post an example with 2
> words as you suggest - this time with a " ; " betwee.
> "if" and "then" (if;else;then ?).
>  
Ah, but what I mean is an if-else-then that doesn’t require ‘;’ to
prevent execution of the following items.
   : w1 if w2 else w3 then w4 ;
reduces the pair of definitions required if there is no ‘else’
   : w5 if w2 ; then w3 ;
   : w1 w5 w4 ;
>      Also, re 'then' has to match an 'if', there are 2
> 'then' matched with only 1 'if' in the definition of '
> +! ' (on block 26 of CF05).  I have noticed such multi
> concatenations elsewhere in CF.  Perhaps the structure
> of 'if' in CF is different from previous Forth,
> allowing one to build multi choice equivalents  of
> 'if;else;then' or 'case' ?
>  
That example actually has two ‘if’s which are nested.  It is easy to
overlook the first one.  I think that the way ‘if’ works precludes
having multiple ‘then’s: the action is to jump to the ‘then’ if the ZF
is set, so having two ‘then’s means you can only jump to the first, the
second being ignored.  I haven't looked at how the compiler works yet,
but I would expect that this would cause a stack underflow during
compilation, yet a simple example I tried compiled fine.


Still perplexed,
Jason



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Jason,

This discussion has given me the confidence to improve
some recent "iffing" in my program.  But I must confess
that, as a humble hobbyist, I cannot follow any
language
in the abstract (not even my native Anglisch; after
70 years I still cannot tell what parts are grammar and
what parts are syntax). The same with CF: I know what I
want my hardware to do, I look for suitable words in
CF, like if and then, and test them with simple
numerical examples until the combine to do what I want.


"Simple" can be deceptive, as you say, and take hours;
but there are no hidden paths and everything (that I
can understand) lies nicely to hand. The factoring that
you mention is part of the charm: using 2 stubby little
words instead of 1 big portmanteau word (like the
difference between modern Enlish and classical Greek).

What I really need to understand (in a practical way) is
all those words in CF05 re USB, or some   Tim /Ray
/Howerd blocks on networking.  I don't mind floppy r/w
being slow; but I have 2 computers, each running CF,
but neither will read the other's floppy.  
However, they can read each other's memory cards. At
present I transfer the one floppy to USB stick (via
Linux dd) then take this stick over to the other
computer and there build a new floppy (again via Linux
dd) which the other computer can then r/w and boot
from. I guess CF can r/w/boot from USB in principle
(and from net also?), but I fear that I might not have
enough hours /days /months /years ahead of me to work
out how.  I am always happy pass on my own little stock
of tips and annotations (eg, on PCI). If any CForther
here has some tips on USBoot, then I would be glad to
ponder them; else I shall just have to hope that my new
floppy drive lasts.  

Caritas,

Nick

Quoting Jason Kemp <jason.kemp@...>:

>... " Hi Nick
>... " [snip]
>... " Not quite what I mean.  This is so hard to
>... " explain and I have spent
>... " literally hours over this.  I have never given
>... " ‘if’s any thought in
>... " other languages.  Who says colorForth is
>... " simple?
>... "
>... " [snip]
>... " Now I am beginning to see that colorForth
>... " encourages all sorts of
>... " ‘factoring’ and also that you are not restricted
>... " by rules.  Yours is an
>... " example of this in that what happens if the
>... " first ‘if’ executes (ie. if
>... " ZF=1) changes what the second ‘if’ does to
>... " achieve the effect you want.  
>... " I'm looking for something that makes the two
>... " parts (what goes when ZF
>... " set and what when it isn’t) independent and then
>... " allows more to follow
>... " within the same word definition.  My colorForth
>... " understanding is so
>... " limited that I have no examples and I am unable
>... " to contrive something
>... " satisfactory either.  I'm ignoring recursion at
>... " the moment too.
>... "
>... " What I wonder now though is if I will find, with
>... " more experience, that
>... " there is no need for an if-else-then construct;
>... " I suspect there might
>... " be no ‘else’ because Mr Moore has no need for
>... " it.  Also you have not
>... " needed it yet.
>... " > [snip]   I think that the way
>... " ‘if’ works precludes
>... " having multiple ‘then’s: the action is to jump
>... " to the ‘then’ if the ZF
>... " is set, so having two ‘then’s means you can only
>... " jump to the first, the
>... " second being ignored.  I haven't looked at how
>... " the compiler works yet,
>... " but I would expect that this would cause a stack
>... " underflow during
>... " compilation, yet a simple example I tried
>... " compiled fine.
>... "
>... "
>... " Still perplexed,
>... " Jason
>... "
>... "
>... "

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by Albert van der Horst :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 28, 2008 at 06:21:13PM +0000, Jason Kemp wrote:
<SNIP>

> >
> >    But is this what is meant by "if-else-then" ?
> Not quite what I mean.  This is so hard to explain and I have spent
> literally hours over this.  I have never given ?if?s any thought in
> other languages.  Who says colorForth is simple?
>
> in this example
>   : w1 if w2 then w3 ;
> the if the ZF is not set then w2 will execute and then w3 will too.  If
> the ZF is set then only w3 goes.

Chuck Moore wanted to have if a meaning by itself. The same for
then.
Read this if you will:
   conditional: w2  then-goon-with w3 ready
>
> in this one:
>   : w1 if w2 ; then w3 ;

Now this makes sense too
     conditional: w2 ready  maybe-goon-here: w3 ready

>
>
> Still perplexed,
> Jason
>

--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by John R. Strohm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

A simpler way would be to reprogram "then" to read "endif"

: testproc w1 if w2 endif w3 ;

: testproc2 w1 if w2 else w3 endif w4 ;

----- Original Message -----
From: "Albert van der Horst" <albert@...>
To: <colorforth@...>
Sent: Sunday, November 02, 2008 7:47 AM
Subject: Re: [colorforth] if then else - but why is there no ?else? in
colorForth?


> On Tue, Oct 28, 2008 at 06:21:13PM +0000, Jason Kemp wrote:
> <SNIP>
>> >
>> >    But is this what is meant by "if-else-then" ?
>> Not quite what I mean.  This is so hard to explain and I have spent
>> literally hours over this.  I have never given ?if?s any thought in
>> other languages.  Who says colorForth is simple?
>>
>> in this example
>>   : w1 if w2 then w3 ;
>> the if the ZF is not set then w2 will execute and then w3 will too.  If
>> the ZF is set then only w3 goes.
>
> Chuck Moore wanted to have if a meaning by itself. The same for
> then.
> Read this if you will:
>   conditional: w2  then-goon-with w3 ready
>>
>> in this one:
>>   : w1 if w2 ; then w3 ;
>
> Now this makes sense too
>     conditional: w2 ready  maybe-goon-here: w3 ready
>
>>
>>
>> Still perplexed,
>> Jason
>>
>
> --
> Albert van der Horst, UTRECHT,THE NETHERLANDS
> Economic growth -- like all pyramid schemes -- ultimately falters.
> albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: colorforth-unsubscribe@...
> For additional commands, e-mail: colorforth-help@...
> Main web page - http://www.colorforth.com
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Evening Nick,

> This discussion has given me the confidence to improve
> some recent "iffing" in my program.  But I must confess
> that, as a humble hobbyist, I cannot follow any
> language
> in the abstract (not even my native Anglisch; after
> 70 years I still cannot tell what parts are grammar and
> what parts are syntax). The same with CF: I know what I
> want my hardware to do, I look for suitable words in
> CF, like if and then, and test them with simple
> numerical examples until the combine to do what I want.
>  
I had to look up Anglisch; not heard of that before.  Hmm, seems to have
been a large influence on English.  Sorry: ignorant Brit.  I've just
looked up syntax too, and I didn’t realise that that was separate from
‘grammar’.  I wonder if when old home computers used to say “syntax
error” that perhaps “grammar error” might have been more accurate sometimes.
> "Simple" can be deceptive, as you say, and take hours;
> but there are no hidden paths and everything (that I
> can understand) lies nicely to hand. The factoring that
> you mention is part of the charm: using 2 stubby little
> words instead of 1 big portmanteau word (like the
> difference between modern Enlish and classical Greek).
>  
But still why is that better?  But I know: I'll just have to wait until
I find a real example to see.

> What I really need to understand (in a practical way) is
> all those words in CF05 re USB, or some   Tim /Ray
> /Howerd blocks on networking.  I don't mind floppy r/w
> being slow; but I have 2 computers, each running CF,
> but neither will read the other's floppy.  
> However, they can read each other's memory cards. At
> present I transfer the one floppy to USB stick (via
> Linux dd) then take this stick over to the other
> computer and there build a new floppy (again via Linux
> dd) which the other computer can then r/w and boot
> from. I guess CF can r/w/boot from USB in principle
> (and from net also?), but I fear that I might not have
> enough hours /days /months /years ahead of me to work
> out how.  I am always happy pass on my own little stock
> of tips and annotations (eg, on PCI). If any CForther
> here has some tips on USBoot, then I would be glad to
> ponder them; else I shall just have to hope that my new
> floppy drive lasts.  
>  
That’s what I want too.  I'm working through the CF05 USB blocks, but
I'm having to work out each word in each definition, which takes one to
other blocks and the kernel (as I know you know) so it’s very slow, but
exceedingly good fun.  In fact I’ve not had such fun with computers
since the days of ZX81s and BBCs  (I saw a Jupiter Ace in a shop once,
but just thought it was really weird back then).

Anyway, I’d just got up to ‘fr’ and so had to get to grips with ‘if
then’, but as this isn’t for money I want to understand it fully—there’s
no boss leaning over me saying ‘just get it to work’.

Floppy is perfect for me as I'm only using 6 cylinders, but my current
CF computer is on its last legs and the others don’t boot this version
of CF (2.0a is too slow to boot for me native) so I would like to get a
USB floppy booting.  I know this sounds crazy, but floppies are cheap
and easy to file away.  If I could get that far (which I know will
require changing the boot sector) then I think USB flash booting would
be little change.

There’s much to find out as it seems there are three protocol
implementations and half a dozen command sets and it’s all quite
nebulous to me at present.

Is USBoot something in CF2.0a?

Jason



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Albert,
> Chuck Moore wanted to have if a meaning by itself. The same for
> then.
> Read this if you will:
>    conditional: w2  then-goon-with w3 ready
>  
> Now this makes sense too
>      conditional: w2 ready  maybe-goon-here: w3 ready
>  
I’m sorry but I don’t understand the “meaning by itself”. Am I missing
the point or is it simple? Do you mean he specifically didn’t want an
‘else’?

Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi John,

John R. Strohm said the following on 02/11/2008 14:05:
> A simpler way would be to reprogram "then" to read "endif"
That had me for a while. The way ‘if’ and ‘then’ are used in Forth seems
so wrong when you’re used to other languages. A newbie expects the
condition between ‘if’ and ‘then’ and the conditional action after the
‘then’. The stack messes up this idea. The Forth ‘if’ is actually the
‘if’ and ‘then’ of other languages combined.

Another way could be using brackets: ‘if(’ and ‘)’. That might be easier
to read.

OK. I’m sick of if now.

Jason



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by John R. Strohm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hm.

Maybe what you want is "IF(", ")ELSE(", and ")ENDIF".

"(" and ")" are already in use, for stack comments, and I'd rather not overload
")".

----- Original Message -----
From: "Jason Kemp" <jason.kemp@...>
To: <colorforth@...>
Sent: Monday, November 03, 2008 11:01 AM
Subject: Re: [colorforth] if then else - but why is there no ?else? in
colorForth?


> Hi John,
>
> John R. Strohm said the following on 02/11/2008 14:05:
>> A simpler way would be to reprogram "then" to read "endif"
> That had me for a while. The way ‘if’ and ‘then’ are used in Forth seems so
> wrong when you’re used to other languages. A newbie expects the condition
> between ‘if’ and ‘then’ and the conditional action after the ‘then’. The stack
> messes up this idea. The Forth ‘if’ is actually the ‘if’ and ‘then’ of other
> languages combined.
>
> Another way could be using brackets: ‘if(’ and ‘)’. That might be easier to
> read.
>
> OK. I’m sick of if now.
>
> Jason
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: colorforth-unsubscribe@...
> For additional commands, e-mail: colorforth-help@...
> Main web page - http://www.colorforth.com
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ?else? in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Albert van der Horst
<albert@...>:

>... "
>... " Chuck Moore wanted to have if a meaning by
>... " itself. The same for
>... " then.
>... " --
>... " Albert van der Horst, UTRECHT,THE NETHERLANDS

Nick here:  Interesting to learn that "if" without
'then' might not be a 'syntax error'.  I've just tried
it.  

         n : testif  -1 + -if -1 ;

That gave -1 for all n.  I tried if then without ';'

     n  : testifthen  -1 +  -if -1  then 1 ;  

That gave 1 if n was positive, but for 0 or negative n
it gave -1 1 together.  Thus acting like 'if ... then
...' ?

Finally tried 'if then' with a ';' to separate them

    n  :  testif;then  -1 +  -if -1 ; then 1 ;  

The semicolon appeared also to separate the two cases,
yielding 1 for n positive or -1 for 0 and negative n.
Thus acting like "if ... else ... " ?        

Caritas,

Nick


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Jason Kemp <jason.kemp@...>:

>... " exceedingly good fun.  In fact I’ve not had such
>... " fun with computers
>... " since the days of ZX81s
>... "

Nick here:  I think one of the brilliant early bloggers
- Jecel Assumpcao @ Merlintec.com (alas, no longer with
us)- would have agreed with you: Jecel said the best
Forth was on the Z80 and since then it has been
downhill all the way.  IMHO Colorforth is Z80 Forth for
the 21st century - EVEN MORE FUN on even faster CPUs.  



>... " 'if then’, but as this isn’t for money I want to
>... " understand it fully—there’s
>... " no boss leaning over me saying ‘just get it to
>... " work’.
>... "

Nick here:  So the Good Book advises: 'Go to the ant,
thou sluggard, consider her ways and be wise; she needs
no boss to stand over her'


>... " Floppy is perfect for me as I'm only using 6
>... " cylinders, but my current
>... " CF computer is on its last legs and the others
>... " don’t boot this version
>... " of CF (2.0a is too slow to boot for me native)
>... "  
>... " Jason
>... "

Nick here:  CF2 is only slow because it has been set to
load a full 80 cylinders (you can hear them clicking
away on the floppy).  But the core kernel and source
blocks occupy only the first 10 cyls.  Neither of my
PCs
will boot CF2 native kernel on a floppy (not CF's fault
but crappy hardware and local EMF pollution) so I've
resorted to two expedients:

1.  Boot Josh's CF05 then rd/wr the first 10 cyls of
CF2A in high RAM with:
 
       4000 block 0 10 reads (/writes)  stop  

That way I can quickly examine CF2a and compare it with
CF05 (to which it is closely related). Some words from
CF2a have been transferred to my CF05 application with
copy and /'n/alt' keys.

2.  The zip package of CF2a for Windows has a program
CF2.EXE which is a bootloader for the native CF2A
blocks.  As Ray has pointed out, CF2.EXE will TRY TO
boot any file that is named OkadWork.cf.  So I put my
native blocks of CF01 or CF05 or whatever I am working
on into the Windows folder, and rename the one that I
want to work on 'OkadWork.cf'.  Then I hit CF2.EXE with
the mouse pointer, and lo-and-behold! up pops CF01 or
CF05 or whatever.cf, in a Windows screen.  Smoooth!

Caritas,

Nick      

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by David Goehrig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 4, 2008, at 8:46 AM, Nick Maroudas wrote:

> [snip]
> Nick here:  CF2 is only slow because it has been set to
> load a full 80 cylinders (you can hear them clicking
> away on the floppy).  But the core kernel and source
> blocks occupy only the first 10 cyls.  Neither of my
> PCs
> will boot CF2 native kernel on a floppy (not CF's fault
> but crappy hardware and local EMF pollution) so I've
> resorted to two expedients:
>
> 1.  Boot Josh's CF05 then rd/wr the first 10 cyls of
> CF2A in high RAM with:
>
>   [snip]

>
> 2.  The zip package of CF2a for Windows has a program
> CF2.EXE which is a bootloader for the native CF2A
> blocks.
[snip]

A 3rd option for anyone who would like the more native experience, but  
need to run other software all day is run CF2a in virtualbox

http://www.virtualbox.org/wiki/Downloads

It works pretty well for experimenting with the system, although I've  
noticed it tends to choke on saving the image back to disk.   I  
haven't had time to figure out why, but that's how this cookie crumbles.



---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting Jason Kemp <jason.kemp@...>:

>... " Evening Nick,
>... "
>... " Is USBoot something in CF2.0a?
>... "
>... " Jason
>... "


Nick  here:  USB and USBoot stuff in CF2a

block 62 boot assembler
      64 USB assembler
      66 boot sector
      68 USBoot
      72 flash files
      82 USB macro (like block 20 in CF05)
      84 USB flash (like CF05 22)
      86 USB command

This seems to continue Chuck's progress from CF01 to
CF05, moving boot code from assembler

to Forth blocks; and from CF05 TO CF2A, moving from
floppy boot to flash boot. The fact that

the new bootloader CF2.EXE can boot all 3 versions into
Windows (CF01, CF05 and CF2a)

indicates a structural similarity: it would be nice to
have a dissassembly of the native

CF2a kernel from OkadWork.cf, to compare with the
dissassemblies that Karig, Tim and Terry

made for CF01, and Josh's dissassembly of CF05.  The
dissassembly of CF2a will be short: a

dump of blocks 0 to 17 reveals great swathes of zeros,
presumably where cpu code has been

shifted to Forth source code.

Caritas,

Nick  

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Nick Maroudas-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Quoting David Goehrig <dave@...>:

>... " [snip]
>... "
>... " A 3rd option for anyone who would like the more
>... " native experience, but  
>... " need to run other software all day is run CF2a
>... " in virtualbox
>... "
>... " http://www.virtualbox.org/wiki/Downloads
>... "
>... " It works pretty well for experimenting with the
>... " system, although I've  
>... " noticed it tends to choke on saving the image
>... " back to disk.   I  
>... " haven't had time to figure out why, but that's
>... " how this cookie crumbles.
>... "

Nick here:  Thanks for the citation to Virtualbox; it
sounds useful for Linux.  But
I turned to native CF for speed and direct control of
PC hardware.  Simulators give you the experience, as
Mark Slicker pointed out, but not the speed.  The
latest CF2a running in Windows RAM might give more
speed, but one is barred (presumably by the MS OS) from
direct access to hardware (see OkadWork User Guide).

Hence my longterm interest in booting native CF - until
an equally fast Forth turns up for Linux. The people at
MicroProcessor Engineering have generously posted their
fastest MPE Forth free for Linux, but I havn;t had time
to benchmark it vs native CF.

Caritas,

NickM

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Z80 Forth (was: if then else - but why is there no ‘else’ in colorForth?)

by Jecel Assumpcao Jr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Maroudas wrote on Tue,  4 Nov 2008 15:46:18 +0200

> Quoting Jason Kemp:
>
> >... " exceedingly good fun.  In fact I've not had such
> >... " fun with computers
> >... " since the days of ZX81s
> >... "
>
> Nick here:  I think one of the brilliant early bloggers
> - Jecel Assumpcao @ Merlintec.com (alas, no longer with
> us)-

I'm still here :-)

But I have never really blogged.

> would have agreed with you: Jecel said the best
> Forth was on the Z80 and since then it has been
> downhill all the way.  IMHO Colorforth is Z80 Forth for
> the 21st century - EVEN MORE FUN on even faster CPUs.  

I don't think I would ever say that Z80 Forths were the best. The best
book I have ever read about Forth implementation (Loeliger, Threaded
Interpretive Languages, Byte Books, 0-07-038360-x) was dedicated to the
Z80 but that is not the same thing. The 68000 was a far nicer processor
for Forth, for example.

What I do agree with is that Colorforth is great fun, though I am
interested observer (I program in Smalltalk) rather than an active
participant in the community.

-- Jecel


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com


Re: if then else - but why is there no ‘else’ in colorForth?

by Jason Kemp-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi David,

Does this work with the previous editions of CF?  I imagine it should
work with anything that can boot.

I can see great value in this for experimenting, particularly as it has
virtual USB controllers.

Jason

David Goehrig said the following on 04/11/2008 17:30:
> A 3rd option for anyone who would like the more native experience, but
> need to run other software all day is run CF2a in virtualbox
>
> http://www.virtualbox.org/wiki/Downloads
>
> It works pretty well for experimenting with the system, although I've
> noticed it tends to choke on saving the image back to disk.   I
> haven't had time to figure out why, but that's how this cookie crumbles.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@...
For additional commands, e-mail: colorforth-help@...
Main web page - http://www.colorforth.com

< Prev | 1 - 2 - 3 | Next >