Simple forth question - maybe simple ? 
Author Message
 Simple forth question - maybe simple ?

How can I define a word ?base, for example, to display the default
base in a useful way. If I try to establish the current

what the value stored in base!

Thanks for any suggestion !

Dima



Sat, 24 Jul 2004 13:01:11 GMT  
 Simple forth question - maybe simple ?

Quote:
> How can I define a word ?base, for example, to display the default
> base in a useful way. If I try to establish the current

> what the value stored in base!

Try

It will show 5 for base 10, 8 for base 16 etc.

You could define


Philip



Sat, 24 Jul 2004 16:11:15 GMT  
 Simple forth question - maybe simple ?

Quote:

>How can I define a word ?base, for example, to display the default
>base in a useful way. If I try to establish the current

>what the value stored in base!




Sat, 24 Jul 2004 16:48:17 GMT  
 Simple forth question - maybe simple ?
Dima Stepanchuk schrieb:

Quote:

> How can I define a word ?base, for example, to display the default
> base in a useful way. If I try to establish the current

> what the value stored in base!


--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/



Sun, 25 Jul 2004 00:30:08 GMT  
 Simple forth question - maybe simple ?


Quote:
>Dima Stepanchuk schrieb:

>> How can I define a word ?base, for example, to display the default
>> base in a useful way. If I try to establish the current

>> what the value stored in base!



This prints the largest digit in the current base.  If you do it
interactively (instead of defining a word ?BASE), you can also use:

10 1 - .

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html



Sat, 24 Jul 2004 18:31:14 GMT  
 Simple forth question - maybe simple ?
This seems to work ! Thanks !

Two things though,
1) How does it work ? What is the trick so that I understand ?

 2)If I define

I never get OK ( I use MVP-FORTH)

Quote:


> >How can I define a word ?base, for example, to display the default
> >base in a useful way. If I try to establish the current

> >what the value stored in base!





Sat, 24 Jul 2004 18:15:25 GMT  
 Simple forth question - maybe simple ?


Quote:
> This seems to work ! Thanks !

> Two things though,
> 1) How does it work ? What is the trick so that I understand ?

It makes a copy of the original base, switches base
to decimal for output then restores the base.

Quote:
>  2)If I define

> I never get OK ( I use MVP-FORTH)

You forgot to end the definition with a semicolon.
-----------
Geoff


Sat, 24 Jul 2004 23:15:32 GMT  
 Simple forth question - maybe simple ?

Quote:

>This seems to work ! Thanks !

>Two things though,
>1) How does it work ? What is the trick so that I understand ?

> 2)If I define

>I never get OK ( I use MVP-FORTH)



>> >How can I define a word ?base, for example, to display the default
>> >base in a useful way. If I try to establish the current

>> >what the value stored in base!



The base is, in essence, the number of numbers in the system. In Decimal
they go -- 0...9. The total number is 10, or 9+1. In Hex it would be 0...F ,
and the total number is F+1 = 10, in the hex number system. Octal 7+1 = 10.
That's why the base, in that number system, always came back as 10, and why
(as pointed out by others) BASE - 1 will return the highest number in that
system.

 But you really wanted the Base as a decimal number. To do this you need to
temporarily switch to the decimal system to print out the value, then back
to the original base.


You need to end a colon definition with a semicolon ( ; ). Then it should
work.

Switching the whole system from one number base to another is the classic
Forth way. Many newer forths use a prefix character to identify numbers in a
base other than decimal, as is common in other languages, and the parser
will convert them. By defining words to display a number in other bases, you
can stay in decimal base all the time. Complexity for convenience.

If you're in Hex base, it is a good idea to prefix numbers with a zero so
the parser won't  confuse them with a name, ie. 0BEEF  for BEEF.

The ok is there to put a comfortable face on forth. When the commands work
OK, forth would tell you so. Some Forths prefer to emulate the command line
of an OS by placing some character or  information at the start of the line.
In F83, the code displaying the ok is a deferred word so you can easily
change it if you wish.

Walter Rottenkolber



Sun, 25 Jul 2004 00:04:10 GMT  
 Simple forth question - maybe simple ?


Quote:
> This seems to work ! Thanks !

> Two things though,
> 1) How does it work ? What is the trick so that I understand ?

>  2)If I define

> I never get OK ( I use MVP-FORTH)

You forgot the semicolon at the end of your definiton.

Because you didn't finish the definition of MYWORD
the Forth stays in compiler mode and doesn't show 'OK'.

Maybe you should have a look at
http://www.albany.net/~hello/simple.htm

I think it is a good tutorial.

Regards, Norbert.



Sat, 24 Jul 2004 19:51:39 GMT  
 Simple forth question - maybe simple ?

Quote:

> How can I define a word ?base, for example, to display the default
> base in a useful way. If I try to establish the current

> what the value stored in base!

Well of COURSE you do!


Remember BASE is an address - so DECIMAL changes what's stored at BASE. You
have to save the value there first (DUP) then put it back (BASE !) after
switching to base 10 for the display.

Now, write a word to display the current base in base N, where N is any
integer.

Another question: what if I do

36 BASE !

If you understand what happens, you will understand a lot about how FORTH
works.

--
-drl



Wed, 28 Jul 2004 13:00:21 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Question in french (a simple question, very simple)

2. Maybe simple regsub question ...

3. Simple Hardware, Simpler FORTH

4. Simple Question seeks simple answer

5. Entry selection - maybe simple

6. Maybe a much simpler syntax

7. Simple Forth Question

8. developing in J with simple tools and simple minds

9. Very simple awk for a simple user

10. Simple courses in J for simple (ordinary) people

11. Simple courses in J for simple (ordinary) people

12. Simple courses in J for simple (ordinary) people

 

 
Powered by phpBB® Forum Software