HP Forums
Problems with eval(IdentifierName,#recall) - 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: Problems with eval(IdentifierName,#recall) (/thread-7836.html)



Problems with eval(IdentifierName,#recall) - compsystems - 02-27-2017 03:08 PM

Hello, the following statements executed line by line in the history of CAS view, show the following output [8, 8, id2, id1, id0, 8, 8], but within a program [id1,id0,id2,id1,id1,id1,id1] Why?

Please follow the following steps orderly to see the problem

1: [Shift]+[mem] /userVars, [DELETE]id0, id1, id2 & CAS Vars id0, id1, id2

2: firts goto CAS & HISTORY VIEW
2.1: id0:=8; id1:='id0'; id2:='id1'; [ENTER] // store id2,id1,id0 in the CAS environment
2.2: [ id2, eval(id2), eval(id2,0), eval(id2,1), eval(id2,2), eval(id2,3), eval(id2,4) ]; [ENTER] // returns [8, 8, id2, id1, id0, 8, 8]

3: then goto HOME & HISTORY VIEW // recall IDs in the CAS environment
3.1: { id2, CAS.eval(id2), CAS.eval(id2,0), CAS.eval(id2,1), CAS.eval(id2,2), CAS.eval(id2,3), CAS.eval(id2,4) } [ENTER] // returns {id1,id0,id2,id1,id0,8,8}

4: NOW AS PRGM return or goto CAS mode

4.1: purge(id0, id1, id2); [ENTER] before running the program, to delete pre-assigned data, although it should not be so, since ID0, ID1, ID2 are local variables within of prgm, why is it calling EVAL to global variables? If id0 is local, should call local ID0 and not global ID0

id2,id1,id0; [ENTER] //returns id2,id1,id0
4.2: RCLidsCAS(); [ENTER] // returns [id1,id0,id2,id1,id1,id1,id1] ?
id2,id1,id0; [ENTER] //returns id2,id1,id0
4.3: RCLidsHOME(); [ENTER] // returns [id1,id0,id2,id1,id1,id1,id1] ?

5: switch HOME VIEW
id2,id1,id0; [ENTER] //returns id2,id1,id0
5.1: RCLidsHOME(); [ENTER] // returns [id1,id0,id2,id1,id1,id1,id1] ?
id2,id1,id0; [ENTER] //returns id2,id1,id0
5.2: RCLidsCAS(); [ENTER] // the virtual calculator is locked and creates global variables, id0, id1, id2, why?

PHP Code:
#cas
    
RCLidsCAS():=
    
begin
        local id0
id1id2;
        print;
        
id0:=8;
        
id1:='id0'// OR id1:=quote(id0);
        
id2:='id1';
        print(
"id2="+id2);wait;                     // "id2=8"           ok   id2 -> 'id1' -> 'id0' -> 8
        
print("eval(id2)=" + eval(id2)  ); wait;    // "eval(id2)=8"     ok   id2 -> 'id1' -> 'id0' -> 8
        
print(" ");
        print(
"eval(id2,0)=" + eval(id2,0) ); wait// "eval(id2,0)=id2" ok   id2 -> 'id2'
        
print("eval(id2,1)=" + eval(id2,1) ); wait// "eval(id2,1)=id1" ok   id2 -> 'id1'
        
print("eval(id2,2)=" + eval(id2,2) ); wait// "eval(id2,2)=id0" ok   id2 -> 'id1' -> 'id0'
        
print("eval(id2,3)=" + eval(id2,3) ); wait// "eval(id2,3)=8"   ok   id2 -> 'id1' -> 'id0' -> 8
        
print("eval(id2,4)=" + eval(id2,4) ); wait// "eval(id2,4)=8"   ok   id2 -> 'id1' -> 'id0' -> 8 -> 8
        //sto(9,id2);
        
return( [ id2, eval(id2), eval(id2,0), eval(id2,1), eval(id2,2), eval(id2,3), eval(id2,4) ] ); // [8, 8, id2, id1, id0, 8, 8]
    
end;
#end 

export RCLidsHOME()
begin
    local id0
id1id2;
    print;
    
id0:=8;
    
id1:='id0';
    
id2:='id1';
    print(
"id2="+id2);wait;                     // "id2=8"                 ok   id2 -> 'id1' -> 'id0' -> 8
    
print("eval(id2)=" + eval(id2)  ); wait;    // "eval(id2)=8"           ok   id2 -> 'id1' -> 'id0' -> 8
    
print(" ");
    print(
"eval(id2,0)=" CAS.eval(id2,0) ); wait// "eval(id2,0)=id1" ok   id2 -> 'id2'
    
print("eval(id2,1)=" CAS.eval(id2,1) ); wait// "eval(id2,1)=id1"   ok   id2 -> 'id1'
    
print("eval(id2,2)=" CAS.eval(id2,2) ); wait// "eval(id2,2)=id0"   ok   id2 -> 'id1' -> 'id0'
    
print("eval(id2,3)=" CAS.eval(id2,3) ); wait// "eval(id2,3)=8"     ok   id2 -> 'id1' -> 'id0' -> 8
    
print("eval(id2,4)=" CAS.eval(id2,4) ); wait// "eval(id2,4)=8"     ok   id2 -> 'id1' -> 'id0' -> 8 -> 8
    //sto(9,id2);
    
return( { id2CAS.eval(id2), CAS.eval(id2,0), CAS.eval(id2,1), CAS.eval(id2,2), CAS.eval(id2,3), CAS.eval(id2,4) } ); // {id1,id0,id2,id1,id0,8,8}
end

6: goto HOME VIEW
6.1: purge(id0, id1, id2); [ENTER]
6.2: Now if you define variables in HOME VIEW
id0:=8; id1:='id0'; id2:='id1';[ENTER] // store id2,id1,id0 in the HOME environment
7: goto CAS VIEW
7.1: RCLidsCAS(); [ENTER] returns [8, 8, id2, id1, id0, 8, 8] Why? EVAL command, must first call the local variables and then the global variables


RE: Problems with eval(IdentifierName,#recall) - parisse - 02-27-2017 08:15 PM

In CAS programs, evaluation is done at level 1 instead of 25 for interactive evaluation.


RE: Problems with eval(IdentifierName,#recall) - compsystems - 02-28-2017 12:32 PM

(02-27-2017 08:15 PM)parisse Wrote:  In CAS programs, evaluation is done at level 1 instead of 25 for interactive evaluation.
understood for CAS PRGM

id0:=8;
id1:='id0'; // OR id1:=quote(id0);
id2:='id1';

id2; // 'id1' // ok, 1 LEVEL of evaluationand and not continuous ... -> 8 as HOME MODE
eval(id2); // 'id0' // 2 LEVELS, Why? EVAL cmd should assess if not one level at all levels

eval(id2,0); // id2 -> 'id2' // ok, I interpret it as not evaluating
eval(id2,1); // id2 -> 'id1' // ok, 1 LEVEL
BUT
eval(id2,2); // id2 -> 'id1' // must be 2 levels of evaluation id2 -> 'id1' -> 'id0' , otherwise for what is the second argument?

Now the logic of the program changes (to check the problem follow the previous steps 6 to 7.1), if there are stored variables in HOME VIEW and there is no way to delete those variables from a CAS prgm, so I request new commands
PURGE() only for HOME environment
& PURGEcas() only for CAS environment


In step 5,this must also be solved, Why global variables are created


RE: Problems with eval(IdentifierName,#recall) - Han - 02-28-2017 12:43 PM

You delete Home variables using: DelHVars("name") or DelHVars({ "list", "of", "names" });

The purge() command is a CAS command; it will only delete CAS variables

By the way, you placed purge(id0, id1, id2); outside of any program, so this will never be evaluated.


RE: Problems with eval(IdentifierName,#recall) - compsystems - 02-28-2017 01:11 PM

(02-28-2017 12:43 PM)Han Wrote:  You delete Home variables using: DelHVars("name") or DelHVars({ "list", "of", "names" });
The purge() command is a CAS command; it will only delete CAS variables

Ok, Han
but if I include the sentence DelHVars({"id0", "id1", "id2"});, the simulator enters an indefinite cycle.

without DelHVars({"id0", "id1", "id2"}); within of the prgm, the EVAL command must first evaluate the local and non-global variables, please try the following

6: goto HOME VIEW
6.1: purge(id0, id1, id2); [ENTER]
6.1a:DelHVars({"id0", "id1", "id2"}); [ENTER]
6.2: Now if you define variables in HOME VIEW
id0:=8; id1:='id0'; id2:='id1';[ENTER] // store id2,id1,id0 in the HOME environment
7: goto CAS VIEW
7.1: RCLidsCAS(); [ENTER] returns [8, 8, id2, id1, id0, 8, 8] Why?

PHP Code:
#cas
    
RCLidsCAS():=
    
begin
        local id0
id1id2;
        
//DelHVars({"id0", "id1", "id2"});
        
print;
        
id0:=8;
        
id1:='id0'// OR id1:=quote(id0);
        
id2:='id1';
        print(
"id2="+id2);wait;                     // "id2='id1'"       ok   id2 -> 'id1'  1 LEVEL
        
print("eval(id2)=" + eval(id2)  ); wait;    // "eval(id2)='id1'"  Why?
        
print(" ");
        print(
"eval(id2,0)=" + eval(id2,0) ); wait// "eval(id2,0)=id2" ok   id2 -> 'id2'  // 0 levels
        
print("eval(id2,1)=" + eval(id2,1) ); wait// "eval(id2,1)=id1" 'id1' Why?
        
print("eval(id2,2)=" + eval(id2,2) ); wait// "eval(id2,2)=id1" 'id1' Why?
        
print("eval(id2,3)=" + eval(id2,3) ); wait// "eval(id2,3)=id1" 'id1' Why?
        
print("eval(id2,4)=" + eval(id2,4) ); wait// "eval(id2,4)=id1" 'id1' Why?
        //sto(9,id2);
        
return( [ id2, eval(id2), eval(id2,0), eval(id2,1), eval(id2,2), eval(id2,3), eval(id2,4) ] ); // [id1,id0,id2,id1,id1,id1,id1] 
    
end;
#end