Post Reply 
HP Prime
08-31-2017, 07:50 AM (This post was last modified: 08-31-2017 07:53 AM by toml_12953.)
Post: #44
RE: HP Prime
(05-24-2015 07:07 PM)StephenG1CMZ Wrote:  Until reading such references to PPL being Pascal-like, I had assumed it was vaguely like BASIC - with many new features, but unfortunately without the GOTO - so I can forget typing in all those old BBC BASIC listings :-)

The old BASIC programs are easily converted to PPL, except for graphics statements perhaps. If the BASIC program was written in a straightforward manner, it's not a hard task. Below is one of the hardest challenges I've had. The example is from Problems for Computer Solution by Stephen J Rogowski. The BASIC is a mess but even that program was eventually translated with all the GOTOs spaghetti eliminated.

Original Program:
Code:
10 DIM X(126),K(2)
20 DEF FNA(X,Y,Z)=X*SIN(Y*0.01745329)*Z-16*Z^2
30 PRINT "INPUT MUZZLE VELOCITY (FT/SEC) AND ANGLE (DEGREES)"
40 LET F2=0
50 INPUT M,A
60 LET X(0)=0
70 FOR T=0.2 TO 25 STEP 0.2
80    LET L=INT(5*T+0.001)
90    LET X(L)=FNA(M,A,T)
100    IF X(L)<0 THEN GOTO 150
110    IF X(L)-X(L-1)<=0 AND F2=0 THEN GOTO 250 ELSE GOTO 350
120    LET K(1)=X(L-2)
130    LET W4=T-0.4+J
140    GOTO 280
150    LET W=L-1
160    FOR J=0.01 TO 0.2 STEP 0.01
170       LET K(1)=FNA(M,A,T-0.2+J)
180       IF K(1)<0 THEN GOTO 200
190    NEXT J
200    PRINT "MAXIMUM HEIGHT IS ";K1;" FEET"
210    LET Y=M*COS(A*0.01745329)*(T-0.2+J-0.01)
220    PRINT "RANGE IS ";Y;" FEET"
230    PRINT "TOTAL TIME AIRBORNE IS ";T+J-0.01;" SECONDS"
240    GOTO 360
250    IF X(L-1)-X(L-2)<X(L)-X(L-1) THEN GOTO 120
260    LET K(1)=X(L-1)
270    LET W4=T-0.2+J
280    LET F2=1
290    FOR J=0.01 TO 0.2 STEP 0.01
300       LET K(2)=FNA(M,A,W4)
310       IF K(1)-K(2)<=0 THEN GOTO 340
320       LET K(1)=K(2)
330    NEXT J
340    LET K1=MAX(K(1),K(2))
350 NEXT T
360 IF K1+11>60 THEN GOTO 470 ELSE LET M1=1
370 FOR D=1 TO 62
380    PRINT TAB(11+D);"+";
390 NEXT D
395 PRINT
400 PRINT "0";TAB(12);"+"
410 FOR N=1 TO W
420    PRINT ROUND(0.2*N*M*COS(A*0.01745329),4);TAB(12);"+";TAB(X(N)*M1+12);"*"
430 NEXT N
440 PRINT "ANYMORE (YES OR NO)";
450 INPUT A$ 
460 IF A$="YES" THEN GOTO 30 ELSE GOTO 500
470 LET M1=1/(INT(K1/60+1))
480 PRINT "SCALE OF HEIGHT IS 1 SPACE = ";1/M1;" FEET"
490 GOTO 370
500 END

PPL:
Code:
FNA(X,Y,Z)
BEGIN
  RETURN X*SIN(Y*0.01745329)*Z-16*Z^2;
END;

EXPORT PROJECTILE()
BEGIN
  LOCAL X,K,F2,W4,K1,ANS,M1,TMP;
  HFormat:=1; HDigits:=4; //Set number mode to Fixed 4
  X:=MAKELIST(0,C,0,126);K:=MAKELIST(0,C,0,2);
  PRINT();
  //REPEAT
    F2:=0;
    INPUT({M,A},"MUZZLE VELOCITY AND ANGLE",{"FT/SEC: ","DEGREES: "});
    X(0):=0;
    FOR T:=0.2 TO 25 STEP 0.2 DO
      L:=IP(5*T+0.001);
      X(L):=FNA(M,A,T);
      IF X(L)<0 THEN 
        BREAK;
      END;
      IF X(L)-X(L-1)<=0 AND F2=0 THEN
        IF X(L-1)-X(L-2)<X(L)-X(L-1) THEN 
          K(1):=X(L-2);
          W4:=T-0.4+J;
        ELSE
          K(1):=X(L-1);
          W4:=T-0.2+J;
        END;
        F2:=1;
        FOR J:=0.01 TO 0.2 STEP 0.01 DO
          K(2):=FNA(M,A,W4);
          IF K(1)-K(2)<=0 THEN 
            BREAK;
          END;
          K(1):=K(2);
        END;
        K1:=MAX(K(1),K(2));
      END;
    END;
    W:=L-1;
    FOR J:=0.01 TO 0.2 STEP 0.01 DO
      K(1):=FNA(M,A,T-0.2+J);
      IF K(1)<0 THEN 
        BREAK;
      END;  
    END;
    PRINT("MAXIMUM HEIGHT IS "+K1+" FEET");
    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 
      M1:=1/(IP(K1/60+1));
      PRINT("SCALE OF HEIGHT IS 1 SPACE = "+(1/M1)+" FEET");
    ELSE 
      M1:=1;
    END;
    TMP=TAB(14);
    FOR D:=1 TO 30 DO
      TMP:=TMP+"+";
    END;
    PRINT(TMP);
    PRINT("0"+TAB(14)+"+");
    FOR N:=1 TO W DO  
      PRINT(0.2*N*M*COS(A*0.01745329)+" +"+TAB(X(N)*M1)+"*");
    END;
    //INPUT({{ANS,[2]}},"ANYMORE (YES OR NO)?"); 
  //UNTIL UPPER(ANS) == "NO";
  HFormat:=0; // Set number mode back to Standard
END;

TAB Program:
Code:
EXPORT TAB(X)
BEGIN
  LOCAL I,T;
  T:="";
  FOR I:=1 TO X DO
    T:=T+" ";
  END;
  RETURN T;
END;

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP Prime - gbh - 08-30-2014, 02:44 AM
RE: HP Prime - Joe Horn - 08-30-2014, 04:20 AM
RE: HP Prime - gbh - 08-30-2014, 04:51 PM
RE: HP Prime - Tim Wessman - 08-31-2014, 02:33 PM
RE: HP Prime - lschroeder1947 - 08-31-2017, 09:59 AM
RE: HP Prime - DrD - 08-31-2017, 12:22 PM
RE: HP Prime - Hans S. - 08-31-2017, 08:49 PM
RE: HP Prime - lschroeder1947 - 09-01-2017, 10:26 AM
RE: HP Prime - sol740 - 08-30-2014, 08:32 PM
RE: HP Prime - eried - 08-30-2014, 09:32 PM
RE: HP Prime - Joe Horn - 08-30-2014, 10:04 PM
RE: HP Prime - walter b - 08-30-2014, 10:12 PM
RE: HP Prime - Joe Horn - 08-30-2014, 10:13 PM
RE: HP Prime - sol740 - 08-31-2014, 09:58 AM
RE: HP Prime - Michael de Estrada - 08-30-2014, 11:26 PM
RE: HP Prime - Mark Hardman - 08-31-2014, 12:40 AM
RE: HP Prime - toml_12953 - 09-10-2014, 03:10 PM
RE: HP Prime - gbh - 08-31-2014, 12:02 AM
RE: HP Prime - Michael de Estrada - 08-31-2014, 12:26 AM
RE: HP Prime - Mark Hardman - 08-31-2014, 12:33 AM
RE: HP Prime - gbh - 09-01-2014, 02:28 AM
RE: HP Prime - oldhpfan - 09-01-2014, 06:14 AM
RE: HP Prime - Tim Wessman - 09-01-2014, 03:42 PM
RE: HP Prime - cutterjohn - 09-05-2014, 08:48 PM
RE: HP Prime - Joe Horn - 09-05-2014, 11:44 PM
RE: HP Prime - cutterjohn - 09-14-2014, 02:40 PM
RE: HP Prime - parisse - 09-06-2014, 06:47 AM
RE: HP Prime - gbh - 09-01-2014, 05:50 PM
RE: HP Prime - walter b - 09-01-2014, 06:42 PM
RE: HP Prime - oldhpfan - 09-02-2014, 08:22 AM
RE: HP Prime - Joe Horn - 09-02-2014, 04:26 PM
RE: HP Prime - oldhpfan - 09-02-2014, 07:37 PM
RE: HP Prime - Joe Horn - 09-02-2014, 09:28 PM
RE: HP Prime - oldhpfan - 09-03-2014, 12:26 AM
RE: HP Prime - gbh - 09-01-2014, 07:35 PM
RE: HP Prime - walter b - 09-02-2014, 09:56 PM
RE: HP Prime - gbh - 09-02-2014, 03:50 PM
RE: HP Prime - oldhpfan - 09-02-2014, 07:55 PM
RE: HP Prime - oldhpfan - 09-06-2014, 02:31 AM
RE: HP Prime - gbh - 09-06-2014, 03:01 AM
RE: HP Prime - Han - 09-06-2014, 03:49 AM
RE: HP Prime - gbh - 09-06-2014, 06:07 PM
RE: HP Prime - oldhpfan - 09-06-2014, 03:27 AM
RE: HP Prime - Eddie W. Shore - 09-14-2014, 03:03 PM
RE: HP Prime - dbbotkin - 09-22-2014, 05:55 PM
RE: HP Prime - StephenG1CMZ - 05-24-2015, 07:07 PM
RE: HP Prime - toml_12953 - 08-31-2017 07:50 AM
RE: HP Prime - EladLending - 08-30-2017, 05:00 PM
RE: HP Prime - DrD - 09-01-2017, 11:55 AM
RE: HP Prime - Hans S. - 09-01-2017, 07:18 PM
RE: HP Prime - lschroeder1947 - 09-02-2017, 10:00 AM
RE: HP Prime - DrD - 09-02-2017, 11:21 AM



User(s) browsing this thread: 3 Guest(s)