Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : No Print Zones???
Author | Message | ||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
In almost every other version of BASIC, there are pre-defined print zones (usually four or five on a line) and a comma in a PRINT statement will advance to the next print zone. This isn't the case in MMBasic. Having print zones makes it much easier to align output simply since the print after the comma doesn't depend on the length of the item before the comma. Example: 10 FOR I=1 TO 100 20 PRINT I,SQR(I),I^(1/3),SIN(I),COS(I) 30 NEXT I will print nice, neat columns in the other BASICs but not in MMBasic. Would it be possible to implement print zones? Of course with MMBasic the number could vary depending on the screen mode but as long as the size of the print zones was constant, there should be no problem. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8567 |
Whether your idea is good or bad, the fact is that a change would break many existing programs so the answer is a definite no. Look at the @() function for how to format print output. 10 FOR I=1 TO 100 20 PRINT I,@(120)SQR(I),@(240)I^(1/3),@(360)SIN(I),@(480)COS(I) 30 NEXT I PS: line numbers are SO passé Edited 2020-12-01 01:10 by matherp |
||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1082 |
PRINT I,@(120)SQR(I),@(240)I^(1/3),@(360)SIN(I),@(480)COS(I) Oooo! Cool, I didn't know you could do that! Visit Vegipete's *Mite Library for cool programs. |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
Neither did I. I thought you needed x,y coordinates. More careful reading for me! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5883 |
You can always use TAB() FOR I=1 TO 100 PRINT I;TAB(5); SQR(I);TAB(20);I^(1/3);TAB(35);SIN(I);TAB(50);COS(I) NEXT I but it suffers from the same problems of most when the data length varies. I prefer STR$() as a means of getting well controlled readouts. FOR I=1 TO 100 PRINT STR$(I,4);STR$(SQR(I),4,6);STR$(I^(1/3),4,6);STR$(SIN(I),4,6);STR$(COS(I),4,6) NEXT I I never liked the old FORMAT command but that's another way. Lots of choices. Jim VK7JH MMedit  MMBasic Help |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
One of the underlying philosophies of BASIC has been, "Give the user a solution that is satisfactory most of the time. If the expert needs something fancier, let the expert do the extra work!" - Back to BASIC by John Kemeny and Thomas Kurtz pp. 11. Which looks more beginner friendly to you? 20 PRINT I,SQR(I),I^(1/3),SIN(I),COS(I) or 20 PRINT I,@(120)SQR(I),@(240)I^(1/3),@(360)SIN(I),@(480)COS(I) Do people programming for the CMM2 system really do that much columnar output that the CMM2 programs rely on comma being a tab? How many programs could it break? I'll bet there are a lot more BASIC programs that rely on print zones than ones that rely on a comma as a tab character. As for line numbers, I made my living for 42 years programming in BASIC and I ain't about to change now! :^) |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8567 |
The CMM2 is part of the MMBasic family and the PRINT statement is the same in all versions. Fine but be aware your programs will run slightly slower than they need as they are simply ignored unless used as gosub or goto targets. In the case of gosub or goto line numbers are many times slower than using a label |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
I have over 1500 BASIC programs that would need converting. The time that would take is much longer than any increased time my programs spend by using line numbers! How about this: OPTION COMMA [TAB | ZONE] with the default being TAB? Edited 2020-12-03 00:46 by toml_12953 |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 430 |
Have a great day. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3649 |
Converting 1500 suggests to me to make a program to do them one by one (akin to the transpiler discussed already). That idea works, BTW - used a converting program many years ago I know not how many times! My experience was that there are a surprising number of "minor" differences waiting to trip you up. John |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
Have a great day. Here's a simple one. It's a projectile program that was a mess originally. I rewrote it in a structured manner and eliminated the line numbers. The ZIP file includes both versions. Projectile.zip |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8567 |
OPTION BASE 0 DIM X(126),K(2) FUNCTION FNA(X,Y,Z) FNA=X*SIN(Y*0.01745329)*Z-16*Z^2 END FUNCTION DO LET F2=0 INPUT "MUZZLE VELOCITY AND ANGLE? "; M,A LET X(0)=0 FOR T=0.2 TO 25 STEP 0.2 LET L=INT(5*T+0.001) LET X(L)=FNA(M,A,T) IF X(L)<0 THEN EXIT FOR IF X(L)-X(L-1)<=0 AND F2=0 THEN IF X(L-1)-X(L-2)<X(L)-X(L-1) THEN LET K(1)=X(L-2) LET W4=T-0.4+J ELSE LET K(1)=X(L-1) LET W4=T-0.2+J END IF LET F2=1 FOR J=0.01 TO 0.2 STEP 0.01 LET K(2)=FNA(M,A,W4) IF K(1)-K(2)<=0 THEN EXIT FOR LET K(1)=K(2) NEXT J LET K1=MAX(K(1),K(2)) END IF NEXT T LET W=L-1 FOR J=0.01 TO 0.2 STEP 0.01 LET K(1)=FNA(M,A,T-0.2+J) IF K(1)<0 THEN EXIT FOR NEXT J PRINT "MAXIMUM HEIGHT IS ";K1;" FEET" LET Y=M*COS(A*0.01745329)*(T-0.2+J-0.01) PRINT "RANGE IS ";Y;" FEET" PRINT "TOTAL TIME AIRBORNE IS ";(T+J-0.01);" SECONDS" IF K1+14>60 THEN LET M1=1/(INT(K1/60+1)) PRINT "SCALE OF HEIGHT IS 1 SPACE = ";1/M1;" FEET" ELSE LET M1=1 END IF FOR D=1 TO 80 PRINT TAB(D+19);"+"; NEXT D PRINT " 0";TAB(20);"+" FOR N=1 TO W PRINT 0.2*N*M*COS(A*0.01745329);TAB(20);"+";TAB(X(N)*M1+20);"*" NEXT N INPUT "ANYMORE (YES OR NO)?";ANS$ LOOP WHILE ANS$="YES" END |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 324 |
My experience was that there are a surprising number of "minor" differences waiting to trip you up. John You can say that again! It's the minor differences that would prevent creating a program to do much of the work. The bulk of CMM BASIC is the same as traditional versions so no work would be needed. In some cases (see below) the difference can be bridged with a mechanical substitution but in others, not. Original: DEF FNA(X,Y,Z)=4*X^2-3*Y/Z Translation: FUNCTION FNA(X,Y,Z): FNA=4*X^2-3*Y/Z: END FUNCTION The above is simple for a program to change automatically. For print zones, single line PRINT statements aren't too bad, just use @((printzone-1)*120) but if the program depends on automatic line feeds, to get to the next print zone on the next line, it can get complicated. |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3649 |
My experience was that there are a surprising number of "minor" differences waiting to trip you up. John You can say that again! OK. I did it (years ago) and it worked. Cut a HUGE problem down to middling. The "traditional versions" vary a lot to the point where really it's almost meaningless to say they are traditional. John |
||||
Print this page |