Post Reply 
2021: Examples of CAS-type programs
05-07-2021, 02:26 AM (This post was last modified: 05-08-2021 03:26 PM by compsystems.)
Post: #13
RE: 2021 Examples of CAS-type programs
"WHEN" "IFTE"and "()?" CMDS

WHEN CMD
4 arguments
1: test to solve
2: action for true
3: action for false
4: optional if you cannot solve the test

with 4 args
PHP Code:
#cas
test_whencmd_cas_0(testvar):=
begin
    
return whentestvartruefalse"other" );
end;
#end 

test_whencmd_cas_0(eeee) > "other"

with 3 args
PHP Code:
#cas
test_whencmd_cas(testvar):=
begin
    
return whentestvartruefalse );
end;
#end 

as function
PHP Code:
#cas
function test_whencmd_cas(testvar)
    return 
whentestvartruefalse );
end

test_whencmd_cas(true); [enter] returns true
test_whencmd_cas(false); [enter] returns false
purge(x); test_whencmd_cas(x); [enter] returns ((x)? true : false)
test_whencmd_cas(1); test_whencmd_cas(0); test_whencmd_cas(-1);
[enter] returns true, false, true


with (?) infix operator
PHP Code:
#cas
test_questionmarkcmd_cas(testvar):=
begin
    
return (testvar)? true:false;
end;
#end 

as function
PHP Code:
#cas
function test_questionmarkcmd_cas(testvar)
    return (
testvar)? true:false;
end

test_questionmarkcmd_cas(1); test_questionmarkcmd_cas(0); test_questionmarkcmd_cas(-1);
[enter] returns true, false, true

test_questionmarcmd_cas(x); [enter] returns ((x)? true : false)

with IFTE cmd, the test must always return a numerical value
PHP Code:
#cas
test_iftecmd_cas(testvar):=
begin
    
return iftetestvartruefalse );
end

as function
PHP Code:
#cas
function test_iftecmd_cas(testvar)
    return 
iftetestvartruefalse );
end


test_iftecmd_cas(1); test_iftecmd_cas(0); test_iftecmd_cas(-1);test_iftecmd_cas(true); test_iftecmd_cas(false);
[enter]
1, 0, 1, 1, 0

test_iftecmd_cas(x); [enter] IFTE(x,1,0)

ifte + := operator
ifte(true,(testvar1:=123),(testvar2:=456)); [enter] returns 123 ok [up] [up] [copy] [enter] ok
ifte(false,(testvar1:=123),(testvar2:=456)); [enter] returns 456 ok
purge(testvar1, testvar2);
ifte(true,(123=>testvar1),(456=>testvar2));

? + => operator
(true)? (123=>testvar1): (456=>testvar2); [enter] returns 123 ok,
(false)? (123=>testvar1): (456=>testvar2); [enter] returns 456 ok, but [up] [up][copy] [enter]
"sto 123:testvar4 not allowed! Error: Bad Argument Type"
Cause of the problem: the parentheses are suppressed in the arguments (123=>testvar3) to 123=>testvar3, this means that it cannot be interpreted
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: 2021 Examples of CAS-type programs - compsystems - 05-07-2021 02:26 AM



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