02-08-2019, 09:23 PM
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++
result of compilation
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.
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( x ) :=
{
local k;
k := 5;
return x * k;
};
f2( x ) :=
begin
local k;
k := 5;
return x * k;
end;
function f3( x )
begin
local k;
k := 5;
return x * k;
end;
function f4( x )
local k;
k := 5;
return x * k;
ffunction;
function f4a( x )
local k;
k := 5;
return x * k;
end;
f5 := function( x )
local k;
k := 5;
return x * k;
end;
// Pascal style
function f6( x )
begin
var k;
k := 5;
return x * k;
end;
// TI68k (ti89 tiv200) style
:f7( x )
:Func
: Local k
: 5 → k
: Return x * 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.