Home Page   We Generate Your Software.
Products Services Company Technology Demo Contact Site Map Search
The Somusar/SoProTech[tm] Booklet Series
Volume VI

"somusar/Tefigel: Reference Guide"

Printer friendly


Contents
1. Introduction
2. File Sections
3. Commands and Instructions
4. Markers
5. Comments
6. Special Characters
7. Variables
8. Arithmetic Computation
9. Boolean Computation
10. Control Flow
11. Subroutines and Functions
11.1 Purpose
11.2 Usage
11.3 Description
12. Built-in Functions
13. Input and Output
14. Packages and Libraries
15. Tag File Processing
16. CSV File Processing
17. Filters
18. Links and Traps
19. Name Spaces
20. Miscellaneous
21. Further Reading

Chapter 11 - Subroutines and Functions

11.1 - Purpose        top

Divide a complex file generation process in a set of simpler functional modules that insulate repetitive or specific tasks and are easier to write, test, and manage.

11.2 - Usage        top

Transfer control to a subroutine (a file) in the same variable name space:

   process <file-reference>
Transfer control to a subroutine (a file) in the same variable name space, ignoring non-existent subroutine files:
   process_if_readable <file-reference>
Transfer control to a subroutine (a file) in a new variable name space:
   [call] <subprogram-reference>
   [call] <subprogram-reference>(<parameter-list>)
Transfer control to a function (a file) in a new variable name space, using its return value within a logical line:
   <call-key><subprogram-reference>(<parameter-list>)
Assign values of a <parameter-list> to a corresponding set of variables in the new variable name space of current function:
   interface(<new-variable-list>)
Shift the <parameter-list>:
   shift
Set return value of current function:
   retvalue=<value>
Return from a function or subroutine:
   quit
Declare a file to be a <code-file>:
   codefile
Note:

Instruction codefile is obsolete and superseded by <file-section>'s.

   
   

11.3 - Description        top

A <file-reference> can be either a valid file pathname - absolute or relative - or a <variable> containing a string corresponding to a valid pathname. Relative file pathnames of functions or subroutines are first sought for with respect to the working directory of Tefigel, then using the current <library-path-specifier>, described later in the guide. Tefigel will first attempt to access the file with the given name; in case of failure it will try to access the file adding the extension ".tfg". In other words, extension ".tfg" is optional and may be omitted in <file-reference>'s.

A <subprogram-reference> can be either a <file-reference> or a <built-in-function>. The call instruction may be omitted.

A <parameter-list> is a sequence of strings or <variable>'s, separated by the character currently associated with <special-function> argdelim.

The <call-key> is the character currently associated with <special-function> callkey.

A <new-variable-list> is a sequence of <variable>'s, separated by the character currently associated with <special-function> argdelim.

The <parameter-list> may be omitted, in which case it is also possible to omit the left and right parentheses. Arguments supplied as parameters to a function or subroutine are made available in the new name space of the called function or subroutine as "register" variables identified as REG_0, REG_1, REG_2, etc., according to their sequential position in the <parameter-list>. Unspecified registers are guaranteed to be initialized to the empty string. The number of arguments is available in variable REG_COUNT. The complete list of arguments is also available in variable REG_ALL.

Instruction shift transfers the contents of each REG_n into REG_n - 1, decrements REG_COUNT, and updates REG_ALL accordingly.

Instruction interface automatically initializes each variable in the <new-variable-list> to the value of the register in the corresponding order position. A <new-variable-list> in the form "..." specifies that the function or subroutine has a variable number of parameters, hence no automatic initialization is performed.

Beyond positional association, no restriction is imposed, and no check is performed, by Tefigel on the function or subroutine signature, so that it is possible to supply a variable number of arguments to functions and subroutines. Currently, Tefigel supports up to 32 parameters.

Functions may set their return value by means of instruction retvalue.

Returning from a function or subroutine is automatically performed when the end of the file containing the function or subroutine is reached. Alternatively, instruction quit can be used to explicitly return from the function or subroutine.

A <code-file> is a file where each line is interpreted as a <command>.

Note:

This feature is obsolete and superseded by <tefigel-section>'s.

   
   

[Previous chapter]    [Next chapter]    [Back to top]

http:// www.somusar.com  / doc  / booklets  / tefigel_ref  - Powered by SoProMach
Copyright © 2003-2012 Somusar - Trademarks - Legal - Privacy - Webmaster