12.07.2015 Views

GLE User Manual - Fedora Project Packages GIT repositories

GLE User Manual - Fedora Project Packages GIT repositories

GLE User Manual - Fedora Project Packages GIT repositories

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

52 CHAPTER 6. PROGRAMMING FACILITIESInside a subroutine, the keyword ‘local’ can be used to define local variables. E.g., ‘local x = 3’,defines the local variable ‘x’ and assigns it the value 3. It is also possible to define several local variablesat once, as is shown in the ‘grid’ example above.The keyword ‘return’ can be used to return a value from a subroutine. E.g.,sub gaussian x mu sigmareturn 1/(sigma*sqrt(2*pi))*exp(-((x-mu)^2)/(2*sigma^2))end subThe main <strong>GLE</strong> file will be much easier to manage if subroutine definitions are moved into a separate file:include "griddef.gle"amove 2 4grid 2 4amove 2 2grid 9 5More information about the “include” command can be found on page 14.6.6.1 Default ArgumentsGiven the following subroutine definition:sub mysub x y color$ fill$default color "black"default fill "clear"print "Color: " color$print "Fill: " fill$end subthe following calls are valid:mysub 1 0mysub 1 0 redmysub 1 0 red greenmysub 1 0 fill bluemysub 1 0 color redmysub 1 0 color red fill blue6.7 Forward DeclarationsA forward declaration of a subroutine is possible with:declare sub mysub x yForward declarations are required for declaring mutually recursive subroutines.6.8 I/O FunctionsThe following I/O functions are available:fopen name file [read|write]Open the file “name” for reading or for writing. The resulting file handle is stored in variable “file”and must be passed to all other I/O functions.fclose fileClose the given file.fread file x1 . . .freadln file x1 . . .Read entries from “file” into given arguments x1 . . .

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!