HP Forums
IFTE CMD & IFT new CMD - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: IFTE CMD & IFT new CMD (/thread-7831.html)



IFTE CMD & IFT new CMD - compsystems - 02-26-2017 03:53 PM

HELLO

I'm trying to port a code, to replace IF THEN ELSE END, by IFTE

1: in many cases you must enclose the field to true and false between (), when you try it in history view

fail
PHP Code:
iftetype(expr2) <> DOM_SYMBOLIC partn:=string(expr2), partn:=conv2RPN3(expr2) ); 

ok
PHP Code:
iftetype(expr2) <> DOM_SYMBOLIC , ( partn:=string(expr2) ), ( partn:=conv2RPN3(expr2) ) ); 

Original Code
PHP Code:
#pragma mode( separator(.,;) integer(h32) )
#cas
conv2RPN2(expr1):=
begin
  local rpnStr
operpartnpartspartJexpr2;
  
  
rpnStr:="";
  
oper:="";
  
partn:="";
  if (
type(expr1) <> DOM_SYMBOLICthen
    rpnStr
:=string(expr1);
    return(
rpnStr);
  
end;
  
oper:=part(expr1,0);
  
parts:=part(expr1);

  for 
partJ from 1 to parts do
    
expr2:=part(expr1,partJ);
    if (
type(expr2) <> DOM_SYMBOLICthen
      partn
:=string(expr2);
    else
      
partn:=conv2RPN2(expr2);
    
end;
    if (
partJ 1then rpnStr:=rpnStr " "end;
    
rpnStr:=rpnStr partn;
    if ((
partJ 1) or (parts == 1)) then
      rpnStr
:=rpnStr " " oper;
    
end;
  
end;

  return(
rpnStr);
end;
#end 



PHP Code:
// convToRPN3(x^3);
#pragma mode( separator(.,;) integer(h32) )
#cas
convToRPN3(expr1):=
begin
  local rpnStr
operpartnpartspartJexpr2;
  
  
rpnStr:="";
  
oper:="";
  
partn:="";
  
iftetype(expr1) <> DOM_SYMBOLIC, [ rpnStr:=string(expr1), return(rpnStr) ] );
  
oper:=part(expr1,0);
  
parts:=part(expr1);

  for 
partJ from 1 to parts do
    
expr2:=part(expr1,partJ);
    
iftetype(expr2) <> DOM_SYMBOLIC , ( partn:=string(expr2) ), ( partn:=conv2RPN3(expr2) ) ); 
    
iftepartJ , ( rpnStr:=rpnStr " " ), "" );
    
rpnStr:=rpnStr partn;
    if ((
partJ 1) or (parts == 1)) then
      rpnStr
:=rpnStr " " oper;
    
end;
  
end;

  return(
rpnStr);
end;
#end 


2: A new IFT command is required, on a future firmware

The field for the false condition, I put an empty string, but this is rubbish and when running in the history view it looks bad

PHP Code:
iftepartJ , ( rpnStr:=rpnStr " " ), "" ); 

->

PHP Code:
iftpartJ , ( rpnStr:=rpnStr " " ) ); 

3: Now if the field of true or false have more than one statement the compiler generates an error, how to solve this?, I try to group sentences between [], but fails =(

PHP Code:
iftetype(expr1) <> DOM_SYMBOLIC, [ rpnStr:=string(expr1), return(rpnStr) ], "" ); 



All of the above for the purpose of running a CAS program step by step, placing each instruction in the history view