![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Patrick Elliott wrote:
>
> On Tue, 15 Jan 2002 19:52:01 -0500, Christopher James Huff <chr### [at] mac com>
wrote:
> >
> >
> > I've never seen any Forth code...what's it like?
>
> Except for some minor syntax differences, like using FORMAT to print formated
> output, instead of PRINT USING, .OR. instead of simple OR and similar things
> the code in Forth appears to be very similar to that of QBASIC, which also allows
> you to use line numbers only when you need them.
[snip]
> Some examples are at http://www.ngs.noaa.gov/PC_PROD/pc_prod.shtml
Actually, that's Fortran, not Forth. What you said about the syntax and
the math-related strengths are very true, though.
Deaken
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Wed, 16 Jan 2002 19:49:07 -0800, Deaken <dwy### [at] sw-tech com> wrote:
> Actually, that's Fortran, not Forth. What you said about the syntax and
> the math-related strengths are very true, though.
>
> Deaken
Oops.. Yeah I figured that out when I took a look at the sample code in your next
post,
but by then it was a little too late. lol Actually the code for loops you had looked
more
C-ish. ;) Though, out of context it is hard to tell how cryptic it really is.
Nothing like trying to figure out how someone elses code works, when you don't know
the language and have no interpreter that will let you see values or get some sense of
what is going on in it. I have tried at least once to convert some code in Fortran
into
VB, but couldn't figure out why it wouldn't work. I wasn't even sure what the
original
code should be generating at each point.. :p Oh well, will figure it out eventually.
lol
Frankly the oldest language I have had any formal learning of is COBOL and that was
due to my college insisting that we had to know it, since most companies still used
it.
Things like C++ and Windows at the time where 'current concepts'. Annoying thing being
that the changed everything (including all new computer systems) the year after I
graduated. :p
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Patrick Elliott wrote:
>
> Actually the code for loops you had looked more
> C-ish. ;) Though, out of context it is hard to tell how cryptic it really is.
Well, here's some context. And it's straightforwardly-written code, so
anything that's "cryptic" is the fault of Forth, not me.
In Forth, \ to end-of-line is a comment. You can also enclose comments
in parens, which is how I will demonstrate what the stack looks like.
[For more on stack-based programming, please see
<URL:http://www-2.cs.cmu.edu/~koopman/stack_computers/contents.html>,
especially Section 1.2.]
N \ This puts the address of N (where the variable is stored) onto the
stack.
( 9238 ) \ Made-up memory address
@ \ This uses up the address of N, and fetches what was IN that address.
( 5 ) \ Made-up value of N.
0 \ This is zero. It gets put on the stack, too.
( 5 0 )
DO \ "DO" takes two numbers off of the stack and loops between them.
\ In this case, it will loop from 0 to N-1, inclusive.
( ) \ Nothing on the stack.
5 \ This puts 5 on the stack.
( 5 )
SQRT \ This replaces 5 with what happens when we run the SQRT word.
\ If we're lucky, it'll turn out to be 2.
\ (Stacks are usually integers, y'see.)
( 2 ) \ The SQRT of 5.
I \ This gives you the value of the looping variable, which is always
\ (for singly-nested loops) called I. It puts it on the stack.
( 2 0 ) \ First time through, it's 0. After that it's 1. And so on.
:)
17 \ Puts 17 on the stack.
( 2 0 17 )
* \ Multiply the top two numbers, and replace them with the result.
( 2 0 ) \ 17 * 0 == 0
23 \ Puts 23 on the stack.
( 2 0 23 )
+ \ Replace the top two numbers with their sum.
( 2 23 )
DOSOMETHING \ DOSOMETHING (notionally) takes the top two numbers, and
\ does something with them. We will also imagine that it
\ doesn't bother to return anything.
( )
LOOP \ Finish the loop started with "DO".
You know what? That's really not very helpful.
Here's a better idea. Go to
<URL:http://www.softsynth.com/pforth/pf_tut.htm> and poke around
"Arithmetic", "Variables" and "Loops". Phil Burk does a much better job
of explaining it than I just did. Sorry about that.
Also, since this has nothing more to do with scene files, please direct
all followups to povray.off-topic or to me personally, via email.
> Annoying thing being
> that the changed everything (including all new computer systems) the year after I
> graduated. :p
Always the way. That happened to me in elementary, junior high, and
college. In high school, they upgraded the last year I was there. Heh.
Deaken
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |