6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Oct 31, 2024 11:48 pm

All times are UTC




Post new topic Reply to topic  [ 144 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8, 9, 10  Next
Author Message
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 09, 2017 9:18 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
I have to disagree, based on the fact that bug-free development is much faster in Forth than in other languages.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 09, 2017 10:45 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
GARTHWILSON wrote:
I have to disagree, based on the fact that bug-free development is much faster in Forth than in other languages.
I'm not sure that's a contradiction - I'm taking about the amount of thinking involved in the process, not the quality of the result. Take the Python snippet above: Simple to grasp, but still an amazing number ways to screw up if I'm not careful (starting with the whitespace indent). The Forth version of the same snippet (with a print(twice) command in the loop to see what we are doing) could very well be easier to keep bug-free if the user carefully chooses small words etc. Uh, off the top of my head:
Code:
: makelist ( -- addr u )  here  1 , 2 , 3 , ( len ) 3 ; 
: .list ( addr u -- )  cells bounds do  i @ 2* .  1 cells +loop ;
makelist .list     \ oops, sorry, forgot that first attempt
This runs with Gforth and Tali (well, once you've explained BOUNDS and 2* to Tali, which will be included out of the box with the next update), two totally different machines. Python won't even run on a 8-bit machine, so the question which language makes better use of limited hardware resources isn't even funny. Certainly bug-free, because I checked makelist and then .list.

My argument is not about which language gets you to bug-free code faster -- I have no reason to think you are not totally correct (my one large Forth project, the 65816 emulator, is far more stable than it has any right to be given my skill level). My argument is about which one requires more thought. I'm not sure the Forth version of the (admittedly trivial) Python example above could be called less complex or easier to understand.

(LATER ADDITION)

Actually, this might be a good example of how you can try to be clever in Forth for even more oompf. If we know that we're only going to have those three numbers, we don't have to muck about with cell sizes, and can just write
Code:
: makelist ( -- addr u )  here  1 c, 2 c, 3 c, ( len ) 3 ; 
: .list ( addr u -- )  bounds do  i c@ 2* .  loop ;
On Gforth with 64-bit cells, that saves 21 bytes, and three bytes with Tali's 16-bit cells. A byte saved is a byte earned!


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 09, 2017 1:02 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
scotws wrote:
One insight that helped me was realizing what Forth was originally made for and what it is used for in Real Life (TM) until this day: Situations when your hardware is really not adequate for the job you have to do - when you have to "do more with less". You're NASA and you're sending a probe into the cold and radiation-bathed hellscape around Saturn, so you're hardware has to be robust and dirt simple.


I think you can achieve the same with C, as long as the hardware has a few (simple) provisions, such as an easy way to access local data on the stack. The 6502 wouldn't really qualify, but something like an STM8 would be fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Thu Mar 09, 2017 7:45 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Garth, here's some of what I was referring to: http://www.ultratechnology.com/cm52299.htm

I had an interesting experience yesterday as I was trying to shove all of the F83 sources in to a single file. F83 works with Block files, vs text files. And it's core system comes in 5 files: KERNEL86.BLK, EXTEND86.BLK, META86.BLK, CPU8086.BLK, and UTILITY.BLK.

A Block files contains both code and documentation. Essentially the file is divided in half, and each code screen has an associated documentation, or Shadow, screen that's half a file away. So, if you have a file with 100 Screens, Code Screen 1's shadow screen would be Screen 51. In the editor, you can toggle between the 2 with the 'A' (Alternate) command. You can change the offset to suit you, but, you're working against the grain doing that.

Now, the Forth block commands have no concept of a file. So, the system has the trait of a Current File. Thus, when you enter 1 LIST or 1 EDIT or 1 LOAD, you will be working with the first screen of the "current" file.

F83 also has a nice facility called VIEW. If you type VIEW WORDS, it will list the source screen that has the "WORDS" word. You have source to everything, so it makes it easy to browse the source and the documentation. However, the VIEW word, under the covers, changes the Current File.

If you do:
Code:
OPEN MYFILE.BLK
1 LIST
VIEW WORDS
1 LOAD

You just loaded the first screen of KERNEL86.BLK, which is where the source for WORDS resides.

So, to simplify things, I was going to try and push all of the source in to a single block file, along with my own work, just to keep that from happening. To quote Forrest Gump: "That's good! One less thing."

So, I had to copy the existing block files in to a new monolithic one. But because of the nature of Shadow screens, and their relationship to the overall size of the file, I couldn't simply concatenate the files. I could, they'd just be more of a pain to deal with overall.

F83 also has the idea of the "INPUT" file, specifically for problems like moving screens from one to another. It also has the CONVEY word to perform the copy. CONVEY has the variable, HOPPED, which is used to offset the copy. Normally you'd do: 1 10 CONVEY, that would copy screens 1 thru 10 to screen 1 thru 10 in the new file. If HOPPED is set to 5, then the destination would be 6 through 15 (as HOPPED is added to each screen during the copy).

There's even a nice facility: 1 10 TO 5 CONVEY. Here, 'TO' is a bit of syntactic sugar to set HOPPED properly. This copies screen 1 10 to screen 5-14.

So, a copy session in the end would look like:
Code:
OPEN NEW.BLK
FROM OLD.BLK
1 10 TO 5 CONVEY


For my task, I need to break the original file up in to 2 pieces (the code, and the shadow screens) and relocate them to the new larger file. So, if NEW.BLK is 50 screens large, and OLD.BLK is 10 screens, I need to basically do:
Code:
OPEN NEW.BLK
FROM OLD.BLK
0 4 TO 0 CONVEY
5 9 TO 50 CONVEY

Then, if I 1 EDIT on NEW.BLK, and hit A, I'll get the proper shadow screen.

Turns out, as shown, none of that is automatable. Not readily. OPEN and FROM are immediate words, so you can't simply stick them in a colon definition. The word TO is also an immediate word that parses the 5 (in this case) out of the input stream. 1 and 10 are on the stack, but 5 is not. So, this also is not easily put in to a colon definition. What starts as a simple automation task, now becomes an advanced Forth exercise.

F83 has a word CAPACITY, which gives you the size of the current file. I need that to split the files in two. But CAPACITY doesn't work on the INPUT file (OLD.BLK in this case), only the current file. And CAPACITY only works with the global FILE variable. Thankfully, there's a SWITCH word to move these back and forth. Also, the word TO behaves differently from HOPPED. For: 5 9 TO 50 CONVEY, naively you'd think HOPPED would be set to 50. But that's not true, it's set to 45. Because we want 5 to become 50, and HOPPED is simply added during CONVEY.

In the end, I finally got CONVEY-FILE written.
Code:
OPEN NEW.BLK
FROM OLD.BLK
10 CONVEY-FILE

This would copy the code screens from OLD.BLK to starting at Screen 10 in NEW.BLK, and the Shadow screens to Screen 35.

This in all took about 2 hours to suss out, and now I get an I/O error when trying to load up the meta compiler from the monolithic file.

But what was interesting here was the fighting between words that are basically designed for interactive use and those used within other words. For example, perhaps it would have been better if CAPACITY were written as:
Code:
: CAPACITY FILE (CAPACITY) ;
: (CAPACITY) ( fcb - size in screens) ... ;

Then, perchance I could use (CAPACITY) in my code, rather than having to SWITCH back and forth between files. This goes to that cognitive load issue. "What file is current when I call CAPACITY?" Man, I tell ya, especially combined with the stack juggling, this little utility, which is, like 3-4 lines of code, boy was it an effort to type this stuff out.

A lot of that is practice, a lot of that is the nature of the F83 design in this case. The mixing of interactive commands and automating them. The premise that there is a difference between the two. (Lisp has different behaviors when LOADING and COMPILING, but they're less in your face as this is.) Some of that is F83 design choices, some of that is Forths nature to effectively allow such choices.

But all of that added up to being a bit of a struggle yesterday, for sure.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Tue Mar 28, 2017 6:42 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
I posted this in the "So, Forth" topic, and then realized it wasn't the topic I thought I was tacking it onto, but Mike already replied to it, so I'll leave it there and re-post here:
Quote:
Byte magazine Forth issue, V5N8, Aug 1980, over 100 pages on Forth:
https://archive.org/details/byte-magazine-1980-08
Caveat: I have not read it myself. Since the .pdf download is over 200MB, I might hold out for the day I can find the paper magazine in a used book store!
:mrgreen:

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Wed Mar 29, 2017 12:32 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
The magazine is a fun read. The ads alone are interesting from a nostalgia factor.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Mon May 08, 2017 1:23 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
Again not 6502-specific, but regarding the character of Forth, I liked this public post (below) on the FORTH PROGRAMMING LANGUAGE facebok group by Vladimir Los who I don't think is on this forum.  He apologizes for his English, so I have taken the liberty to make minor edits to improve the English while preserving the meaning (assuming I understood him correctly).

------------------------------------

For me, Forth is a means to help think about a modeled system.  Even further, Forth helps in creating things to support such thinking.  I've used several languages in my projects: C (plain, ++, #), Delphi, Turbo/Borland Pascal, Oberon (Active and Component Pascal), even Ada in one project.  Every time, sooner or later, the thought came to me that one part or another would be better expressed in _____ <fill in the blank> language!  When the project was in Delphi, I thought it about C.  When it was in C, I thought it about Oberon...

Why did it happen regularly?  Because all those languages had (and have) a strictly limited set of concepts and approaches to express or implement things.

But in Forth you don't even have any syntax!  You really only have one rule: put spaces between things you consider meaningful or significant.  :D The concept of defining words is something so radically different from what you can show in all other (even possible) languages!

This is simply genius!

One has the simplest compiler with unlimited possibilities to express what was/is born between one's ears!  This compiler will never reach the limits of its complexity!  Its ability to expand is infinite, without forfeiting its simplicity.  You don't have to add "new features" to a "compiler" itself.  It stays the same; but you add new chunks of code to build only the needed structures and operations to implement your new ideas.  No need to wait for a new version.  No need to wait for a committee to finish a new standard.

But this feature of Forth is what managers and bosses view as problematic.  They have no standard scales and means of measurement to evaluate the progress in a project.  They realize that they will have a big problem if they hire a forther and later need to find a replacement for a him/her.  For a long time, I have preferred to not tell my colleagues and bosses that I like FORTH.  Forth changes the thinking.  And these changes are not viewed as positive by the mainstream programmer today.  The mainstream is working differently.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri May 12, 2017 8:43 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1241
Location: Soddy-Daisy, TN USA
GARTHWILSON wrote:
I cannot believe how such an incredibly idiotic language (C) got accepted by the industry! I assume it took a good salesman taking advantage of perfect timing and other factors that just happened to line up. Samuel's words were, "C is a very simple language to learn. Just be careful, since C is also a terribly difficult language to master." I can't agree with it being simple to learn. Difficult to master, definitely. I have a million notes in the book. I can only take a couple of pages at a time, as it's so exasperating. IMO, C is an absolute disaster; and the C code in the book (which is supposed to be a model) looks to me like when you see the helicopter views of houses in Tornado Alley that have been turned into a pile of toothpicks by a tornado.


I guess it's just different strokes for different folks. I started out with BASIC and moved to 6502 ASM when I was 11 or 12. I then moved on to C (on DOS). There are times when it doesn't make sense. But, I never felt it was garbage. As I learned C, it helped me quickly learn C++ which helped me learn C# very fast. Then my company dropped C# and went to Java which I currently develop in. In all of those years, I moved from C to C++ to C# to Java with VERY LITTLE difficulty. Because they share so much in common.

On the other hand, I'm trying to give Forth a chance (several times actually). I guess it's the RPN that gets me. My human brain just doesn't compute that way and I've got 30+ years in programming in the "C based" world.

Anyway, in my experiences...I find the languages are the least of the problem. In my experiences, it's the frameworks that are usually bad. But it's deeper than that for me...again, in my experiences, developers generally want to reinvent the wheel because they think they can. So I see GIANT projects NOT USING the frameworks we all agreed on. Or, some programmer will abstract classes beyond belief because he read a book about it or a blog post and how he's doing it "the right way".

Sorry, went off topic there.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri May 12, 2017 9:55 pm 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
I don't really understand what the problem with C is. I started with 6502 assembly language, well, hex code first, then some BASIC, which I qiuickly found terrible. Then Fortran, Pascal, etc. C arrived at some point and it was effortless. A few pitfalls, easy to stay clear of those. It's simply another procedural language. But much more standardised than most languages, due to where it came from.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri May 12, 2017 10:12 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
At its most basic, C is portable assembly. Anyone comfortable with a macro assembler should be able to pick up basic C readily.

The most complex notions being dealing with types and pointers. Its easy to go off the rails wth complicated type declarations, and they can certainly be difficult to decipher. Add in complicated expressions, especially with pre- and post-fix operators, and it can daunting to understand exactly what may be happening.

But just because you can have "Obfuscated C" contests, or puzzles that go in to the nuances of operator precedence, doesn't mean you have to.

All of the arguments about Forth unreadability apply to C. If you don't want your Forth or C to be unreadable, don't write it that way.

My singular difficulty with Forth, specifically with an existing source code base, is that you as the reader need to have much more familiarity with the source code in order to understand it, simply because Forth does not make visible the argument structure of the different routines. You, as the reader, need to keep the runtime stack in your head as you read the code. And this requires that you have an understanding of what are the stack affects and requirements of each word. Add in some global variables, and its quite a burden for someone unfamiliar with the source code.

Reading C code, you still need to understand what individual routines do, but, outside of global variables, the data flow, along with the logic flow, of a routine is explicitly laid out in the source code. It's different when you're intimate with the code and the routines, but when dealing with strange code, C can be much more accessible than Forth, to me.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Fri May 12, 2017 10:35 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8466
Location: Midwestern USA
whartung wrote:
At its most basic, C is portable assembly. Anyone comfortable with a macro assembler should be able to pick up basic C readily.

That's basically it. Of course, we're talking about K&R C and ANSI C, not the aberrations that followed.

As for Forth, I see absolutely nothing in that language for me.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Sat May 13, 2017 6:56 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
cbmeeks wrote:
I guess it's just different strokes for different folks ...

Agreed. When I was a teenager, my brain was very receptive to new languages, and I quickly learned BASIC, 6502 assembly, 6809 assembly, Fortran, Pascal, IBM 360 assembly, C, 68K assembly (in addition to Spanish and a bit of French and Portuguese) ... then I ran out of teenage years, and my brain started getting less and less receptive. I really want to learn Forth and use it, but it's an uphill battle, because my 51-year-old brain is resisting my efforts ...

Mike B.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Sat May 13, 2017 8:19 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8534
Location: Southern California
I have a long list of beefs with C; but as we've discussed the C v. Forth thing here on the forum, I am coming to be more of the opinion that some people really are destined to think more one way than another, like it's inborn, not just a matter of background (although I understand the Korean language is RPN, making Forth more natural to Koreans).  I had TI algebraic calculators before an HP RPN one, and I did a lot of BASIC also (from toy BASICs to professional), and even took Fortran, before meeting Forth; yet the way I think definitely tends toward RPN and Forth.  Others have some trouble with it.  With those who use the calculators, they often want the stack displayed so they can see what's there.  I have no need for that.

As I was discussing this with Ed, he replied, "It's an interesting idea, that you might have an RPN brain!"  The evidence points that way.  It's not just the RPN though.  It's also C's suffocating punctuation, syntax rules, parentheses, brackets, curly braces, that a pointer cannot be a variable and vice-versa, that the compiler is not extendable, that it doesn't work well to have a function return more than one output, that in switch...case, the cases can only be constants, that you can't use special characters in names for example to name a variable °C(initial) (yes, all 11 characters are the name), a list of precedence and associativity of operators that I'll never remember unless I use it every day, that the system of pointers to pointers or pointers to functions is much more complicated and less flexible than what Forth affords...and on and on it goes.  I see C as a very inflexible system that cannot be extended by the user.

I have no problem with anyone wanting to use the language they're good at, and I do hope better and better 65c02/816 compilers for these get written.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Sat May 13, 2017 10:43 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10971
Location: England
I read an interesting note about learning a new (spoken) language, to this effect: if you're the kind of person who wants to know precise definitions, it's a drawback. You need to have a go, and struggle through your difficulty in expressing yourself. To me, this seems the same in programming. Most languages have a lot of features and some dark corners, and most programmers become competent without exploring all of them.
Quote:
Linguists have found that students with a low tolerance of ambiguity tend to struggle with language learning.
Language learning involves a lot of uncertainty – students will encounter new vocabulary daily, and for each grammar rule there will be a dialectic exception or irregular verb. Until native-like fluency is achieved, there will always be some level of ambiguity.
The type of learner who sees a new word and reaches for the dictionary instead of guessing the meaning from the context may feel stressed and disoriented in an immersion class. Ultimately, they might quit their language studies out of sheer frustration. It’s a difficult mindset to break, but small exercises can help. Find a song or text in the target language and practice figuring out the gist, even if a few words are unknown.


Top
 Profile  
Reply with quote  
 Post subject: Re: What is Forth?
PostPosted: Sat May 13, 2017 12:45 pm 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
As for RPN and Forth - or not Forth - that doesn't necessarily have much to do with it. In my case my problem with Forth has nothing to do with RPN - HP calculators are extremely natural for me. I moved over from TI first chance I got. And I actually like the RPN part of Forth. It's just that I've never managed to find a way to get Forth to solve the programming tasks I want to try it on. So I don't try anymore. It looks to me like if you stick to problems solvable by Forth, and just ignore the rest, then all is fine. But I'm short of those.
I don't know if anything of this has any connection with real languages - my gut feeling says 'no'. In any case, dictionaries aren't very useful for me when learning languages. I learned English without one, I only remember words when I understand the meaning from context. It's the same for the other languages I know, although I'm not that fluent in those.
Edit/Update: Thinking more about it, the RPN of Forth is not my problem, it's probably more my procedural brain. And that my designs, in general, only have a few places where I would create functions to do something with parameters and return the result, which for me at least is the one case which is easy to map to Forth.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 144 posts ]  Go to page Previous  1 ... 4, 5, 6, 7, 8, 9, 10  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: