Learning Forth, attempt #3472 
Author Message
 Learning Forth, attempt #3472

I'm not refering to the book, I'm refering to my personal venture.  :0/

It finally dawned on me the whole concept of Forth.  I was looking at a list
of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
whatever they are, and I realized what that was!  The word that is being
used at some point is taking three values from the stack, and then returning
one.

So does this only work with one data stack?  I've seen references to String
Stacks, Return Stacks, and Float Stacks... can someone explain a little?

Unfortunately my SwiftForth evaluation is way past expired, and didn't have
much time to work with it.  What is hindering me most about Forth is that I
feel the need to use variables of some sort, when in fact all data is being
stored and retrieved from a single location.

Another thing about Forth is the way I enter in the program - it follows
every step I make and processes accordingly.  I *don't want* it to do that.
I want to write the program, and then execute it.  Even BASIC was an
interpretor, but it didn't interpret a single line of code unless I wanted
it to.

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
    http://www.*-*-*.com/       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Sun, 30 Jun 2002 03:00:00 GMT  
 Learning Forth, attempt #3472


Quote:

> >It finally dawned on me the whole concept of Forth.  I was looking at a
list
> >of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
> >whatever they are, and I realized what that was!  The word that is being
> >used at some point is taking three values from the stack, and then
returning
> >one.

> Yes!

> >So does this only work with one data stack?  I've seen references to
String
> >Stacks, Return Stacks, and Float Stacks... can someone explain a little?

> Having the data on a separate stack is a lot better than putting it into
> stack frames and juggling them.  The return stack is the stack that other
> languages use -- it holds subroutine return values.  You can put things on

> junk out of the way when it's time for a subroutine return.

> Math coprocessors tend to have a hardware floating-point stack.  And
floating
> numbers are big enough to get in the way of stack operations on the data
> stack, plus different implementations make them different sizes.  (There
are
> 32-bit floats, 40-bit, 64-bit, 80-bit, etc.)  So Forths tend to use a
> separate float stack when they use floats.  They might settle for the
limited
> depth hardware float stack, or build a separate float stack in hardware.

> String stacks have never really caught on in Forth, I don't know why.
People
> have been discussing them recently.

What are the advantages of a String stack?

- Show quoted text -

Quote:

> >Unfortunately my SwiftForth evaluation is way past expired, and didn't
have
> >much time to work with it.  What is hindering me most about Forth is that
I
> >feel the need to use variables of some sort, when in fact all data is
being
> >stored and retrieved from a single location.

> You can use variables.  It's just that to do much with variables you
usually
> have to get the value out and put it on the data stack, and later when
you're
> done you put it back into the variable.  So you'll mostly use variables to
> store things that are clumsy to leave on the stack.

> >Another thing about Forth is the way I enter in the program - it follows
> >every step I make and processes accordingly.  I *don't want* it to do
that.
> >I want to write the program, and then execute it.  Even BASIC was an
> >interpretor, but it didn't interpret a single line of code unless I
wanted
> >it to.

> Most Forths let you write your program with a text editor, and load it
later.
> Many editor/forths let you choose a line or a few lines at a time to dump
into
> the interpreter.

Oh... I never thought of writing it as a text first.  Great idea!

  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----



Sun, 30 Jun 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

Quote:

>It finally dawned on me the whole concept of Forth.  I was looking at a list
>of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
>whatever they are, and I realized what that was!  The word that is being
>used at some point is taking three values from the stack, and then returning
>one.

Yes!

Quote:
>So does this only work with one data stack?  I've seen references to String
>Stacks, Return Stacks, and Float Stacks... can someone explain a little?

Having the data on a separate stack is a lot better than putting it into
stack frames and juggling them.  The return stack is the stack that other
languages use -- it holds subroutine return values.  You can put things on

junk out of the way when it's time for a subroutine return.

Math coprocessors tend to have a hardware floating-point stack.  And floating
numbers are big enough to get in the way of stack operations on the data
stack, plus different implementations make them different sizes.  (There are
32-bit floats, 40-bit, 64-bit, 80-bit, etc.)  So Forths tend to use a
separate float stack when they use floats.  They might settle for the limited
depth hardware float stack, or build a separate float stack in hardware.

String stacks have never really caught on in Forth, I don't know why.  People
have been discussing them recently.

Quote:
>Unfortunately my SwiftForth evaluation is way past expired, and didn't have
>much time to work with it.  What is hindering me most about Forth is that I
>feel the need to use variables of some sort, when in fact all data is being
>stored and retrieved from a single location.

You can use variables.  It's just that to do much with variables you usually
have to get the value out and put it on the data stack, and later when you're
done you put it back into the variable.  So you'll mostly use variables to
store things that are clumsy to leave on the stack.

Quote:
>Another thing about Forth is the way I enter in the program - it follows
>every step I make and processes accordingly.  I *don't want* it to do that.
>I want to write the program, and then execute it.  Even BASIC was an
>interpretor, but it didn't interpret a single line of code unless I wanted
>it to.

Most Forths let you write your program with a text editor, and load it later.
Many editor/forths let you choose a line or a few lines at a time to dump into
the interpreter.  


Mon, 01 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472
I'm not sure why you insist on trying to work with one hand tied behind your
back.  The fundamental issues you're asking about are covered in some detail
in free tutorials that have been recommended to you in the past (available
on www.forth.org), and in the Forth Programmer's Handbook (a pdf of which
accompanied your SwiftForth and is still there, even though the program has
expired and will no longer run).

Please try some of these sources of information.

Cheers,
Elizabeth


Quote:
> I'm not refering to the book, I'm refering to my personal venture.  :0/

> It finally dawned on me the whole concept of Forth.  I was looking at a
list
> of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
> whatever they are, and I realized what that was!  The word that is being
> used at some point is taking three values from the stack, and then
returning
> one.

> So does this only work with one data stack?  I've seen references to
String
> Stacks, Return Stacks, and Float Stacks... can someone explain a little?

> Unfortunately my SwiftForth evaluation is way past expired, and didn't
have
> much time to work with it.  What is hindering me most about Forth is that
I
> feel the need to use variables of some sort, when in fact all data is
being
> stored and retrieved from a single location.

> Another thing about Forth is the way I enter in the program - it follows
> every step I make and processes accordingly.  I *don't want* it to do
that.
> I want to write the program, and then execute it.  Even BASIC was an
> interpretor, but it didn't interpret a single line of code unless I wanted
> it to.

>   -----------== Posted via Newsfeeds.Com, Uncensored Usenet News
==----------
>    http://www.newsfeeds.com       The Largest Usenet Servers in the World!
> ------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers

==-----


Mon, 01 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

Quote:
> It finally dawned on me the whole concept of Forth.  
> I was looking at a list of core words, and I kept
> looking at statements like (n1 n2 n3 -- n4) or
> whatever they are, and I realized what that was!  
> The word that is being used at some point is taking
> three values from the stack, and then returning one.

> So does this only work with one data stack?  I've
> seen references to String Stacks, Return Stacks,
> and Float Stacks... can someone explain a little?

I was just thinking of playing devil's advocate yesterday in a
new thread about the concept of the complexity of Forth from the
point of view of the Standard by asking if the ANS Forth
Standard was in fact a virtual machine with four stacks, data,
return, control, and FP.  The Standard model separates these things
conceptually although an implemenation may have control and FP
stacks within the other two or separately or not at all. Not
that I think that the Standard has exactly forced the
extension of Forth to four stacks but I just wanted to point
out that the wording of the standard with regard to these
other stacks introduces more complexity into understanding
the concept of Forth. I understand why control and FP stacks
were factored out conceptually in the Standard to cover a
range of implementations and why FP stacks are generally
really another stack and part of the standard.

I thought that people might say I was grasping at straws and
that people would not ever get the wrong impression and not see
the virtual machine model in Forth being a two stack machine.
It might appear that I asked Sagalore to act as a schill
and appear confused about how many stacks Forth actually has.

For Sagalore: Forth is based on the model of a virtual machine
with two stacks.  Many other languages use a stack for return
addresses with subroutine calls and returns and for temporary
storage of data.  In Forth we call that the return stack.  Forth
also has a parameter stack also called data stack for holding
the working data.  This is one of the things that make Forth
different than BASIC.  Code in Forth is organized in words
and most of them work with the data on the data stack when
they run.  When you include support for the floating point
extension specified in the standard you will also usually
get a separate stack for that.  You can also create your
own stacks inside of a program to hold other things when
you want to do that.  But the Forth virtual machine has
the two stacks, data and return.

I am suprised that you didn't figure out the importance of the
idea of the two stacks in Forth earlier on and were then actually
confused about if the model was not really three or four stacks.
I hope my explanation helped.  I think you are making your
progress very difficult by limiting where you are looking
so much.  But there are on-line tutorials that might help you
graps the basic concepts of Forth to help you visualize what
is going on with the stacks.  I am pleased that you did get
the idea of how the words manipulate the stacks in Forth.

Jeff Fox



Mon, 01 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

Quote:


>> String stacks have never really caught on in Forth, I don't know why.
>> People have been discussing them recently.
>What are the advantages of a String stack?

I don't know, I haven't used one.  If you do without one you can use
"counted strings" where you put the count first, or you can use
"string-and-count" where you put the starting address and the count
on the stack, or you can use zero-delimited strings, or come up with
something else.  

The traditional way to use counted strings gives you one character
for the length, which on most systems limits you to strings of no
more than 255 characters.  That's a disadvantage.  If you use 2 bytes
for the count, or four, you can have long strings but you get
incompatibility with the systems that use 1 and you might do better
to invent a whole new set of names for your operations.

If you use string-and-count, each string takes 2 items on the stack
and if you try to do anything with more than 2 strings at a time you
have to juggle them.

If you use zero-delimited strings, putting a zero at the end to say
it's the end, you can't have a zero inside your string and you have
to look through the whole string the first time you want to find out
how long it is (which is more of an issue the longer it is) and then
unless you want to do the same thing again later, you have to save
the length some other way.

If you only have one string, sometimes you might want to just leave
it on the stack, one character per stack item.  This might require a
rather deep stack but if you're going to do something to it one
character at a time in reverse order compared to the way you built
the string, it can work.  For a lot of things that's far too clumsy.

Languages like Basic give you reasonably easy string operations, they
make it look simple.  I think they use complicated memory management
techniques with garbage collection.  It's slow and inefficient but it
looks easy when you can ignore what's going on.  Forth programmers
can get efficient string stuff provided they don't try to do the hard
things.  Once you start doing hard things all of a sudden there's no
common practice and various extremely clever people have each done it
their own way.

I hope this gives some of the flavor of what the problem is.  I'd like
it if someone who's been using string stacks explains what they do.



Tue, 02 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472
On Fri, 14 Jan 2000 13:11:26 GMT, Jonah Thomas

Quote:



>>> String stacks have never really caught on in Forth, I don't know why.
>>> People have been discussing them recently.

>>What are the advantages of a String stack?

>I don't know, I haven't used one.

I'm just getting started using one.  The advantages I see are:

(1) The ability to write string words that use few parameters.  For
example, at one stage in developing my pattern matching strings, there
was a total of four items on the stack to represent the portion of the
string passed over, the portion remaining, and the state of the match.
The string stack reduced that to just a flag for the state of the
match.

(2) That makes it easier to interpolate string handling and other
forth words.  I've seen that in a dramatic decrease in 'stack noise'
in the pattern matching words when I rewrote them for the string
stack.

(3) And I guess its an advantage to have implicit space recovery
without any garbage collection process running in the background, but
as I am still experimenting with my pattern matching (I just got my
file grep type word and line span display word running last weekend),
and I am running gForth on a home computer, space recovery has not
been a serious issue yet.



Wed, 03 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

Quote:

>It finally dawned on me the whole concept of Forth.  I was looking at a list
>of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
>whatever they are, and I realized what that was!  The word that is being
>used at some point is taking three values from the stack, and then returning
>one.

Congrats.

Quote:
>So does this only work with one data stack?  I've seen references to String
>Stacks, Return Stacks, and Float Stacks... can someone explain a little?

You usually only explicitly work with one stack (at least when starting
out), the data stack.  The return stack is useful to track program flow
(and also to store some temporary values like loop counters/etc), but
that's "an advanced topic."  float and string stacks are nothing you need
to worry about until you understand everything else -- they aren't
available everyhwere and there is controversy as to whether or not they
are a good idea at all.

Quote:
>Unfortunately my SwiftForth evaluation is way past expired, and didn't have
>much time to work with it.  What is hindering me most about Forth is that I
>feel the need to use variables of some sort, when in fact all data is being
>stored and retrieved from a single location.

You can still have variables, they just aren't as useful and hence don't
have as many fancy scoping rules.  If you want a Forth to mess around on
since SwiftForth evaluation expired, I recommend Pygmy Forth (for
DOS...http://www.eskimo.com/~pygmy/), though there are at least a dozen
freely available Forths that could be great for learning.

Quote:
>Another thing about Forth is the way I enter in the program - it follows
>every step I make and processes accordingly.  I *don't want* it to do that.
>I want to write the program, and then execute it.  Even BASIC was an
>interpretor, but it didn't interpret a single line of code unless I wanted
>it to.

You will get into the habbit of testing programs as you write them and
begin to see it as an advantage, but Forth really doesn't limit you to
this (superior) methodology. :)

        Elizabeth Rather has suggested that you read free texts available
on the Internet.  I cannot personally vouch for those texts, though I'm
sure they're fine.  Something that is failsafe guaranteed great
introduction, though, is _Starting Forth_ by Leo Brodie.  I figure you
probably don't want to throw much money into the venture, so you will have
to try your best to find it at a library (I found it at the local
university library, but I'm rather lucky to have such a large university
in my home town).  I read _Starting Forth_ with Pygmy Forth as my
companion and I can now say I understand how Forths work, not just how the
language looks when looked at the way other languages are looked at
(looking at Forth the same way you look at C and Scheme etc can be
extraordinarily rewarding, surprisingly, but nowhere near as rewarding as
looking at Forth the way that Forth fiends look at it).



Wed, 03 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

Quote:




>> >It finally dawned on me the whole concept of Forth.  I was looking at a
>list
>> >of core words, and I kept looking at statements like (n1 n2 n3 -- n4) or
>> >whatever they are, and I realized what that was!  The word that is being
>> >used at some point is taking three values from the stack, and then
>returning
>> >one.

If you are looking for a Forth to use, go to www.forth.org , the FIG site,
and look for a line that says Forth Primer. This is a 1.1 meg zip file that
contains F-Pc forth along with help files and a tutorial by Dr. Ting. As a
bonus, eForth is included. This forth uses text files for source so it
should be more familiar than forths that use screens.

The FIG site also has links to other forth sites. Look for the Forth UK site
as it has an online tutorial that they keep expanding, and the ftp: site at
www.taygeta.com  where other forths can be found.

I don't know where you live, but most American libraries are able to borrow
books  from other libraries for two to four weeks, plenty of time for you to
get a crash course in Forth.

"Starting Forth" by Leo Brodie, and "Forth: A Text and Reference" by Mahlon
G. Kelley and Nicholas Spies are both good.

You will be much happier if you stop trying to think of Forth as a strange
form of C. I like to regard it as a postfix assembler.  Instead of ADD a,b
, you have a b +, where a and b are data on the stack. Forth emulates a zero
register  processor in which the Operator (Word) finds data by their
position in the data stack rather than the address of a register.

The ( n1 n2 -- n ) is called a stack picture, and is a comment. It is
divided into two parts by the '--'. The left half tells you the proper order
of the data the Word expects, and which you arrange, if necessary, by using
the stack operators ( dup, swap, rot, etc.). The right half shows the order
of the data after the Word executes. If there is more than one number, the
Top number in the stack is the rightmost in each list, n2 in this case.

Walter Rottenkolber



Thu, 04 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472


Quote:
>I was just thinking of playing devil's advocate yesterday in a
>new thread about the concept of the complexity of Forth from the
>point of view of the Standard by asking if the ANS Forth
>Standard was in fact a virtual machine with four stacks, data,
>return, control, and FP.

Locals, loop data, return addresses.

Actually you could implement a standard system with one stack for each
of those abstract data types with undefined size that cannot be

do-sys, case-sys, of-sys, loop-sys, nest-sys.  There is no standard
way a program could tell the difference between such a system and a
system with only two stacks.

- anton
--
M. Anton Ertl                    Some things have to be seen to be believed

http://www.complang.tuwien.ac.at/anton/home.html



Thu, 04 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472

concerning "Learning Forth, attempt #3472":

Quote:
> It finally dawned on me the whole concept of Forth.
> Another thing about Forth is the way I enter in the program - it
> follows every step I make and processes accordingly.  I *don't want*
> it to do that. I want to write the program, and then execute it.

May be you should use  F-PC  with build in help and editor.
F-PC comes with ALL sources so you have a lot of samples

There are also many tutorials available.

F-PC  will let you use  FORTH  the right way, from start on.

--
Arndt Klingelnberg      Forth: F-PC-ak and Triangle TDS ( + CAN )


        Aix la Chapelle   :-)   Euregio Meuse/Maas Rhine/Rhein

        Die OstKantone Belgiens, wo andere Ferien machen.

## CrossPoint v3.11 ##



Fri, 05 Jul 2002 03:00:00 GMT  
 Learning Forth, attempt #3472


Quote:
> I'm not refering to the book, I'm refering to my personal venture.
:0/

> It finally dawned on me the whole concept of Forth.  I was looking at
a list
> of core words, and I kept looking at statements like (n1 n2 n3 -- n4)
or
> whatever they are, and I realized what that was!  The word that is
being
> used at some point is taking three values from the stack, and then
returning
> one.

OK. One big hurdle is behind you...

Quote:
> Another thing about Forth is the way I enter in the program - it
follows
> every step I make and processes accordingly.  I *don't want* it to do
that.
> I want to write the program, and then execute it.  Even BASIC was an
> interpretor, but it didn't interpret a single line of code unless I
wanted
> it to.

This is the next big step, and you are not alone. Every month or so, I
get requests to make a "bytecode compiler" for my pbForth. The whole
point of pbForth is that it runs on the LEGO RCX Mindstorms brick, and
that it does the interpret/compile for you in a platform independent
way.

You type at the terminal to check definitions, when you are happy, you
can cut the good stuff out of your terminal window and paste it
into your editor as skeleton code. Then comment it and resent it
to the RCX and when you are done, you can even get it to spit a
precompiled image back to your computer in S record format using
XMODEM!

The whole idea is that the LEGO Kindstorms brick is doing the compile,
not the PC/Mac/Linux box. I don't have to write any software to
do cross-compiles on those boxes either. Slick, huh?

But some folks just don't get it. The idea of a little 8 bit micro
doing their compiles instead of a 400Mhz Bit-Smasher III CPU running
some GUI is too far-fetched.

--------------------------------------------------------
Check out pbFORTH for LEGO Mindstorms at:
<http://www.hempeldesigngroup.com/lego/pbFORTH>
--------------------------------------------------------
Reply to:      rhempel at bmts dot com
--------------------------------------------------------

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 06 Jul 2002 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. 3472

2. The BEST Forth FOR LEARNING Forth

3. Forth Programs (was Forth learning curve)

4. Parallelism in FORTH (third attempt)

5. Games in Forth ? Need source to learn

6. Forth learning/teaching aid

7. Learning Forth?

8. Learning Forth

9. learning forth -- please help

10. I want to learn forth

11. The Grand Challenge after Learning Forth

12. how can I learn forth

 

 
Powered by phpBB® Forum Software