Post Reply 
syntax flexibility (programming) of xcas on HP-Prime
02-08-2019, 09:23 PM (This post was last modified: 02-09-2019 02:01 PM by compsystems.)
Post: #1
syntax flexibility (programming) of xcas on HP-Prime
Hello, HP-Prime users, the syntax flexibility of xcas makes you like it a lot, some users according to the context they like, at the beginning and at the end of the blocks with symbols {...}, others in a more explicit way is to say for example to define a function with words, Func..EndFunc

According to the following set of definitions, Xcas supports 8 different ways to define a function, it is not governed by a particular style, of course the compilation is done in ~ c++
PHP Code:
/// c++ style
f1) := 

  
local k;
  
:= 5;
  return 
k
}; 

f2) :=
begin  
  local k
;
  
:= 5;
  return 
k
end;

function 
f3)
begin  
  local k
;
  
:= 5;
  return 
k
end;

function 
f4)
  
local k;
  
:= 5;
  return 
k
ffunction

function 
f4a)
  
local k;
  
:= 5;
  return 
k
end

f5 := function( 
  
local k;
  
:= 5;
  return 
k
end

// Pascal style
function f6)
begin  
  
var k;
  
:= 5;
  return 
k
end;

// TI68k (ti89 tiv200) style
:f7)
:
Func
:  Local k
:  5 → k
:  Return k
:EndFunc

// python style
// ... 

result of compilation
PHP Code:
nameFunction 
(x)-> 
local k
k:=5;  
return(
x*k);  


test
f1(3); f2(3); f3(3); f4(3); f5(3); f6(3); ClrIO [enter] returns 15, 15, 15, 15, 15, 15

test online
Different ways to define a function.
Find all posts by this user
Quote this message in a reply
02-09-2019, 01:39 PM
Post: #2
RE: syntax flexibility (programming) of xcas on HP-Prime
Another example for IF-THEN-ELSE-END

PHP Code:
function AgeVote( )
begin 
    local Age

    
assumeAgeinteger );

    
DispGClrIOClrGraph

    
printf"How old are you?" );
    
inputAge );

    if 
Age ≥ 18 then
        printf
(  "Go vote!" );
    else
        
printf"Sorry, not yet" );
    
end_if

    
return Done;

end:;

AgeVote( ) :=


    
local Age
    
assumeAgeinteger );

    
DispGClrIOClrGraph

    
printf"How old are you?" );
    
inputAge );

    if (
Age>=18printf("Go vote!");   
    else 
printf("Sorry, not yet");  

    return 
Done;

}:;


AgeVote( ) :=

    
local Age
    
assumeAgeinteger );

    
DispGClrIOClrGraph

    
printf"How old are you?" );
    
inputAge );

    if (
Age >= 18
    {
        
printf(  "Go vote!" );
    }
    else
    {
        
printf"Sorry, not yet" );
    }
    
    return 
Done;
}:;


function 
AgeVote1( )
begin 
    local Age

    
assumeAgeinteger );

    
DispGClrIOClrGraph

    
printf"How old are you?" );
    
inputAge );

    if (
Age >= 18
        
begin
            printf
(  "Go vote!" );
        
end  
    
else
        
begin
            printf
"Sorry, not yet" );
        
end

    
return Done;

end 
Find all posts by this user
Quote this message in a reply
Post Reply 




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