Please enable JavaScript to view this site.

A-Shell Consolidated Reference

Navigation: A-Shell BASIC (ASB)

User-Defined Functions

Scroll Prev Top Next More

Updated October 2016; see History

{PRIVATE} {DYNAMIC} FUNCTION FN'name{$}(p1{=defval} {as typsiz{:mod}},...pN{=defval} {as typsiz{:mod}} ) {as typsiz}

<optional local MAP statements, with optional STATIC prefix>

<optional XGETARGs>

<nearly any kind of statements>

    FN'name = <expression>    ! set return value

ENDFUNCTION

The function definition, as shown above, starts with the zero or one of the optional keywords "PRIVATE" / "DYNAMIC" (see Private Functions and Procedures and Dynamic Functions for details), followed by the keyword "FUNCTION" followed by the function name, the list of formal parameters, and the function return type. The function name must start with FN', Fn', or fn' so that references embedded in expressions can easily be identified as function calls rather than arrays; see Function Name and Type for clarification. The function name must end with $ if the function returns a string or unformatted or defined structure type. If the final {as typsiz} clause (which defines the return type of the function) is omitted, the default type is F6.  

The typsiz (data type and size) specification is similar to that used in MAP statements, except without a comma between the type code and the size. For example:

FUNCTION Fn'Test(p1 as S10, p2 as f6, p3 as B2, p4 As x256) AS i2

 

Function fn'display'name$(cus as ST_CUS_REC, bold as BOOLEAN) as s MAX_NAME

 

function fn'test(p1 as s20:inputonly, p2 as ST_PHONE:outputonly)

 

The first example above illustrates that, as with virtually all keywords, the FUNCTION keyword and AS typsiz clauses are not case sensitive. However, as with all other variables and labels, the function name and the formal parameter names are case sensitive, unless compiled with the /ci option.

The optional {=defval} clause assigns a default value to the parameter; see Named Parameters.

The optional :mod clause may be used to declare certain modifying attributes for the parameter, such as inputonly or outputonly; see Parameter Type and Size.

See Also

XFUNC in System-Defined Functions
SOSLIB:[907,10] also known as SOSFUNC

History

2016 August, A-Shell 6.3.1523, compiler edit 770:  Add private attribute for functions and procedures.

2014 October, A-Shell 6.1.1391:  Function name does not need to begin with FN'; see History note in Function Name and Type

2014 September, A-Shell 6.1.1389:  A-Shell now supports Passing DIMX Arrays to functions/procedures by reference.

2014 January, A-Shell 6.1.1373: Named parameters implemented in A-Shell.

Subtopics

Function Name and Type

Parameter Type and Size

Named Parameters

Parameter Passing

Return Expression

Local Variables

Global/External Variables

Exit Label $EXIT

Error Trapping in Functions

Invoking A Function

Private Functions and Procedures

Dynamic Functions

Ellipsis Function Arguments

Indirect Function Calls

User-Defined Function Examples

Implicit Function Return Value Capture