GENTUT55.TXT General Tutorial for Lisa GJ2 Fic3 -- the f3 language explained as a series of tiny essays Written by Aristo Tacoma with L.A.H. Date: 2011:3:5 Numbers 01..99 in this series of gentutNN are circulated as needed, when more recently written articles make earlier ones unnecessary. Each article: copyright author, further distribution license the usual www.yoga4d.org/cfdl.txt. Kids: there are other tutorials for you. But you should find pieces here and there which are easy to read. In B9, use the search function, CTR-F or F4 within each. Beware ;-) This is written as a flow, quickly, and wherever there is a reference to concrete f3 syntax, it may have been written from memory and so not every word is guaranteed to be written here exactly correct. Search up with the CTR-F and repeated search CTR-L in the F3DOCS manual or in example programs if things here are not clear enough or precise enough for your present purposes. Good luck!!! ***HOW TO DO STRUCTURED PROGRAMMING WELL When you instruct the computer to do something which is intensely repetitive, you naturally want to find a snappy way to express it. In that way, you look at it, see if you can find a structure, and instruct the computer to repeat this structure. This is, vaguely, what structured programming is all about. We can add a further point about what structured programming is about: it is making the hierarchy -- a simple structure -- of each of your functions stand out as clearly as you like. So for instance, let us conjure up an kind of example in which there is not much of structured programming: (LET FUNC5 :********** POPS }You just gave} POPS :********* POPS >N1 N1 POPS :********** POP }to this function, and multiplied} POP }by itself 3 times is} POPS :********** POPS N1 ONE MUL N1 MUL POPS :********** POP }and five times is} POPS :********** POPS N1 ONE MUL N1 MUL N1 MUL N1 MUL POPS :********** POP }and by itself 8 times is} POPS N1 ONE MUL N1 MUL N1 MUL N1 MUL N1 MUL N1 MUL N1 MUL POPS :********* POP }and the POWER function, indeed, with 8, gives} POPS N1 8 POWER POPS :********* POP OK) (LET TRYIT BE }TYPE A SMALL WHOLE NUMBER:} POPS READLN FUNC5 OK) (LET AUTOSTART BE }TYPE TRYIT NOW!} POP OK) Note that the POPS and the POP both work in text mode, when GJ-ON nor when LogoLike mode, or LineLoving mode, or LoL mode or whatever, while DONE-GRAPHICS can be used if you want to check variable values after doing a graphics program instead of GJ-DONE, for DONE-GRAPHICS allows it to stay in programming mode without exiting.) In addition, it is a good convention to throw in some (( LOOKSTK )) lines which reports, during reading in of the program text, whether there is anything extra (usually unintended) left on the stack, and a similar function is carried out by both GJ-ON and RAM-REFRESH on completing the program. Doing manual check with such routines as STK and RICHSTK is valuable when one tries programs such as above, to see that e.g. no extra N1 is put in. If you put the above inside a file called e.g. TEST6 it and produces a neat result. You type TRYIT several times and type XO when done testing it. Technically the program is flawless. However to do good meaningful programming which satisfy your deeper spirits so that you can trulyc all it first-hand, -- psychologically easy to modify, to expand, to think about, then, at least when it is part of something larger, you rather want something like this -- which contains independently useful structures that you can apply for other things as well, when you expand on the program: (LET STARLINE BE (( )) (( (( :*********** => POPS )) )) OK) (LET MUL-MANY BE (( >N2 >N1 )) (( (( N2 ; N1 => DEC (COUNT (( ; N4 => MUL ; )) COUNTUP) ; => => )) )) OK) (LET FUNC5 BE (( >N1 )) (( (( STARLINE ; }You just gave} => POPS ; STARLINE )) (( N1 => POPS ; STARLINE ; CRLN ; (( }to this function, and multiplied} => POP )) (( }by itself 3 times is} => POPS ; STARLINE )) (( 3 ; N1 => MUL-MANY => POPS ; STARLINE ; CRLN ; (( }and five times is} => POPS )) (( STARLINE ; 5 ; N1 => MUL-MANY => POPS ; STARLINE ; CRLN )) (( }and by itself 8 times is} => POPS )) (( 8 ; N1 => MUL-MANY => POPS ; STARLINE ; CRLN )) (( }and the POWER function, indeed, with 8, gives} => POPS )) (( N1 ; 8 => POWER => POPS ; STARLINE ; CRLN )) )) OK) (LET TRYIT BE (( )) (( (( }TYPE A SMALL WHOLE NUMBER:} => POPS )) (( READLN => FUNC5 )) )) OK) (( LOOKSTK )) (LET AUTOSTART BE }TYPE TRYIT NOW!} => POP OK) Note that the program is technically longer -- ie, it has more characters, but it is psychologically shorter, in the sense of easier, simpler, once you have got used to this way of structuring things. The MUL-MANY has some semicolons and some arrows but these are but conventions, the actual nuts and bolts are the (COUNT and the MUL and the COUNTUP). The reason the N4 suddenly appears is that inside a (COUNT .. COUNTUP) any N2 outside of it becomes N4. The reason there is a DEC there, which decrements, or reduces by 1, is that when you want to have it multiplied by itself three times, then you naturally want the number multiplied by itself, and again multiplied by that number -- ie, two times. Because, when we speak this way, we typically tend to imply that multiplied by itself is something we speak of when the number of times is greater than 1, since 1 refers to the number itself. The CRLN suddenly arises on the scene -- put in a lineshift on the output -- because we singled out the routine STARLINE so that it all the time uses POPS rather than, as in the code above, sometimes POP. So we have to make up for those lacking lineshifts by putting in this extra CRLN. We also put in a (( LOOKSTK )) for good measure. On a couple of points, I have had some pleasure in reading some written talks by Larry Wall, a skilled programmer indeed, and he made a point out of saying that one shouldn't overdo structured programming. For sometimes it is clear enough for the purpose to just do copy and paste on the text editor, without one having to single out neat functions like this. I totally agree, -- if that is really the simplest, then that is the simplest, and in that sense then that is also the most structured. However, once a program grows, if you stick to conventions on having programs fairly hierarchical-looking each inside the function -- by the extra pair of blanks each time there is such as (COUNT -- and by singling out very repetitive phrases and making functions for them -- you get something which it is easy to work with. Fewer factors have to be balanced in the mind, you can focus on what you want the program to do rather than on having to hack into your own program to disentangle the mess on entirely trivial points, all the time. Nonetheless, even when you do structured programming also trivial programming things do arise -- lots of them -- but each of them can be quickly identified in mostly all cases when you build a program and gradually test and gradually expand. The caution one must make against structured programming is that one mustn't loose the sense of immediacy -- you mustn't make so abstract-sounding functions that the sense of you and the PC being good chums gets even slightly reduced. You are good chums and you share in good also often funny function names, and you are ot trying to prove that you can do abstract structures for the sake of somebody else. So first-hand programming is the more important concept, but structured programming in Lisa GJ2 Fic3, or f3, comes naturally in as part of it.