ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/08/90)
Date: 05-31-90 (22:01) Number: 3322 (Echo) To: ALL Refer#: NONE From: ROGER BICKNELL Read: (N/A) Subj: WIL BADEN'S PUZZLES Status: PUBLIC MESSAGE Help! Do you remember those logic puzzles from wil baden that we had around here awhile back? A friend of mine is VERY interested in seeing them - can anyone provide them? thanks, in advance roger NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/14/90)
Category 3, Topic 35
Message 109 Tue Jun 12, 1990
R.BERKEY [Robert] at 00:10 PDT
Dennis Ruffer writes:
You can not pass a string to CREATE other than messing with the
input stream and even that might be real tough under Forth-83.
This seems to keep coming up, but Forth-83 specifies the accessability of the
text input buffer. The file QUOTE-TO.SCR rigidly follows Forth-83 constructs
and thus is fully portable under the Forth-83 Standard. As to the specific
case of CREATE , the example at the end of QUOTE-TO.SCR defines "CREATE
("quote-create").
So, it need not be any "tough"er than downloading a file from GEnie.
---
The program QUOTE-TO.SCR is more than an idle exercise. This is portability
as it is defined today.
It wasn't so easy. I found the documentation requirements to be much more
difficult than the program itself. I think it is possible to write a Forth-83
program that would automatically calculate the documentation values, but two
key words are missing that make this prohibitively difficult. One of these is
ACQUIRE , which was recently submitted as a proposal to X3.J14. Had each of
the Forth-83 committee members written some programs, perhaps there would be
enough software tools within the standard itself to get the job done right.
(The documentation requirements might have been changed, too, but the tools
would be useful for much more than the one case.)
Pertinent questions:
What's needed to run this program on F-PC?
What's needed to run this program on LMI products?
How about other systems?
Why doesn't this program meet BASIS usage rules?
If you're not interested or concerned about such standard's issues,
why not?
How easy is it to translate this program into BASIS Forth?
Are there individual words that won't translate?
Can the resulting program be burned in ROM by a third party? I.e,
without doing more programming?
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/14/90)
Category 3, Topic 35 Message 110 Tue Jun 12, 1990 D.RUFFER [Dennis] at 23:58 EDT Robert, QUOTE-TO.SCR loads and appears to work just fine in polyFORTH. I'm not versed well enough in BASIS to know if it complies, but I will try to do some analysis tomorrow. I seem to remember something about >IN. There was a need for the words SAVE- INPUT and RESTORE-INPUT, but I need to check it out before saying for sure. Thanks for pointing your file out to me. I hadn't thought about saving and restore the entire input stream, but it would fit in nicely with the original problem. Now to go re-read that message and use your words to solve it. DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/16/90)
Category 3, Topic 35 Message 111 Fri Jun 15, 1990 D.RUFFER [Dennis] at 01:07 EDT Ok, with Robert's QUOTE-TO.SCR in hand, John's puzzle can be solved. ir230@sdcc6.ucsd.edu (john wavrik) writes: > PUZZLE > > It is possible to write Forth words which create new definitions. > My code gives a situation in which this is would be desirable: it > defines > : [1] 1 [] X@ ; : [2] 2 [] X@ ; etc. > > What is the best way to define a word SELECTORS so that 2 > SELECTORS would add the above two definitions to the dictionary, > 9 SELECTORS would add [1] up to [9], etc.? > > RULE: Only Forth-83 Standard words can be used to do this. Here is a couple of solutions. First, like John wanted it: CREATE TEMP 80 ALLOT : C+! ( n a) DUP C@ ROT + SWAP C! ; : !b ( b) TEMP COUNT + C! 1 TEMP C+! ; : !$ ( a n) DUP >R TEMP COUNT + SWAP CMOVE R> TEMP C+! ; : [n] ( n) CREATE , DOES> @ [] X@ ; : SELECTORS ( n) 0 DO 0 TEMP C! 91 ( [ ) !b I 1+ DUP 0 <# #S #> !$ 93 ( ] ) !b TEMP COUNT "> [n] LOOP DROP ; Then, we can also expand on the idea a bit: : SELECTORS: ( n) >IN @ SWAP 0 DO 0 TEMP C! 91 ( [ ) !b I 1+ 0 <# #S #> 2DUP !$ 93 ( ] ) !b #SP !b !$ #SP !b DUP >IN ! 59 ( ; ) WORD COUNT !$ 59 ( ; ) !b TEMP COUNT "> : LOOP DROP ; For this one, you type: 2 SELECTORS: [] X@ ; or you can make it do anything you want it to. However, its utility is a little limited by the fact that the names of the definitions are always the same. If you have to change the name inside SELECTORS: you probably are better off with the first definition anyway. Thanks Robert! DaR BTW, I can't see anything in QUOTE-TO.SCR that would not fit ANS Forth except maybe \, but then I'd argue that it doesn't fit the 83 Standard either. A lot of your definitions go away, however, because they are already included in BASIS. It would be a curious excercise to find out if the versions in BASIS do the same things as yours do. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (06/18/90)
Category 3, Topic 35 Message 118 Sun Jun 17, 1990 D.RUFFER [Dennis] at 18:00 EDT > Dennis, I take it you don't like \ . Maybe Mitch can tell us > what the story is about \ at X3.J14. I'm also interested to > hear about what has happened to >IN . The problem with your definition of \ Robert is that it can not be used on text files or interpretively at the keyboard. I hope Mitch can explain what we just passed at the last TC meeting that makes it possible to define \ transparently. He understands it better than I do. As for >IN, let me quote the rationale from BASIS11: "When BLK is zero, the current input stream is specified by TIB, >IN, and #TIB. One obvious interpretation is that the initial value of >IN is zero and #TIB is the total number of characters in the input stream. Although this is indeed the case for QUERY, it is not generally true. In particular, EVALUATE might be implemented by setting >IN to the difference between TIB and the addr passed to EVALUATE, and #TIB set to >IN plus the number of characters in the string to be EVALUATEd. Re-reading the input stream by setting >IN to some arbitrary value, such as zero, in incorrect. It is, however, permissible to set >IN to some previously stored value of >IN." Now, I may be reading this wrong, but I infer from those comments that it is also incorrect to perform math on the value in >IN to adjust the input stream. You are probably correct about my SELECTORS: example Robert, but as I said in the posting, my SELECTORS version that uses [n] is a much better solution to John's puzzle. DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/02/90)
Category 3, Topic 35 Message 121 Sun Jul 01, 1990 W.BADEN1 [Wil] at 02:59 PDT Thanks to BOB WADA, president of Orange County FIG chapter, for answering the Permutation Puzzle. The puzzle was to generate the permutations of n things with the least effort. Least effort in this situation means with the least amount of work if the operations were actually physically performed. This would be if each permutation is transformed from the previous by exchanging the elements of a single pair of adjacent elements. A puzzle is a problem whose method of solution is not obvious. This problem qualifies for it is certainly not obvious how to solve it. It is also the kind of problem found in elementary programming textbooks. The solution here is a function "commuted", which given n and the sequence number of a permutation, tells which pair, 1..n-1, to exchange to obtain that permutation from the previous. For n = 4 and q = 1 to 4! this yields (extra spacing added): 1 2 3 1 3 2 1 3 1 2 3 1 3 2 1 3 1 2 3 1 3 2 1 3 Starting with 1234 these generate: 2134 2314 2341 3241 3214 3124 1324 1342 3142 3412 3421 4321 4312 4132 1432 1423 4123 4213 4231 2431 2413 2143 1243 1234 Forth. : commuted ( n q -- i) DUP 0= IF NIP EXIT THEN 0 >R BEGIN OVER /MOD ( n r q) 2 PICK 1 > 2 PICK 0= AND WHILE NIP ( n q) DUP 1 AND 0= IF R> 1+ >R THEN -1 +under REPEAT ( n r q) 1 AND IF ( n r) OVER - NEGATE THEN NIP ( r) R> + ; If you need it : +under ( a b c -- a+c b) ROT + SWAP ; ABC. HOW TO RETURN n commuted q: IF q = 0: RETURN 0 PUT 0 IN adjust PUT floor (q / n), q mod n IN q, r WHILE r = 0 AND n > 1: IF q mod 2 = 0: PUT adjust + 1 IN adjust PUT n - 1 IN n PUT floor (q / n), q mod n IN q, r IF q mod 2 = 1: PUT n - r IN r RETURN adjust + r This problem is not an academic exercise. In the fifties the NSA built special hardware to do this for cryptoanalys. It is also useful in the design of experiments. Further question: is Forth a suitable language for this kind of problem? Procedamus in pace. del,72 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/04/90)
Category 3, Topic 35 Message 122 Tue Jul 03, 1990 W.BADEN1 [Wil] at 18:31 PDT My apologies for the Permutation Puzzle. When I posed it I thought that there was a simple solution. Two days after discovering my solution I found the standard algorithm for this by H. F. Trotter, Algorithm 115, C.A.C.M., August 1962. The two produce exactly the same sequence. I don't expect that I'm the first to solve it the way I have, and if any one seen this solution before, would you let me know? I wish I had thought of it 30 or even 20 years ago, though. Trotter's algorithm was written in spaghetti Algol. (Sounds tasty -- spaghetti al gol.) Here are C versions of my algorithm and his for comparison. W.Baden. int commuted( int n, long i ) { int k, q; if ( !i ) return 0; k = 0; while ( !( q = i % n ) && n > 1 ) if ( !(( i /= n-- ) & 1 )) k++; if ( ( i / n ) & 1 ) q = n - q; return q + k; } H. F. Trotter #define MAXPERM 10 static int p[ MAXPERM ] = { 1 }; static int d[ MAXPERM ]; int perm( int n ) { int k, q; if ( p[ 0 ] ) { for ( k = 0; k < n; k++ ) { p[ k ] = 0; d[ k ] = 1; } return 0; } k = 0; --n; do { if ( !( q = p[ n ] += d[ n ]) ) { d[ n ] = 1; k++; } else { if ( q <= n ) return k + q; /* The usual exit.*/ d[ n ] = -1; } } while ( --n ); /* The final exit.*/ p[ 0 ] = 1; return k + 1; } If you don't know C well you'll probably have trouble following my algorithm, but you should be able to understand Trotter's. As a previous posting showed, there is a reasonable Forth implementation of my algorithm. I won't even try to forthify Trotter's, unless I need lots of speed for this function. Once again, is Forth a suitable language for this kind of problem? Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/05/90)
Category 3, Topic 35 Message 123 Tue Jul 03, 1990 W.BADEN1 [Wil] at 22:28 PDT I've changed my mind. Here's Trotter's algorithm in Forth. 10 CONSTANT Maxperm CREATE P Maxperm ALLOT 1 P C! CREATE D Maxperm ALLOT : perm ( n -- i) P C@ IF 0 DO ( ) 0 P I + C! 1 D I + C! LOOP 0 EXIT THEN 0 ( n k) 1 ROT 1- DO ( k) D I + C@ P I + C+! P I + C@ ( k q) DUP IF DUP I > 0= IF + UNLOOP EXIT THEN DROP ( k) -1 D I + C! ELSE ( k q) DROP ( k) 1 D I + C! 1+ THEN -1 +LOOP 1 P C! 1+ ; If you lack : C+! ( n a -- ) DUP C@ +under C! ; This was easy to code from the C. And I find the Forth easy to read. But discovering the algorithm in Forth without benefit of a higher level language would have been difficult. Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/14/90)
Date: 07-11-90 (22:52) Number: 3488 (Echo) To: W.BADEN1 [WIL] Refer#: NONE From: ROGER BICKNELL Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE Wil, Hi Quite some time ago now, you presented some puzzles in Forth here on BCFB's board. One in particular is of interest to a programmer friend of mine. It was a challenge to generate the log2 of a given integer. I don't remember the algorithm - would you repeat the question and answer for me? Thanks, in advance, Roger NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/15/90)
Category 3, Topic 35 Message 125 Fri Jul 13, 1990 W.BADEN1 [Wil] at 22:50 PDT Roger, I don't remember posing the problem, but the "answer" would probably be -- : lg ( n -- "log base 2 of n") 1+ -1 SWAP ( lg n) 1 DO ( lg) 1+ I +LOOP ; Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/19/90)
Date: 07-16-90 (22:07) Number: 3520 (Echo) To: W.BADEN1 [WIL] Refer#: 3504 From: ROGER BICKNELL Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE Hmmmmmm. Unfortunately I don't remember the actual puzzle either - except that determining whether an integer was a power of 2 was relevent and that there was a second, related problem posed. It was this second problem that I thought was associated with log2. I mentioned this to a programmer friend of mine, who subsequently decided to "prove" ( ala exhaustion...) that a Loop would be necessary to determine the log2 of an integer. I replied that I didn't remember there being a Loop in any of the results of the puzzles that were up here a number of months ago. ( I remember some preliminary suggested solutions that used Loops but were succeeded by results that derived the answer strictly from logical manipulations). No No No, he said - you definitely require a Loop! I said - Na - I appreciate your answer, Wil, but gosh... you used a Loop !!! =8-\ NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/25/90)
Category 3, Topic 35 Message 127 Mon Jul 23, 1990 W.BADEN1 [Wil] at 21:25 PDT Roger Bicknell writes, rb> No No No, he said - you definitely require a Loop! I said - Na - Strictly speaking you win because he said "definitely" and any loop with a constant number of iterations can be unrolled. Here is a 16-bit version. : lg ( i -- log2 i) 2/ DUP IF EXIT THEN 2/ DUP IF DROP 1 EXIT THEN 2/ DUP IF DROP 2 EXIT THEN ... and so on ... DROP 15 ; If there's any money riding on this, you collect. But I'm sure the three of us agree that this isn't what he meant. The problem you're thinking of is to test for a number's being a power of 2: : powerOf2? ( n -- flag) DUP 1- AND 0= ; Or if you don't want 0 to be a power of two: : powerOf2? ( n -- flag) DUP IF DUP 1- AND 0= ( flag) THEN ; Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/25/90)
Category 3, Topic 35 Message 128 Mon Jul 23, 1990 W.BADEN1 [Wil] at 21:28 PDT Every language has areas of application in which it is superior, even Basic, Cobol, and Ada. I'm trying to discover just what is Forth's domain of superiority. Obviously it is superior when resources are scarce, or there is an unusual environment. As Marty Fraeman says, "Forth is given us to program one-of-a- kind computers." Then there are unfamiliar environments where Forth's ability to peek, poke, and try lets us find out by trial and error how to hack what we want. There are algorithms envolving many variables and complicated expressions for which Forth offers no advantage. The determination of the date of Easter by 10 quotients and remainders is such, although of course it can be programmed in Forth as any algorithm can be. Local variables make Forth definitions into something like Tiny C with postfix operators. If vector operators are important for an application, Forth is not the best language to program them. Forth in these instances is a dancing dog. Forth may still be appropriate for such applications because of environmental rather than linguistic reasons. Forth may be a good language to program applications using operations for these things defined in another language, e.g., assembler. It is ironic that Forth's name was chosen to suggest it is a fourth generation language. The essence of 4GL's is that they indicate what to do, not how to do it. The essence of Forth is the explicit specification of how to do something. I think that one reason it took so long to get an answer to the permutation problem is that Forth does not lend itself to thinking algebraically. A better name for RPN is "arithmetic notation" as opposed to "algebraic notation." Forth does addition, subtraction, etc., the way we were taught to do when we learned the 3 R's. I know that I solved the permutation problem algebraically and then choreographed my solution into Forth. Forth's muse is Terpsichore, not Calliope -- every participating value must be on the stack in the right place at the right time. Busby Berkeley could have been a great Forth programmer. I'd like to see others' ideas of what the proper domain of Forth is. I'm especially eager to hear from John Wavrik. Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
dwp@willett.UUCP (Doug Philips) (07/27/90)
[BTW: I use all CAPITAL letters to indicate slight pause and slight added stress, not to indicate shouting. -dwp] In <1385.UUL1.3#5129@willett.UUCP>, W.BADEN1 [Wil] writes: > Forth may still be appropriate for such applications because of environmental > rather than linguistic reasons. Forth may be a good language to program > applications using operations for these things defined in another language, > e.g., assembler. I'm not sure what you mean by "linguistic" reasons. Do you mean that it is syntacticly simple, or that the stack orientation is too alien or ???? > It is ironic that Forth's name was chosen to suggest it is a fourth generation > language. The essence of 4GL's is that they indicate what to do, not how to > do it. The essence of Forth is the explicit specification of how to do > something. I've heard this before (probably from Wil). Everytime I heard it I was annoyed, but didn't know why. I think I now know why. Whether or not the why makes sense, I'm not sure yet, but I must disagree (albeit circuitously) with Wil on this point. Any conventional computer language is at some point going to have to say "how to do it". For example, consider SmallTalk. Everything in SmallTalk is done by sending messages to objects and getting some other object to do your work for you. (Almost... I realize that there are some syntactic deviations from that, but not in the direction I think is important for this point.) BUT, eventually you have to stop sending messages and actually do something, like an addition operation. In SmallTalk that is done by the virtual machine as a "primitive". SmallTalk is much less flexible than Forth because of the complexity difference between its virtual machine (Messages, Objects, etc.) and the underlying implementation OF the virtual machine. Anyway, the point is that there must be something inside of a Forth implementation that does the "how" of addition, etc. as well. I don't think that that level of "how" is sufficient to unseat Forth from its claim to being a 4Th generation language. Forth is, as far as I can tell, the only language so flexible that you don't actually write your application in Forth, but you use Forth to write the language in which you write your application. Consider a hypothetical example: (Ignore screwy capitalization) 90 degrees Left Arm X Axis Rotate ( Pick another order for the arguments to Rotate if you think it would scan better ) When you have the system "grown" to the point where the user can type that line of code and have it actually happen, the Forth system has evolved into a "what" NOT a "how". If it were a "how" it would look more like (hypothetically, of course): 90 degrees ( -- stepper motor step count for 90 degree rotation ) 0 ( I don't have my Forth Books handy, so add a SWAP to get the ) ( DO params in the right order, if necessary ) DO 3 MOTOR STEP LOOP Anyway, thats my buck two fifty: Forth is a "what" not a "how" language builder. One might even argue that "DUP" is a "what" and not a "how" word, but I'll save that for a later note. -Doug --- Preferred: willett!dwp@hobbes.cert.sei.cmu.edu OR ...!sei!willett!dwp Daily: ...!{uunet,nfsun}!willett!dwp [in a pinch: dwp@vega.fac.cs.cmu.edu]
ForthNet@willett.UUCP (ForthNet articles from GEnie) (07/30/90)
Category 3, Topic 35 Message 129 Sun Jul 29, 1990 W.BADEN1 [Wil] at 17:21 PDT Replying to Doug replying to me, > In <1385.UUL1.3#5129@willett.UUCP>, W.BADEN1 [Wil] writes: > > > Forth may still be appropriate for such applications because of > > environmental rather than linguistic reasons. Forth may be a good > > language to program applications using operations for these things > > defined in another language, e.g., assembler. The first point that I was trying to make is merely that your environment may restrict your choice of languages, e.g. 68HC11. The second point is that after an uncongenial procedure has been implemented in whatever it takes, Forth may be excellent to invoke that procedure. > > It is ironic that Forth's name was chosen to suggest it is a fourth > > generation language. The essence of 4GL's is that they indicate what to > > do, not how to do it. The essence of Forth is the explicit specification > > of how to do something. (You never heard or saw me state that Forth was a fourth generation language.) The distinction of "How to" versus "What to" is more commonly expressed as Procedural versus Non-procedural. All languages have elements of both. As Doug points out, > Any conventional computer language is at some point going to have to > say "how to do it". The purpose of subroutines is to package "What to" whatever the language. The level of a language is a measure of how much has already been piled up for you, or conversely how much you have to pile up to do what you want to do. In this ordering Forth clearly stands between Asm and C. > Forth is, as far as I can tell, the only language so flexible that > you don't actually write your application in Forth, but you use > Forth to write the language in which you write your application. All sufficiently powerful languages have this ability. This is the way applications are programmed in every language. What Forth shares with Lisp and APL is the ability to grow into your application. (Tell me, does SmallTalk have this too?) "Everthing should be programmed from the top down -- except the first time." As an application is built, every component should be checked. With conventional development this means that scaffolding must be rigged for each component. This scaffolding, which may become much larger than the final appplication, is thrown away. Forth's mode of development reduces and often eliminates scaffolding. > When you have the system "grown" to the point where the user can > type [a program invocation] and have it actually happen, the > Forth system has evolved into a "what" NOT a "how". Agreed. This is what applications are for. Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or willett!dwp@hobbes.cert.sei.cmu.edu
dwp@willett.UUCP (Doug Philips) (08/02/90)
In <1429.UUL1.3#5129@willett.UUCP>, W.BADEN1 [Wil] writes: > The purpose of subroutines is to package "What to" whatever the language. The > level of a language is a measure of how much has already been piled up for > you, or conversely how much you have to pile up to do what you want to do. In > this ordering Forth clearly stands between Asm and C. Hmmm. I don't quite follow this here. I would be more inclined to put C and Forth at about the same level. If you look at the language itself and not the libraries. I say that because while PD or ShareWare versions of Forth are pretty bare bones, so are most PD or ShareWare C's. As a side note, it tickles me to see the ratio of PD/ShareWare Forths to C's versus the ratio for commercial products. Anyway, from the ads I've seen, the libraries available for Forth are comparable to those available for C. The real issue is, I think, the language itself. Both C and Forth provide basic "machine" types. C provides structures/unions which most PD Forth's don't; I don't know if commercial systems do or not. C and Forth provide the same style of looping and branching constructs, with, perhaps, the exception of C's "switch", but again, I don't know about commercial Forth's. C provides global, module and block scoping. Forth has vocabularies. Commercial Forth's may have locals (like block scoping). C is traditionally compiled, but interpreters are becoming available. Forth is traditionally interpreted, but subroutine threading is often available. C defers I/O to the runtime library. Forth has it built in. C defers memory management to the runtime library. Forth has some memory management built in. C often lets you escape to machine code with "asm()" statements. Forth has ;CODE. C has separate compilation. Forth has vocabularies, but that isn't really the same thing. Forth's ability to drop into assembly code allows one to interface with other languages. I don't know how common this is with commercial systems. I think I hit all the main points (until I irrevocably send off this message anyway!). The point I'm trying to make is that although one might technically rate C higher on the basis of the above comparison, I would argue that Forth is not clearly between C and ASM. I would say that it is more more clearly close to C. > All sufficiently powerful languages have this ability. This is the way > applications are programmed in every language. What Forth shares with Lisp > and APL is the ability to grow into your application. (Tell me, does > SmallTalk have this too?) I've not written much SmallTalk, but the literature seems to support that view. Rapid prototyping, interpreted self-modifying system. etc. > As an application is built, every component should be checked. With > conventional development this means that scaffolding must be rigged for each > component. This scaffolding, which may become much larger than the final > appplication, is thrown away. Forth's mode of development reduces and often > eliminates scaffolding. Forth is losing this advantage. There are products available for interpreting C code. Often they are billed with the same advantages that the Forth environment has, plus the advantage of "compiling" the production version of the code to "recover" the traditional speed advantage. Lisp, Forth, Smalltalk, APL and probably others I don't even know about, all provide a nice interactive environment for prototyping and development. Forth is the only one (maybe APL too) that can do so in very spartan quarters. That environmental economy is a *second* order effect of the Forth philosophy, not a *first* order one. As resources become cheaper Forth will have to rely more on its *first* order attributes in order to retain/attain superiority or popularity. -Doug --- Preferred: willett!dwp@hobbes.cert.sei.cmu.edu OR ...!sei!willett!dwp Daily: ...!{uunet,nfsun}!willett!dwp [in a pinch: dwp@vega.fac.cs.cmu.edu]
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/13/90)
Category 3, Topic 35 Message 130 Sun Aug 12, 1990 W.BADEN1 [Wil] at 09:35 PDT congratulations to mitch bradley on being the first person to offer what i agree is readable forth code if everyone wrote code the way mitch has shown then forth would not have the reputation of being "write only" any improvement i can make will be marginal and moot others have uploaded further examples of readable forth and i will comment on them later mitch has recognized the obvious fact about forth readability you can't understand what the code does if you don't know what's on the stack the obvious way to handle this is: make sure there's never any question as to what's on the stack mitch has done this as well as telling in plain english what the intent of the code is i hope that if you have read this far you can see another way in which readability can be improved the distinction between upper and lower case was introduced to make writing more readable all lower case is easier to read than all upper case but mixed upper and lower is still better most languages also use punctuation marks to improve readability let's rewrite the beginning of this as it should be done in plain english Congratulations to Mitch Bradley on being the first person to offer what I agree is readable Forth code. If everyone wrote code the way Mitch has shown then Forth would not have the reputation of being "write only". Any improvement I can make will be marginal and moot. Others have uploaded further examples of readable Forth and I will comment on them later. Mitch has recognized the obvious fact about Forth readability. You can't understand what the code does if you don't know what's on the stack. The obvious way to handle this is: Make sure there's never any question as to what's on the stack. Mitch has done this as well as telling in English what the intent of the code is. It is curious that Forth programmers are typically Proud To Be Different and deprecate C, yet many blindly imitate old-fashioned C style. Contemporary C programming is groping toward a significant use of mixed upper and lower case. C programming can be more tolerant of monocase because it has punctuation marks to clarify syntax (parens, commas, brackets, semicolons). Modern languages of Western civilization using a Latin, Greek, or Cyrillic alphabet normally begin complete thoughts with an upper case letter, and terminate them with a full stop, question mark, or exclamation mark. Forth does not have punctuation marks and uses extra spacing and subordination instead. A convention that I believe makes for more readable code is: ALL UPPER CASE for standard and would-be standard words. First Letter Upper Case for new words not expecting anything on the stack. first letter lower case for new words expecting something on the stack. \ Comments in proper English syntax with final punctuation. Extra spacing shows stack state is the same as previously indicated. If the stack state at extra spaces for phrasing is different from the previously indicated state there should be a stack comment. This results in complete thoughts beginning with upper case, and modifying phrases separated by extra spacing. Some other convention may work as well, but if Forth code is to be readable with adequate comments the present trend to all lower case must be cured. In an application the names of new words should all be distinct ignoring case. E.g., don't define "glean" and "Glean". Mitch's examples are very readable and my improvement is minuscule. Nonetheless there was room for improvement. Some readers may recall my 1970 "Principle of Mutual Superiority." Anything you do I can do better. Anything I do you can do better. Anything I do I can do better. Anything IBM does will cost more money. The last was revised in 1989 to Anything IBM or Apple does will cost more money. Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/13/90)
Category 3, Topic 35
Message 131 Sun Aug 12, 1990
W.BADEN1 [Wil] at 09:39 PDT
\ Examples of readable Forth by Mitch Bradley as edited by Wil Baden.
\ CATCH/THROW Error Handling Wordset.
\ This implementation uses the non-standard words SP@ , SP! , RP@ , and
\ RP! . These words, or their equivalents, are present in most systems.
\ Thanks to Don Colburn and Dean Sanderson for implementation suggestions.
VARIABLE Handler \ Most recent error handler (should be a USER variable).
: CATCH ( cfa -- error#, or 0 )
( cfa ) \ Return address is already on the stack.
SP@ >R ( cfa ) \ Save data stack pointer.
Exception @ >R ( cfa ) \ Previous handler.
RP@ Handler ! ( cfa ) \ Set current handler to this one.
EXECUTE ( ) \ Execute the word passed in on the stack.
R> Handler ! ( ) \ Restore previous handler.
R> DROP ( ) \ Discard saved stack pointer.
0 ( 0 ) \ Signify normal completion.
;
: THROW ( ??? error# -- ??? error# ) \ Returns in saved context.
?DUP IF ( err# )
Handler @ RP! ( err# ) \ Return to saved return stack context.
R> Handler ! ( err# ) \ Restore previous handler.
\ Remember error# on return stack before changing data stack pointer.
R> SWAP >R ( saved-sp ) \ err# is on return stack.
SP! ( ) R> ( err# ) \ Change stack pointer.
\ This return will return to the caller of catch, because the return
\ stack has been restored to the state that existed when CATCH began
\ execution.
THEN ( err# )
;
Another readable code submission:
\ LEFT-PARSE-STRING ( adr len char -- adra lena adrb lenb )
\ Splits a string into two halves around a delimiter character.
\ If the delimiter character is present in the string, adra lena is the
\ substring after the first occurrence of the character, adrb lenb
\ is the substring before it.
\ Both substrings exclude the character itself.
\
\ If the character is not present in the string, the original string
\ adr len is returned, and the flag on top of the stack is false.
\ Removes max(n,len) characters from the beginning of the string "adr len".
: /string ( adr len n -- adr+len adr-len )
OVER MIN >R ( adr len) SWAP ( len adr ) R@ + SWAP ( adr len ) R> -
;
( Another definition.)
: /string ( adr len n -- adr+len adr-len )
OVER MIN 2>R ( adr ) R@ + 2R> ( adr len n ) -
;
: +string ( adr len -- adr len+1 ) 1+ ;
: -string ( adr len -- adr+1 len-1 ) >R ( adr ) 1+ R> ( adr len ) 1- ;
\ adra,lena is the string after the delimiter.
\ adrb,lenb is the string before the delimiter.
\ lena = 0 if there was no delimiter.
: left-parse-string ( adr len char -- adra lena adrb lenb )
>R ( adr len ) OVER 0 ( adra lena adrb lenb ) 2SWAP ( adrb lenb adra lena
)
\ Throughout the loop, we maintain both substrings. Each time through,
\ we add a character to the first string and remove it from the second.
\ The loop terminates when either the second string is empty or the
\ desired character is found.
BEGIN DUP WHILE ( adr0 len0 adr1 len1 )
OVER C@ R@ = IF \ Found it; exchange strings.
R> DROP -string 2SWAP ( adra lena adrb lenb )
EXIT
THEN ( adr0 len0 adr1 len1 )
2>R ( adr0 len0 ) +string 2R> ( adr0 len0 adr1 len1 )
-string ( adr0 len0 adr1 len1 )
REPEAT ( adr0 len0 adr1 len1 )
\ Character not found. len1 is 0.
2SWAP ( adra lena adrb lenb )
R> DROP
;
-----
This message came from GEnie via willett through a semi-automated process.
Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/13/90)
Category 3, Topic 35 Message 133 Sun Aug 12, 1990 W.BADEN1 [Wil] at 13:54 PDT Another candidate for readable Forth was: : |x| ( x - clippedx ) ( clip x to left edge of screen and one screen less than edge on the right ) maxx viewwidth - min 0max ; There's no doubt that to the author this is very readable, because the author knows the meaning of all constituent words and how they are used. A good Forth programmer who doesn't know the meaning of constituent words can analyze the code and make reasonable guesses, which for this definition luck out. Thus the code is decipherable but I would not call it readable. Let's show how the analysis might proceed. We are told that at the end "clippedx" is left on the stack. maxx viewwidth - min 0max ( clippedx) ; "0max" is a would-be standard word whose meaning is known. It may change the value of the top stack element, but it leaves the state status unchanged. maxx viewwidth - min ( clippedx) 0MAX ; "min" is a standard word whose meaning is known. Its stack effect is ( n1 n2 - - n3). n3 is clippedx, and we make the reasonable guess that n1 is x. maxx viewwidth - ( x n2) MIN ( clippedx) 0MAX ; The stack effect of "viewwidth" is unknown. The "view" part suggests that it displays something, but a luckier guess is that it behaves like a constant. This moves the stack comment left. Extra spacing is left to show that the stack status recurs. maxx ( x n2) ViewWidth - MIN ( clippedx) 0MAX ; A reasonable guess is that "maxx" also behaves like a constant. This gives a better stack comment. MaxX ( x xLimit) ViewWidth - MIN ( clippedX) 0MAX ; The analysis would be much easier if the definition is written: : |x| ( x -- clippedX ) ( Clip x to left edge of screen and one screen less than edge on the right. ) MaxX ( x xLimit) ViewWidth - MIN ( clippedX) 0MAX ; The definition would be even a little more readable if it had a name something like "clipX" or "xClipped". (Is the hornet's nest still stirring?) ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/16/90)
Date: 08-13-90 (06:40) Number: 3644 (Echo) To: ALL Refer#: NONE From: GORDON GANDERTON Read: (N/A) Subj: C OR FORTH Status: PUBLIC MESSAGE Feeling the pressure, I decided to get back into learning C using TurboC, which I must admit has a very attractive environment. While doing the exercises form Turbo C Programming for the IBM, it occurred to me that I could do them a lot easier using Forth and its a lot more fun. I got stuck on chapter 3, ex3 at end of chapter though and was about to return to C but then wondered if anyone has the answer in Forth to this one: 3. Write a program that repeatedly calculates how many chars separate two letters typed in by the user, until terminated with ctlC. For instance there are 2 characters ('b' and 'c') between 'a' and 'd'. Take advantage of the fact that the arithmetic operators work on character variables just as well as they do on numbers. Rgds. --- ~ EZ-Reader 1.20 ~ NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/16/90)
Category 3, Topic 35 Message 135 Wed Aug 15, 1990 D.RUFFER [Dennis] at 23:18 EDT Re: GORDON GANDERTON > 3. Write a program that repeatedly calculates how many chars > separate two letters typed in by the user, until terminated with > ctlC. For instance there are 2 characters ('b' and 'c') between > 'a' and 'd'. Take advantage of the fact that the arithmetic > operators work on character variables just as well as they do on > numbers. Rgds. I don't understand the question Gordon. What letters are typed in by the user, the 'a' and 'd' or the characters in between, and what gets terminated by ctlC? If I know what the deliminating characters are and I have gotten the string into memory, then the problem is simply searching from the start of the string for the left deliminator and from the end of the string for the right one. Then you simply subtract the addresses. That part seems trivial, but I'm confused about where the string and deliminators come from. DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/16/90)
Date: 08-14-90 (20:24) Number: 3650 (Echo) To: W.BADEN1 [WIL] Refer#: 3632 From: GORDON GANDERTON Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE WW> make sure there's never any question as to what's on the stack I notice some Forths (ie, Abundance) automatically put the date at eol of top line. Could a similar sort of thing be used to auto put contents of stack at end of each line (if space there of course). by using the .S word? Then you would always know what's on stack and .S is none destructive so it wouldnt change stack contents. Rgds. --- ~ EZ-Reader 1.20 ~ NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/17/90)
Category 3, Topic 35 Message 137 Thu Aug 16, 1990 W.BADEN1 [Wil] at 18:27 PDT \ More Readable Ebcdic to Ascii Conversion 07/10/90 \ There is NO error checking in this code. It is assumed \ that only VALID ebcdic codes are input. \ \ This code is placed in the public domain. \ Letters & Numbers 07/10/90 HEX : do-letters ( ebcdic --- ascii ) \ For letters only. 0080 - DUP 0049 > ( i.e. "J".."Z" ?) IF 7 - DUP 0052 > ( i.e. "S".."Z" ?) IF 8 - THEN THEN ; : do-alphanumerics ( ebcdic --- ascii ) \ For letters & numbers. DUP 00EF > ( i.e. "0".."9" ?) IF 00C0 - ELSE do-letters THEN ; DECIMAL \ Symbols 07/10/90 HEX CREATE Symbols \ Conversion table for special characters. 20 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 2E C, 3C C, 28 C, 2B C, 7C C, 26 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 21 C, 24 C, 2A C, 29 C, 3B C, 7E C, 2D C, 2F C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 2C C, 25 C, 5F C, 3E C, 3F C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 00 C, 3A C, 23 C, 40 C, 27 C, 3D C, 22 C, : ebcdic>asciI ( ebcdic --- ascii ) DUP 00C1 < ( i.e. special character ?) IF 0040 - Symbols + C@ ELSE do-alphanumerics THEN ; DECIMAL : test ( c --- ) ebcdic>ascii DUP EMIT SPACE . ; The most readable *algorithm* would be CREATE AsciiTable HEX 00 C, ... (256 Byte Conversion Table) ... DECIMAL : ebcdic>asciI ( ebcdic --- ascii ) AsciiTable + C@ ; This would also take care of lower case values. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/17/90)
Category 3, Topic 35 Message 138 Thu Aug 16, 1990 W.BADEN1 [Wil] at 18:31 PDT JOHN WAVRIK has supplied an example of vintage Forth in the FigForth dialect that defies understanding. John comments: >[I notice in reproducing it that the programmer forgot to deal with the >case in which the user types in something other than HIGH, LOW or >RIGHT.] The technique of manifesting the stack reveals that the programmer did indeed deal with that case. It's still an example of bad Forth coding style, but now the logic can be followed and understood. ( Guessing Game Program 2A ) 10 $VARIABLE Answer : Game BEGIN ( ) 0 101 ( lo hi) BEGIN 2DUP + 2/ ( lo hi guess) CR ." I guess " DUP . CR BEGIN ." Is that high, low, or right?" In$ Answer $! Answer $" HIGH" $compare 0= IF SWAP DROP ( lo hi) 0 1 ELSE ( lo hi guess) Answer $" LOW" $compare 0= IF ROT DROP SWAP ( lo hi) 0 1 ELSE ( lo hi guess) Answer $" RIGHT" $compare 0= IF CR ." I got it." DROP 2DROP ( ) BEGIN ( ) CR ." Play again (Y or N)?" KEY ( c) DUP 78 ( ie "N") = IF DROP ( ) 1 1 1 1 ( again 1 1 1) ELSE (c ) 89 ( ie "Y") = IF ( ) 0 1 1 1 ( again 1 1 1) ELSE ( ) 0 ( 0) THEN THEN ( 0, or again 1 1 1) UNTIL ( again 1 1) ELSE ( lo hi guess) CR 0 ( lo hi guess 0) THEN THEN THEN ( again 1 1, or lo hi 0 1, or lo hi guess 0) UNTIL ( again 1, or lo hi 0) UNTIL ( again) UNTIL ; JOHN's re-writing of the program is a masterful use of Forth, and little can be done to improve upon it. My only cavil is that the stack state is not explicitly given and traced in the definition of "GUESS". And of course, narrative comments should be properly punctuated. ( Guessing Game Program 3A ) VARIABLE Ll VARIABLE Hh ( Low and high for current range. ) VARIABLE Gg ( Current guess. ) : Guess ( -- ) Ll @ Hh @ + 2/ ( midpt: Guess midpoint of range ) DUP Gg ! ( '' and save it.) CR ." I guess " . ( ) ." Is that LOW, HIGH, or RIGHT ?" ; : GAME 0 Ll ! 101 Hh ! Guess ; : HIGH Gg @ Hh ! Guess ; ( Take lower half of range. ) : LOW Gg @ Ll ! Guess ; ( Take upper half of range. ) : RIGHT CR ." Wow, I got it." ; John has shown that one technique for readable Forth is to mop up the stack in every line. He has also shown the expressive power of an interactive language with a workspace or a language with persistent objects. Lisp, APL, ABC, Eiffel and (I'm told) REXX and the Korn shell can do likewise. (Yes, John, I'd like to see your comparison of Forth and the algebra languages.) Procedamus in pace. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/18/90)
Date: 08-15-90 (14:45) Number: 3654 (Echo) To: W.BADEN1 [WIL] Refer#: 3632 From: NICK JANOW Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE >Will Baden's convention for more readable code: >ALL UPPER CASE for standard and would-be standard words. I've been doing that. >First Letter Upper Case for new words not expecting anything on the stack. >first letter lower case for new words expecting something on the stack. I was doing something like that. I used lower case for variables, locals and other words which had the stack effect of ( -- something ). I used first letter upper case words--or mixed upper case ( ie. SearchForThis$) for words using something from the stack. I'd gradually arrived at this to improve readability, but I hadn't considered it as a convention for stack documentation so I wasn't quite consistent in applying it. I'd used first letter uppercase for words that the user would see. Is "First Letter Upper Case for new words not expecting anything on the stack. first letter lower case for new words expecting something on the stack." common convention or a personal convention? I prefer the opposite convention, but if your convention is widely used, I should change now before my habits become too deeply ingrained. >\ Comments in proper English syntax with final punctuation. >Extra spacing shows stack state is the same as previously indicated. I often use long names and indent control structures: BEGIN DUP SearchForThis$ nthEntry ! \ so stack coments often run off the line. I prefer to use terse \ comments to comments that go onto the next line. I've been relying on decomposition and descriptive names to improve readability. My comments are mostly on the order of "\ 1+ to skip string count byte", for those times when names and stack comments wouldn't help. I use several techniques to improve readability: mixed capitalization, decomposition and descriptive names, stack and descriptive comments where necessary, indenting, spacing and putting one thought per line. I do need to apply comments more frequently though. I'm beginning to appreciate stack comments within a word, even if they seem an unnecessary bother while I'm writing the code. The more I use them, the less I mind the exercise. "I know what this does; I don't need to make a stack comment! ...Uh, I think I know what it does...What _does_ this do?" :-) NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/20/90)
Category 3, Topic 35 Message 140 Sat Aug 18, 1990 W.BADEN1 [Wil] at 22:34 PDT Gordon Ganderton, Although easy to do (see my 1985 FORML Pretty Phraser), pretty printing with indication of stack depth is not as satisfying as doing it yourself. The values on the stack correspond to the variables in profane languages, and stack indications should have meaningful names for the values. The result of automatic indication would be like programs in Basic with single letters for names of variables, only worse. Forth programs put values on the stack, and take them off. You can make a chart showing the rise and fall of the stack depth. When the chart hits a valley either the values on the stack represent the same things they did earlier, or the individul values represent something new. In either case there should be some stack comment, or extra space if the it's the same as at the previous stack comment. If a valley is not as low as the previous valley, you are probably missing a stack indication. If one stack status predominates after initial instructions setting it up, as it usually happens, but there is a section in the middle with a different status, that is a strong suggestion to consider factoring out that section. A good test for readability is to read the definition backward, last line first. If you can understand what each line does from stack comments previously given without having to mentally execute the code, then the definition qualifies for consideration as readable. There will always be someone who disagrees, though. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/20/90)
Category 3, Topic 35 Message 141 Sat Aug 18, 1990 W.BADEN1 [Wil] at 22:35 PDT Nick Janow, The convention of Initial Capital Not Expecting Anything On The Stack, and initial minuscule expecting something, is analogous to natural language. Forth "sentences" have a syntax similar to classical Latin, or to Japanese -- subject and object first, verb last. "Johannes Mariam amat," not "johannes mariam Amat." Thus complete thoughts in Forth, i.e., sentences, will begin with a capital letter, and the last word, which will be like a verb, will be lower case. E.g., "Buffer 80 expect", "Name count type" Forth words with stack effect ( -- ) should begin with a capital because they are complete one-word sentences. Note that they should be followed by extra-space because the stack status will be the same as it had been. Another precedent is that English used to and German still does capitalize all nouns as well as the first letter of a sentence. Words that do not expect anything on the stack are like nouns or are one-word sentences. Pascal and C should observe the opposite convention because of their syntax for complete statements other than assignment statements. Seven years of experimentation has convinced me that this convention yields better looking code. There will always be someone who disagrees, though. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/21/90)
Date: 08-18-90 (11:40) Number: 3667 (Echo) To: DENNIS RUFFER Refer#: 3656 From: GORDON GANDERTON Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE DR>I don't understand the question Gordon. What letters are typed in by the I took the question verbatim from the text. Here is my effort so far. \ c3ex3.seq - calcs # of letters between input letters variable CHARS1 variable CHARS2 : userenters ." enter two letters " ; : getfirst KEY CHARS1 ! ; : getsecond KEY CHARS2 ! ; : getcharsback chars1 @ . chars2 @ . ; : doit userenters getfirst getsecond getcharsback ; \ end of program. It's really a very simple program. I think you are thinking of it as more complex than what is required. The read out will be something like: HAL: Type in 2 letters DAVE: AG HAL: There are 6 Characters that separate the letters A and G. DAVE: ^C HAL: Thankyou Dave. Would you like a game of chess, now? I'm very good! I am trying to do all the problems in FPC from the Waite book TURBO C PROGRAMMING FOR THE IBM PC by Robert Lafore, to compare Forth and C. So far, I enjoy the Forth rendition but the TurboC shell sure is attractive. Tks and rgds. Gord. ~ EZ-Reader 1.20 ~ NET/Mail : British Columbia Forth Board - Burnaby BC - (604)434-5886 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/23/90)
Category 3, Topic 35 Message 143 Tue Aug 21, 1990 D.RUFFER [Dennis] at 23:23 EDT Re: GORDON GANDERTON > The read out will be something like: > HAL: Type in 2 letters > DAVE: AG > HAL: There are 6 Characters that separate the letters A and G. Well, if that is all there is to it, then it is simple: : TEST BEGIN CR ." Type in 2 letters " KEY KEY SWAP 2DUP - ABS CR ." There are " . ." characters that seperate the letters " EMIT ." and " EMIT AGAIN ; However, I again didn't try it, so if it works it's a surprise to me. <grin> DaR P.S. I don't know how F-PC handles the Break key, but in polyFORTH the ctrl-C will abort at either of the KEY's. ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/23/90)
Date: 08-20-90 (21:55) Number: 3678 (Echo) To: W.BADEN1 [WIL] Refer#: 3669 From: PAUL PRICE Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE So, when do you write the book with this wealth of "style". I'd really like to see it all together, rather than in little pieces/parts on the BBS.. Paul Price NET/Mail : LMI Forth Board, Los Angeles, CA (213) 306-3530 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/27/90)
Date: 08-23-90 (08:01) Number: 3691 (Echo) To: DENNIS RUFFER Refer#: 3684 From: JONAH THOMAS Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE -> : TEST BEGIN CR ." Type in 2 letters " -> KEY KEY SWAP 2DUP - ABS -> CR ." There are " . -> ." characters that seperate the letters " -> EMIT ." and " EMIT AGAIN ; I think it should work, but you should subtract 1 -- 2DUP - ABS 1- to account for the last letter 'counting itself'. I wonder if we really understand this problem? Does it matter about upper and lower case? Oh well.... NET/Mail : The MATRIX (5 Nodes/1.2 Gig) Birmingham, AL (205) 323-2016 Date: 08-23-90 (19:17) Number: 3692 (Echo) To: DENNIS RUFFER Refer#: NONE From: JONAH THOMAS Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE Oops! I was in the shower when I realized that that fix wouldn't work. ABS 1- works for everything except 0 -- when the 2 letters are the same. Then it fails. Maybe ABS DUP 0= + 1- would be better. Funny how much harder it is to do these things as thought problems. Sitting at a keyboard, you'd find the bugs really fast. I met a Fortran programmer last weekend who was kind of indignant that people don't any more think out the whole program before they write any of it, and didn't know quite what to say to him.... NET/Mail : The MATRIX (5 Nodes/1.2 Gig) Birmingham, AL (205) 323-2016 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (08/29/90)
Category 3, Topic 35 Message 147 Tue Aug 28, 1990 D.RUFFER [Dennis] at 00:59 EDT Re: JONAH THOMAS > think out the whole program before they write any of it or try to fix something that ain't broke. <grin> > Maybe ABS DUP 0= + 1- would be better. No, I believe the original is correct. There are 0 characters seperating A and A and 1 character seperating A and B. Your "fix" eliminates this distinction. > Does it matter about upper and lower case? It depends on if you are a C programmer or if you believe that computers really can tell the difference. <smile> DaR ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us
ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) (09/03/90)
Date: 08-25-90 (14:28) Number: 3711 (Echo) To: DENNIS RUFFER Refer#: NONE From: IAN WATTERS Read: NO Subj: PUZZLES AND PROBLEMS Status: PUBLIC MESSAGE DRpWell, if that is all there is to it, then it is simple: DRp DRp: TEST BEGIN CR ." Type in 2 letters " DRp KEY KEY SWAP 2DUP - ABS DRp CR ." There are " . DRp ." characters that seperate the letters " DRp EMIT ." and " EMIT AGAIN ; DRp DRpHowever, I again didn't try it, so if it works it's a surprise to me. Yep, it gives one too many "between" if they aren't the same... You also don't need the swap (except to EMIT in the same order as they came in) Ian PCRelay:IBBSNET -> #143 RelayNet (tm) NET/Mail : DC Information Exchange, MetroLink Int'l Hub. (202)433-6639 ----- This message came from GEnie via willett through a semi-automated process. Report problems to: uunet!willett!dwp or dwp@willett.pgh.pa.us