FUNCTIONS:OVERVIEW
path: NCI:REGULATORY AGENCIES > NEWS:NUWIKI > ABOUT SCCS > SHL:MENU > FUNCTIONS:OVERVIEW
Nucleus Functions and the Pre-Compiler
Expandable functions enable a single set of source code to provide similar functionality across many platoforms as well as a way to modularize functionality without writing a subroutine.
Functions are items stored in one of two default libraries (files). The default functions library is SBP,FUNCTIONS. The pre- compiler first searches the thisbp,FUNCTIONS data area n the currently addressed BO-type file. If the function is not found or the data area does not exist the search continues in the SBP,FUNCTIONS file. To include a function library in addition to the two mentioned above, use the #INCLUDE directive at the beginning of your program.
INCLUDE yourBPFileName
For Example, #INCLUDE MYPROJISUB would search MYPROJISUB,FUNCTIONS. This indicates that the functions will first be looked for in MYPROJSUB,FUNCTIONS before the two default libraries.
Syntax
To include a function in a BASIC program:
{Function(arg,arg,…)}
The Function name is an item id for an entry in the function library. In the program source code, functions are offset from the rest of the code by braces ({})
Example and Usage
Consider the example where a function called EREPLACE is used to replace any substring by a replacement string where VM has been previously equated to CHAR(253).
Astring = ‘aa;bb;cc;dd;ee’EREPLACE(Astring,’;’,VM)}
Astring is now value delimited instead of semicolon delimited.
{EREPLACE(Astring,’dd’,’xxx’)}
The substring dd in the fourth value is now xxx.
The default function EREPLACE is as follows;
EREPLACE
001 ! function: EREPLACE(string,srch,rep)
002 IF {2} # '' THEN
003 LOOP
004 Z$ = INDEX({1},{2},1)
005 WHILE Z$ DO
006 {1}={1}[1,Z$-1]:{3}:{1}[Z$+LEN({2}),32000]
007 REPEAT
008 END
009 !
NOTE The pre-compiler uses commas (,) as delimiters for function arguments. Therefore literal commas CANNOT be used as one of the arguments in a functions. If it is necessary to use a comma as one of the arguments, it is suggested to equate it to a descriptive name and use the name in the function. i.e. EQU comma TO ','
Use this method:
- {EREPLACE(ThisFunction,Comma,VM)} which will replace a comma with a value mark
This method will fail:
- {EREPLACE(ThisFunction,',',VM)}
The numeric expandable arguments, {1},{2}, and {3} refer to the contents of the argument positions. From the above example, EREPLACE would expand as follows:
- searches this BP file’s FUNCTIONS data area. If the function is not found or the data area does not exist the search continues in the SBP,FUNCTIONS file.