Shop OBEX P1 Docs P2 Docs Learn Events
Aliasing Return Values in Methods — Parallax Forums

Aliasing Return Values in Methods

MikerocontrollerMikerocontroller Posts: 310
edited 2009-03-16 22:58 in Propeller 1
· I'm stuck on the concept of the return value being aliased and placed after the PUB method name.
For example:
·······
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?

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-03-16 19:50
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-16 20:06
    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.
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2009-03-16 22:25
    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-16 22:36
    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.
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2009-03-16 22:58
    Thank-you guys. Now it makes sense.
Sign In or Register to comment.