P+

Prime Plus Language

About P+

P+ is a proprietary programming language designed to mitigate the challenges associated with code maintenance and comprehensibility in the HP Programming Language (PPL). PPL does not support pre-processing or multiple files, resulting in a single large file that can be unwieldy to manage. P+ serves as an intermediary language that addresses these issues by introducing support for pre-processing and facilitating code organization. P+ code is pre-processed into a single PPL file, which is subsequently executed on the HP Prime calculator since PPL is an interpreted language.

Insoft exclusively employs a proprietary programming language known as P+ for developing software intended for the HP Prime. Insoft has made the decision to release the software responsible for converting P+ to PPL to the general public. This software, developed internally, allows external developers to utilize the specialized programming language by seamlessly converting their own code written in P+ into PPL.

note:
The P+ proprietary programming language is susceptible to change, while also maintaining a certain degree of compatibility with previous revisions.
v1.3.x Library

Syntax Help v1.3.x

1. If-Else

When ever you want to perform a set of operations based on a condition If-Else is used.

Prime Plus Language (P+)
if expression {
    // code for 'expression' is true
else
    // code for 'expression' is false
}

if expression {
    // code for 'expression' is true
}
HP Prime Programming Language (PPL)
IF expression THEN    
    // code for 'expression' is true
ELSE
    // code for 'expression' is false
END;

IF expression THEN    
    // code for 'expression' is true
END;

2. Switch-Case

Switch-case is an alternative to If-Else-If ladder.

Prime Plus Language (P+)
switch expression {
    case condition1
        // statements
    end

    case condition2
        // statements
    end

    .
    .
    .

    case conditionN
        // statements
    end

    default 
        // default statements
}
HP Prime Programming Language (PPL)
CASE 
    IF expression1 THEN
        // statements
    END;

    IF expression2 THEN
        // statements
    END;

    .
    .
    .

    IF expressionN THEN
        // statements
    END;

    DEFAULT // optional 
        // statements
END;

3. For-Next

For-next loop is used to iterate a set of statements based on a condition.

Prime Plus Language (P+)
for a = 0 ... 9 {
    // code
}

for a = 9 down ... 0 step b {
    // code
}
HP Prime Programming Language (PPL)
FOR a FROM 0 TO 9 DO
    // code
END;

FOR a FROM 9 DOWNTO 0 STEP b DO
    // code
END;

4. While-Do

While-do is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

note:
Also valid PPL code.
Prime Plus Language (P+)
while condition {
    // code
}
HP Prime Programming Language (PPL)
WHILE condition DO
    // code
END;

5. Repeat-Until

Repeat-until is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

note:
Also valid PPL code.
Prime Plus Language (P+)
repeat
    // code
until condition
HP Prime Programming Language (PPL)
REPEAT
    // code
UNTIL condition

6. Function

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

Prime Plus Language (P+)
var var1, auto:var2; // global variables
var3; // var is optional for global variables NOTE 'auto' not supported!

#define NUM_ZERO	0

export MAINPRG()
@begin
    // code
    return NUM_ZERO;
@end

#include "include.pp"

SUBROUTINE()
@begin 
    var var4; // local variable only : SUBROUTINE()
    var4 = var3+var2-var1;
@end
include.pp
SUBROUTINE_FILE()
@begin 
    return !NUM_ZERO;
@end
HP Prime Programming Language (PPL)
LOCAL var1, var2; // global variables
var3; // LOCAL is optional for global variables

EXPORT MAINPRG()
BEGIN
    // code
    return 0;
END;

SUBROUTINE_FILE()
BEGIN 
    return NOT 0;
END;

SUBROUTINE()
BEGIN 
    LOCAL var4; // local variable only : SUBROUTINE()
    var4  :=  var3+var2-var1;
END;

7. Double-Identity

Variables possess the capability to be linked to an alternate name, enabling the use of longer, more meaningful names while still retaining shorter versions. This approach proves advantageous as it minimizes the storage footprint in the hpprgm file format.

Prime Plus Language (P+)
auto:LongFunctionName(auto:alpha)
@begin
    var i:index := 1;
    var auto:auto_variable_name := 2;
    PRINT(alpha);
    PRINT(index);
    PRINT(auto_variable_name);
@end
HP Prime Programming Language (PPL)
s1(p1)
BEGIN
    LOCAL i := 1;
    LOCAL v1 := 2;
    PRINT(p1);
    PRINT(i);
    PRINT(v1);
END;

8. Set-As

These bear similarities to #define, yet differ in that they adopt a prefix-suffix structure. This unique arrangement facilitates the efficient organization of aliases to functions into various categories.

Prime Plus Language (P+)
@set myFn::LongFunctionName as SUBROUTINE
SUBROUTINE(a:alpha)
@begin
    PRINT(alpha);
@end

@start
    myFn::LongFunctionName(1);
@end
HP Prime Programming Language (PPL)
SUBROUTINE(a)
BEGIN
    PRINT(a);
END;

EXPORT START()
BEGIN
    SUBROUTINE(1);
END;

9. Data-As

These bear similarities to #define, yet differ in that they asign an name to the data contents of a given file. This unique arrangement facilitates the ability of injecting file data into a LIST.

Prime Plus Language (P+)
#include <prime>

@data "file.bin" as myData
@start
   pixel::DimGROB(G1, 4, 4, `myData`);
   pixel::Blit(0, 0, G1);
   io::Wait();
@end
HP Prime Programming Language (PPL)
EXPORT START()
BEGIN
   DIMGROB_P(G1, 4, 4, {
#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h,#7FFF7FFF7FFF7FFF:64h
});
   BLIT_P(0, 0, G1);
   WAIT();
END;

10. Auto

The challenge posed by lengthy variables, functions, and parameter names lies in the significant increase in file footprint. While adopting shorter names may mitigate this concern, it concurrently introduces complexity in code comprehension and maintenance. The 'auto' feature effectively addresses this quandary by permitting the utilization of extended names. During processing, these extended names are automatically substituted with abbreviated counterparts, thereby preserving the manageability and comprehensibility of your source code.

Prime Plus Language (P+)
auto:LongFunctionName(auto:parametersAlso)
@begin
    var index:iAmLong := 1;
    var auto:iAmShorter := 2;
    PRINT(iAmLong);
    PRINT(iAmShorter);
    PRINT(parametersAlso);
@end
HP Prime Programming Language (PPL)
s4(p1)
BEGIN
    LOCAL index := 1;
    LOCAL v2 := 2;
    PRINT(index);
    PRINT(v2);
    PRINT(p1);
END;

11. Object

Wraps a collection of subroutines and global variables as methods and properties, accessed via the object name.

Prime Plus Language (P+)
#include <prime>

object name
@propery property
method(auto:text)
@begin
    PRINT(text);
@end
endof object

@start
    [name method:"Hellow Object"];
    io::print([name property]);
@end
HP Prime Programming Language (PPL)
LOCAL rw_1:=0;
m_1(p_1)
BEGIN
    PRINT(p_1);
END;
EXPORT START()
BEGIN
    m_1("Hellow Object");
    PRINT(rw_1);
END;

12. Let

Constants, these will become just normal variables in PPL and if your P+ code trys to change a constant it will simple give a warning.

Prime Plus Language (P+)
HP Prime Programming Language (PPL)