Post Reply 
Calling the contents of an identifier
03-13-2017, 01:45 AM
Post: #1
Calling the contents of an identifier
Hello

It is common within a program to store an identifier inside another identifier and then store an object within the contents of the last ID, I have not currently been able to do this in HPP-PL

X:=0; [ENTER] 0
sto('X+1',F1); [ENTER]
F1; [ENTER] 'X+1' // ok
FunctionUserAppVar:='F2'; [ENTER] F2 // OK
sto('X+2',FunctionUserAppVar); [ENTER] // 2 =(

I think the first argument ('X+2') if it is enclosed in quotation marks should not be evaluated 0+2 -> 2, Should be kept 'X+2'

Now the second argument, should be able to be controlled with eval CMD Or with a new RECALL command, to call n times your content.

ID1:= 'ID0'
ID:='ID1'

eval(ID,1) == recall 1 time -> ID1
eval(ID,2) == recall 2 times etc -> ID0

sto('X+2',eval(FunctionUserAppVar,1) ); == sto('X+2', 'F2') == (F2:='X+2')
Find all posts by this user
Quote this message in a reply
03-13-2017, 03:16 AM
Post: #2
RE: Calling the contents of an identifier
Code:

local casName:="F2";
CAS(EVAL(casName + ":='X+2'"))

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-13-2017, 10:29 PM (This post was last modified: 03-21-2017 04:18 AM by compsystems.)
Post: #3
RE: Calling the contents of an identifier
In CAS MODE, does not work, evaluates the USER variables, (A, ... Z, L0-L9, M0-M9, etc.) I keep insisting that the quotation marks should be not evaluated the expression.

//CAS MODE with X uppercase
X:=0;
symbExpr:='X+1';
var:="FF1";
CAS( EVAL ( var + "(X):=" + symbExpr ) ); // FF1(X):=1
FF1(2); // RETURNS 1 evaluates X =(

//HOME MODE with X uppercase
X:=0;
symbExpr:='X+1';
var:="FF1";
CAS( EVAL (var + "(X):=" + symbExpr )); // FF1(X):='X+1'
FF1(2); // RETURNS 3 OK

//CAS MODE with x lowercase
purge(x);
symbExpr:='x+1'; // or symbExpr:=x+1;
var:="FF2";
CAS( EVAL ( var + "(x):=" + symbExpr ) ); // FF2(x):='x+1'
FF2(2); // RETURNS 3 OK

At least I was able to execute INPUT CMD from a CAS PRG
run PRGCAS();

PHP Code:
export resetFunctionAppVarsvarApp_str )
BEGIN
  expr
"Function." varApp_str ":=0"); // "" = "No definition in Symbolic view"
  
return "Done";
END;


#cas
  
PRGCAS():= 
  
BEGIN
    SetFunctionAppVars
"F1" );
    
SetFunctionAppVars"F2" );
    
// ....
    
return("Done");
  
END;
#end

export SetFunctionAppVarsvarApp_str )
BEGIN
  local symbExpr
resetVALUE_FXinitVALUE_FX;
  
IFERR
    initVALUE_FX 
:= EXPRvarApp_str );
  
THEN
    initVALUE_FX 
:= 0
  
END
  
resetVALUE_FX := 'X^2/9';
  
local ObjectType_SymbolicExpression := 8;
  if 
  (
    
input
    { { 
symbExpr, [ ObjectType_SymbolicExpression ] } }, 
    
"Set Function App Vars",
    
varApp_str+"(X):",
    
"Enter Symbolic Expression for "+varApp_str+"(X)",
    
resetVALUE_FX
    
initVALUE_FX
    
)
  )
  
then
    expr
("Function." varApp_str ":='" symbExpr "'");
    
//CAS( EVAL(varApp_str + "(X):=" + symbExpr) );
    //return( { varApp_str, symbExpr, varApp_str + "(X):=" + symbExpr,  varApp_str + ":='" + symbExpr + "'" });
  
end;
END
Find all posts by this user
Quote this message in a reply
03-14-2017, 12:51 AM (This post was last modified: 03-14-2017 01:19 AM by Han.)
Post: #4
RE: Calling the contents of an identifier
Your program seems extremely convoluted. There is no reason to request a "type 8" object when you are simply going to treat the input as a string anyway. (In other words, why not just use strings?) Also, why create a CAS program that does nothing but call non-CAS programs? A more straightforward approach is to simply do it all in non-CAS programs.

Don't use EXPR() if you don't want variables evaluated. Use CAS() instead.

Code:
export resetFunctionAppVars( varApp_str )
BEGIN
  EXPR(EVAL(varApp_str + ":=" + string(""))); 
  return("Done");
END;

export SetFunctionAppVars( varApp_str )
BEGIN
  local symbExpr, resetVALUE_FX, initVALUE_FX;
  IFERR
    initVALUE_FX := string(EXPR(varApp_str));
  THEN
    initVALUE_FX := "";
  END;
  resetVALUE_FX := "X^2/9";

  if 
  (
    input( 
    { { symbExpr, [ 2 ] } }, 
    "Set Function App Vars",
    varApp_str+"(X):",
    "Enter Symbolic Expression for "+varApp_str+"(X)",
    resetVALUE_FX, 
    initVALUE_FX
    )
  )
  then
    CAS(EVAL(varApp_str + ":=(X)->" + symbExpr));
    return(1); 
  end;
  return(0);
END;

EXPORT PRGCAS()
BEGIN
    SetFunctionAppVars( "F1" );
    SetFunctionAppVars( "F2" );
    return("Done");
END;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-16-2017, 01:10 AM
Post: #5
RE: Calling the contents of an identifier
(03-13-2017 01:45 AM)compsystems Wrote:  It is common within a program to store an identifier inside another identifier and then store an object within the contents of the last ID

That claim is rather broad. I have never used such a construct. Not in a system like the HP Prime.
Find all posts by this user
Quote this message in a reply
03-16-2017, 01:18 AM
Post: #6
RE: Calling the contents of an identifier
(03-13-2017 10:29 PM)compsystems Wrote:  In CAS MODE, does not work, evaluates the USER variables, (A, ... Z, L0-L9, M0-M9, etc.) I keep insisting that the quotation marks should be not evaluated the expression.

Well, that behavior is not how the HP Prime works. 'Insisting' won't change anything. Have you considered learning how the HP Prime works and developing your programs accordingly?
Find all posts by this user
Quote this message in a reply
03-16-2017, 03:22 AM
Post: #7
RE: Calling the contents of an identifier
(03-14-2017 12:51 AM)Han Wrote:  ...There is no reason to request a "type 8" object when you are simply going to treat the input as a string anyway. (In other words, why not just use strings?) Also, why create a CAS program that does nothing but call non-CAS programs? A more straightforward approach is to simply do it all in non-CAS programs.

Hola/Hi Han,
El INPUT CMD no trabaja dentro de un CAS MODE, por esta razón hay que crear una función o programa tipo HOME,

No me gusta trabajar con cadenas para expresiones simbólicas matemáticas , pues me parece que es una forma primitiva de programacion, solo las uso en casos extraordinarios.


[eng -Translation by google ]The INPUT CMD does not work within a CAS MODE, for this reason you have to create a function or program type HOME,

I do not like working with strings for symbolic mathematical expressions, as it seems to me that it is a primitive form of programming, I only use them in extraordinary cases.

If there is a type 8, for symbolic expressions, it would have to work.
Find all posts by this user
Quote this message in a reply
03-16-2017, 01:25 PM (This post was last modified: 03-16-2017 02:45 PM by Han.)
Post: #8
RE: Calling the contents of an identifier
(03-16-2017 03:22 AM)compsystems Wrote:  [eng -Translation by google ]The INPUT CMD does not work within a CAS MODE, for this reason you have to create a function or program type HOME,

Yes, this is correct.

Quote:I do not like working with strings for symbolic mathematical expressions, as it seems to me that it is a primitive form of programming, I only use them in extraordinary cases.

The string is used for indirection (i.e. indirect storing/declaration of a variable whose name is saved as another variable) and for non-evaluation of expressions. A pair of single quotes will only prevent one level of evaluation, whereas you need several levels of non-evaluation (especially so, since you are using the EXPR() command). This is why it should be done using strings. Moreover, your expression is merely a formula. I agree that symbolic manipulation is best done using expressions, but in this case you are not doing any symbolic manipulation. Instead, you are merely declaring a formula.

Once you have set up F1, F2, etc., creating a CAS program to do actual symbolic manipulation would be a perfectly fine approach.

Quote:If there is a type 8, for symbolic expressions, it would have to work.

Type 8 is quite limited in the Home view. It is mostly there for display purposes (for example, when viewing CAS objects in the Home view) and not for any real symbolic manipulation. So while you could achieve what you want using type 8 objects, a direct approach would be to use strings in conjunction with the CAS() command since your program is a "Home" program. This would also lower the chances of issues with evaluation.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




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