Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!rutgers!rochester!pt.cs.cmu.edu!dsl.pitt.edu!pitt!willett!ForthNet From: ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) Newsgroups: comp.lang.forth Subject: Vocabularies Message-ID: <1649.UUL1.3#5129@willett.pgh.pa.us> Date: 31 Aug 90 02:54:00 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 82 Category 18, Topic 92 Message 44 Thu Aug 30, 1990 D.RUFFER [Dennis] at 00:28 EDT Re: R.BERKEY [Robert] > IF( > c1 e1 > ... > ck ek > )IF > So, no. None of the posted solutions work. At least to the > problem for which a solution was sought. > Another closely related issue is whether comments are to be > allowed within the range of the custom compiler. I believe I could solve the multiple line problem easily (if it isn't already solved by using blocks), but adding comments does invalidate both Mitch's and my solutions (not to mention invalidating John's original solution). So, we just need to think about it a little more closely. (no one said it was going to be easy :-). What we really have here is a case statement and the "problem" is that John has typically written it without including "markers" to separate the cases. This organization makes it essentually impossible to put anything between the start of the case statements and the end except pairs of logical tests and execution phrases. The fact remains that John's code allows multiple lines and excludes intervening comments. Therefore I contend that my solution works just as well as his version, and Mitch's is probably also correct. However, since you have added an additional requirement to the problem, I will suggest an alternate solution. Even if I were to solve the problem without adhearing to the ANS Standard, I really don't see any way to add comments without adding in the missing markers. So, if you don't mind, I will change the format to allow the requirements to be satisfied. Here is the new format that I will try to implement CASE( ... OF ... ELSE ... OF ... ELSE . . . ... )CASE Now, without even looking at all the ways case statements have been implemented before, here is a way that will work within the standard: VARIABLE #CASES : CASE( 0 #CASES ! ; IMMEDIATE : )CASE BEGIN #CASES @ WHILE POSTPONE THEN -1 #CASES +! REPEAT ; IMMEDIATE : OF 1 #CASES +! POSTPONE IF ; IMMEDIATE Now, ain't that easy enough? Of course, there is the multi-user implications with using a variable to count the cases, but that can be easily solved by making the variable a stack. That would even allow nesting the case structures. Although this solution to John's problem does not look as "pretty", the added functionality more than makes up for the the loss of asthetics. Here is how John's original problem would look: : Perm ( n -- t ) DUP 2 = \ terminal condition IF DROP 1 ELSE DUP Next-Pos ( n pos ) CASE( Now, can I say again, YES IT DOES! 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