Post Reply 
example python ppl with subroutines hp prime
06-08-2021, 01:53 AM (This post was last modified: 06-08-2021 02:42 AM by Liamtoh Resu.)
Post: #1
example python ppl with subroutines hp prime
The following demonstrate the useage of subroutines in python and ppl.
A simple pi approximation was used.

edit: fixed ppl code, was missing predeclaration for cls().

python:
Code:

#PYTHON name
# aprxpi02
import math

def pintro():
  print ("aprxpi02 pi approximation")
  return

def api():
  return 355/113

def pout():
  q1 = api()
  print ("pi = ", q1)

pintro()
pout()

#end 
 
EXPORT aprxpi02()
BEGIN
  PRINT;
  PYTHON(name);
END;

ppl
Code:

// aprxpi01
// predeclare subroutines
cls();
pintro();
api();
pout();

// main program
EXPORT aprxpi01()
BEGIN
cls();
pintro();
pout();
end;

// clear screen
cls()
begin
print();
end;

// print intro
pintro()
begin
print("aprxpi01: pi approximation");
end;

// pi approximation
api()
begin
return 355/113;
end;

// print output
local q1;
pout()
begin
q1 := api();
print("pi = " + q1);
end;

// end of source code

This is for those who are looking for a starting point.

Thanks/
Find all posts by this user
Quote this message in a reply
06-08-2021, 05:28 AM (This post was last modified: 06-08-2021 05:54 AM by toml_12953.)
Post: #2
RE: example python ppl with subroutines hp prime
(06-08-2021 01:53 AM)Liamtoh Resu Wrote:  edit: fixed ppl code, was missing predeclaration for cls().

You don't need to pre-declare functions anymore. The below still works.

Code:
// aprxpi01

// main program
EXPORT aprxpi01()
BEGIN
cls();
pintro();
pout();
end;

// clear screen
cls()
begin
print();
end;

// print intro
pintro()
begin
print("aprxpi01: pi approximation");
end;

// pi approximation
api()
begin
return 355/113;
end;

// print output
local q1;
pout()
begin
q1 := api();
print("pi = " + q1);
end;

// end of source code

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-08-2021, 05:58 AM (This post was last modified: 06-08-2021 06:03 AM by Liamtoh Resu.)
Post: #3
RE: example python ppl with subroutines hp prime
Ok Tom,

Thanks for the quick late night response about the pre-declaration entries.

The omission of the predeclarations did not seem to work on the emulator
--will check it out on the real hp prime.
Find all posts by this user
Quote this message in a reply
06-08-2021, 12:34 PM
Post: #4
RE: example python ppl with subroutines hp prime
(06-08-2021 05:58 AM)Liamtoh Resu Wrote:  Ok Tom,

Thanks for the quick late night response about the pre-declaration entries.

The omission of the predeclarations did not seem to work on the emulator
--will check it out on the real hp prime.

Are you sure you have the latest beta emulator? It works on mine without the pre-declarations.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
06-08-2021, 03:45 PM (This post was last modified: 06-08-2021 04:22 PM by Liamtoh Resu.)
Post: #5
RE: example python ppl with subroutines hp prime
I had problems trying to get the 20210428 emulator to run so I reverted back to the
2020 emulator.
The 20210428 CK is running fine.

I have the 20210505 firmware on the real hp prime.
I have not sent the updated version to the prime yet.

PPL and python are relatively new to me -- I am thinking about
backward compatibility.

Thanks.

edit: The program without the pre-declarations worked ok on the real hp prime.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: