Post Reply 
Problems with the name of files (*. hpprgm) and global ids
02-11-2018, 09:18 PM (This post was last modified: 02-13-2018 12:33 PM by compsystems.)
Post: #1
Problems with the name of files (*. hpprgm) and global ids
Hello, Sorry for my bad translation

A good practice of computer programming is divide and conquer (Folders, subfunctions, etc), which is disseminated in most programming books.

The system of the hp-prime allows to call from directory or folder, a identifier or function and works very well =), except that if the file name (pc-name) is renamed it fails =(

Example of the use of the dot operator or double colon, binary files below

Step 1: create a file with the following name
file: dir_pi_main.hpprgm (main file, library)
PHP Code:
export pi_k:=π// declares a visible global variable pi_k=3.14159265359 path dir_pi_main::pi_k

EXPORT main_pi_k()
BEGIN
  
return {pi_k}; // returns the internal variable pi_k, path dir_pi_main::pi_k
END

step 2: Execute the following instruction.
dir_pi_main.main_pi_k() [ENTER] // recall the variable pi_k of dir_pi_main
returns {3.14159265359} // ok

or

[tools] program functions dir_pi_main main_pi_k [ok]
dir_pi_main.main_pi_k() [ENTER] {3.14159265359}

Step 3: create a file with the following name
file: dir_pi_2.hpprgm
PHP Code:
EXPORT main_pi_k() 
BEGIN
  
return { dir_pi_main.pi_k };  // returns a external variable (pi_k of dir_pi_main)
END;

EXPORT pi_ext1()
BEGIN 
  dir_pi_main
.pi_k:=dir_pi_main.pi_k+1// modify an external variable  (pi_k of dir_pi_main) where pi_k = pi_k+1
  
return { dir_pi_main.pi_k } ;  // returns an external variable
END;

EXPORT pi_ext2()
BEGIN
  dir_pi_main
.pi_k:=dir_pi_main.pi_k+2// modify an external variable (pi_k of dir_pi_main) where pi_k = pi_k+2
  
return { dir_pi_main.pi_k } ;  // returns an external variable
END;

EXPORT pi_ext3()
BEGIN  
  
return { dir_pi_main.pi_k } ; // returns an  external variable
END

step 4: Execute the following four instructions.
dir_pi_2.main_pi_k() [ENTER] returns {3.14159265359} // ok
pi_ext1() [ENTER] returns {4.14159265359} // ok
pi_ext2 ()[ENTER] returns {6.14159265359} // ok
pi_ext3 ()[ENTER] returns {6.14159265359} // ok

Step 5: create a file with the following name
file: dir_pi_3.hpprgm
PHP Code:
export pi_k=pi-1// declares a visible  variable pi_k=3.14159265359-1 path dir_pi_3::pi_k

EXPORT main_pi_k()
BEGIN  
  
return( { pi_kdir_pi_main.pi_k } );  // returns a internal (path dir_pi_3::pi_k) and external variable (path dir_pi_main::pi_k)
END;

EXPORT pi_ext4()
BEGIN  
  pi_k
:=pi_k-1;   // modify an internal variable (pi_k of dir_pi_3) where pi_k = pi_k-1
  
dir_pi_main.pi_k:=dir_pi_main.pi_k+3// modify an external variable (pi_k of dir_pi_main) where pi_k = pi_k+3
  
return( { pi_kdir_pi_main.pi_k } ); // returns a internal and external variable
END;

EXPORT pi_ext5()
BEGIN  
  
return( { pi_kdir_pi_main.pi_k } );
END

step 6: Execute the following three instructions.
dir_pi_3.main_pi_k() [ENTER] returns {2.14159265359, 6.14159265359} // ok
pi_ext4 ()[ENTER] returns {1.14159265359, 9.14159265359} // ok
pi_ext5() [ENTER] returns {1.14159265359, 9.14159265359} // ok

Problem #1: If you rename the main file, many functions would fail, because they do not find the correct path

One solution is to store in the header a folder name in each file (internal library name), in this way the name of the file is irrelevant (external library name [pc name]), the real path is defined by the header (internal library name)

With the new directive
file: dir_pi_main.hpppl
PHP Code:
#FOLDER dir_pi_main // header for real path
export pi_k:=pi;

EXPORT main_pi_k()
BEGIN
  
return {pi_k};
END
file: dir_pi_2.hpppl
PHP Code:
#FOLDER dir_pi_2 // header
EXPORT main_pi_k()
BEGIN
  
return { dir_pi_main.pi_k }; 
END;
... 
file: dir_pi_3.hpppl
PHP Code:
#FOLDER dir_pi_3 // header
export pi_k=pi-1;
... 


you can check the problem by downloading the files below twice and sending the second download to the HPCONNECTITYKIT and you will notice that a syntax error is generated because it does not include the path, since a postfix (n) to the file is appended

2: second problem

In the memory manager, the variables can be reset to zero, but this alters the constant value defined within the algorithm, which produces unexpected results, for this reason to avoid this problem, a possible solution is to define a global variable as constant

CONSTANT EXPORT qpiDIGITS

Example for test the second problem, binary files below (QPI_4.4.hpprgm)
You can check it yourself, resetting the variables qpiEXPLN, qpiMAXINT, qpiDIGITS of QPI_4.4.hpprgm

QPI_(1.41421356237) [enter] returns sqrt(2)
[shift]+[tools]: user vars: qpiEXPLN (real), qpiMAXINT (real), qpiDIGITS (real) then reset each
QPI_(1.41421356237) [enter] returns 1 (failure)

PHP Code:
export qpiEXPLN:=100// max denom for exp(p/q) or ln(p/q)
export qpiMAXINT:=2^20// largest n allowed for sqrt(n)=a*sqrt(b)
export qpiDIGITS:=10// controls accuracy (best results at 9 or 10) 


please test the codes and tell me

Thanks

Jaime


Attached File(s)
.hpprgm  dir_pi_main.hpprgm (Size: 1.67 KB / Downloads: 2)
.hpprgm  dir_pi_2.hpprgm (Size: 2.63 KB / Downloads: 1)
.hpprgm  dir_pi_3.hpprgm (Size: 2.7 KB / Downloads: 1)
.hpprgm  QPI_4.4.hpprgm (Size: 13.3 KB / Downloads: 1)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Problems with the name of files (*. hpprgm) and global ids - compsystems - 02-11-2018 09:18 PM



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