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.

Syntax help

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 then
    // code for 'expression' is true
else
    // code for 'expression' is false
endif;

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
end;
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
}

for b from 0 ... 9 step 1 do
    // code
next;

for c from 9 down ... 0 step 2 do
    // code
next;
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;

FOR b FROM 0 TO 9 STEP 1 DO
    // code
END;

FOR c FROM 9 DOWNTO 0 STEP 2 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 do
    // code
end;

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, var2; // global variables
var3; // var is optional for global variables

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

embed 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

Now, variables with names from a-z have the capability to be associated with an alternative identity, allowing for a more meaningful name while still maintaining a single-character name. This approach is advantageous as it requires only two bytes of storage in the hpprgm file format.

Prime Plus Language (P+)
SUBROUTINE(a:alpha)
@begin
    var i:index = 1;
    var ?:auto_variable_name = 2;
    PRINT([alpha]);
    PRINT([index]);
    PRINT([auto_variable_name]);
@end // All Double Identities Purged
HP Prime Programming Language (PPL)
SUBROUTINE(a)
BEGIN
    LOCAL i := 1;
    LOCAL b := 2;
    PRINT(a);
    PRINT(i);
    PRINT(b);
END;