View Full Version : Aliasing Return Values in Methods
03-17-2009, 03:28 AM
· I'm stuck on the concept of the return value being aliased and placed after the PUB method name.
PUB Active: YesNo
· YesNo := Cog > 0
· From my understanding the return result for the PUB Active method is aliased to the variable YesNo upon exit from this method.· Does this mean that the next time that Active is called it will not execute if YesNo·was false?· What effect does placing the colon symbol and return value after the method name have?
03-17-2009, 03:50 AM
My understanding is that is's only for giving the return value a name. Don't mix that up with parameter list or local variables.
03-17-2009, 04:06 AM
MagIO2 is correct. The default name for the return value is RESULT. Giving a name after a colon simply substitutes the given name for RESULT.
The actual variable (either RESULT or a given name) only exists within the method and it's initialized to zero every time the method is called. It's
allocated in Spin's stack along with the return address from the method call and some other information related to the call.
03-17-2009, 06:25 AM
I took this example from Chapter 3 Exercise 7 of the Propeller Manual. Does the program flow stop at this method if the Cog variable evaluates to FALSE? What action is taken by the program based on the state of RESULT? I see that the VARIABLE Cog is aliased to YesNo but I can't see what action is taken based on that result in this method. I'm stuck in Basic logic : if Yesno=False then....what happens???? I don't see what the program is doing with the return result. Thanks for your patience. I'm misunderstanding this at a very basic level.
03-17-2009, 06:36 AM
From outside the method Active, there is no such thing as YesNo. Effectively, writing the name Active is the same as writing the expression Cog > 0, that's all. The method doesn't do anything else. You haven't written anything else to call Active and do something with the value produced.
03-17-2009, 06:58 AM
Thank-you guys. Now it makes sense.