Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 12:03 20 Apr 2024 Privacy Policy
Jump to

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 States
Posts: 324
Posted: 03:01pm 30 Nov 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8567
Posted: 03:10pm 30 Nov 2020
Copy link to clipboard 
Print this post

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: Canada
Posts: 1082
Posted: 06:05pm 30 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 324
Posted: 06:58pm 30 Nov 2020
Copy link to clipboard 
Print this post

  vegipete said  
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!

Neither did I. I thought you needed x,y coordinates. More careful reading for me!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5883
Posted: 08:23pm 30 Nov 2020
Copy link to clipboard 
Print this post

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 States
Posts: 324
Posted: 01:01pm 02 Dec 2020
Copy link to clipboard 
Print this post

  matherp said  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é


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 Kingdom
Posts: 8567
Posted: 02:12pm 02 Dec 2020
Copy link to clipboard 
Print this post

  Quote  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?

The CMM2 is part of the MMBasic family and the PRINT statement is the same in all versions.

  Quote  As for line numbers, I made my living for 42 years programming in BASIC and I ain't about to change now! :^)


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 States
Posts: 324
Posted: 02:45pm 02 Dec 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  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?

The CMM2 is part of the MMBasic family and the PRINT statement is the same in all versions.

  Quote  As for line numbers, I made my living for 42 years programming in BASIC and I ain't about to change now! :^)


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


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 States
Posts: 430
Posted: 04:09pm 02 Dec 2020
Copy link to clipboard 
Print this post

  Quote  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!
 Here is a suggestion.  Why don't you start your conversions and then post them here and ask others to try to modify them to uses the more modern and efficient forms and standards?  If your contributions would benefit from the performance gains and have utility for some users then maybe they will get that TLC and later from those examples you might learn how easy it is to convert your programs when needs be.   This is a community that chips in from my experience.  We are all here to enjoy the CMM2 and any contributions can add to that. I find that I learn from almost every bit of code that is posted.

Have a great day.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3649
Posted: 04:44pm 02 Dec 2020
Copy link to clipboard 
Print this post

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 States
Posts: 324
Posted: 04:49pm 02 Dec 2020
Copy link to clipboard 
Print this post

  mclout999 said  
  Quote  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!
 Here is a suggestion.  Why don't you start your conversions and then post them here and ask others to try to modify them to uses the more modern and efficient forms and standards?  If your contributions would benefit from the performance gains and have utility for some users then maybe they will get that TLC and later from those examples you might learn how easy it is to convert your programs when needs be.   This is a community that chips in from my experience.  We are all here to enjoy the CMM2 and any contributions can add to that. I find that I learn from almost every bit of code that is posted.

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 Kingdom
Posts: 8567
Posted: 04:57pm 02 Dec 2020
Copy link to clipboard 
Print this post

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
  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 States
Posts: 324
Posted: 05:11pm 02 Dec 2020
Copy link to clipboard 
Print this post

  JohnS said  
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 Kingdom
Posts: 3649
Posted: 05:41pm 02 Dec 2020
Copy link to clipboard 
Print this post

  toml_12953 said  
  JohnS said  
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.

  toml_12953 said  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 ...


The "traditional versions" vary a lot to the point where really it's almost meaningless to say they are traditional.

John
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024