yorick banner

Home

Manual

Packages

Global Index

Keywords

Quick Reference

Back: extern Forward: Environment   FastBack: Loops Up: Scoping FastForward: Environment         Top: Yorick Contents: Table of Contents Index: Concept Index About: About this document

1.2.5.2 local statements

The save and restore functions store and retrieve Yorick variables in self-descriptive binary files (called PDB files). To create a binary file `demo.pdb', save the variables theta, E, m, and c in it, then close the file:

 
f = createb("demo.pdb")
save, f, theta, E, m, c
close, f

To open this file and read back the theta variable:

 
restore, openb("demo.pdb"), theta, c

For symmetry with save, the restore function has the unusual property that it redefines its parameters (except the first). Thus, theta is redefined by this restore statement, just as it would have been by a theta= statement. The Yorick parser does not understand this, which means that you must be careful when you place such a function call inside a function:

 
func q_out_file(infile, Q, outfile)
{
  if (!is_stream(infile)) infile = openb(infile);
  local theta;
  restore, infile, theta;
  return q_out(Q, outfile);
}

This variant of q_out uses the theta variable read from infile, instead of an external value of theta. Without the local declaration, restore would clobber the external value of theta. This way, when q_out_file calls q_out, it has remembered the external value of theta, but q_out "sees" the value of theta restored from infile. When q_out_file finally returns, it replaces the original value of theta intact.

Any number of variables may appear in a single local statement:

 
local var1, var2, var3, var4;