Propeller Manual

Table Of Contents
RESULT – Spin Language Reference
Page 194 · Propeller Manual v1.1
RESULT
Variable: The return value variable for methods.
((PUB PRI))
RESULT
Explanation
The
RESULT variable is a pre-defined local variable for each PUB and PRI method. RESULT
holds the method’s return value; the value passed back to the caller of the method, when the
method is terminated.
T
When a public or private method is called, its built-in
RESULT variable is initialized to zero
(0). If that method does not alter
RESULT, or does not call RETURN or ABORT with a value
specified, then zero will be the return value upon that method’s termination.
T
Using RESULT
In the example below, the
DoSomething method sets RESULT equal to 100 at its end. The Main
method calls DoSomething and sets its local variable, Temp, equal to the result; so that when
DoSomething exits, Temp will be set to 100
T
PUB Main | Temp
Temp := DoSomething 'Call DoSomething, set Temp to return value
PUB DoSomething
<do something here>
result := 100 'Set result to 100
You can also provide an alias name for a method’s RESULT variable in order to make it more
clear what the method returns. This is highly recommended since it makes a method’s intent
more easily discerned. For example:
PUB GetChar : Char
<do something>
Char := <retrieved character> 'Set Char (result) to the character
The above method, GetChar, declares Char as an alias for its built-in RESULT variable; see PUB,
page 182 or
PRI, page 181, for more information. The GetChar method then performs some
task to get a character then it sets
Char to the value of the retrieved character. It could have