Language Elements and Reference:xpplrm

Reference operator Foundation

When a variable is passed as an argument to a procedure or user-defined function, the default is to pass the variable by value. Within the called subroutine, the passed value can be changed in any way without changes to this value being reflected in the variable within the calling routine.

************** 
PROCEDURE Main 
   LOCAL cString := "Xbase++" 

   ? cString                       // result: Xbase++ 
   NewString( cString )            // passing as a value 
   ? cString                       // result: Xbase++ 

RETURN 

************************* 
PROCEDURE NewString(cVar) 
   cVar := "James Bond" 
RETURN 

Using the reference operator @, variables can be passed to a subroutine by reference instead of by value. If passed by reference, any change made to the value of the variable within the called subroutine is also reflected in the value of the variable within the calling routine when the subroutine terminates:

************** 
PROCEDURE Main 
   LOCAL cString := "Xbase++" 

   ? cString                       // result: Xbase++ 
   NewString( @cString )           // pass by reference 
   ? cString                       // result: James Bond 

RETURN 

************************* 
PROCEDURE NewString(cVar) 
   cVar := "James Bond" 
RETURN 

The reference operator @ allows the values of variables passed as arguments to UDFs or procedures to be changed. In this way, the value of lexical variables (which are otherwise not even visible in the subroutine) can be changed in a subroutine. Several variables can also be changed at one time by calling a single procedure or function and passing several variables by reference.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.