Path: utzoo!utgpu!news-server.csri.toronto.edu!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: PUZZLES AND PROBLEMS Message-ID: <1512.UUL1.3#5129@willett.pgh.pa.us> Date: 13 Aug 90 03:45:18 GMT Organization: String, Scotch tape, and Paperclips. (in Pgh, PA) Lines: 61 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