• Dave Schwartz
    264
    Ah, now I understand (I think).

    What does the call to reget the variable look like?
  • RanchWest
    503
    If a value is passed in, that SETS the stored value. If no value is passed in, that GETS (fetches) the stored value. In my example, I denoted no passed value as being NIL, but the exact coding would depend on the language.
  • Dave Schwartz
    264
    I'm still confused.

    Function(X1,X2,X3)
    Y= X1 + X2 * X3
    Return Y


    So, if you pass (say) 3 values (x2,x2,x3), and it returns (Y), how do you fetch Y again without passing the values again?
  • RanchWest
    503
    function MySortaGlobal( xValue )
    static xKeep

    if xValue == NIL
    else
    xKeep := xValue
    endif

    return xKeep
    RanchWest

    When a value is passed, it is stored in xKeep and xKeep is returned. When no value is passed, the function returns what is stored in xKeep.
  • Dave Schwartz
    264
    Now I understand.

    So, if I use a function multiple times, it stores the last time xKeep was changed?
  • RanchWest
    503
    Now that you understand that, you could pass in two values. One is the lookup and the other is the change value (or no value). You could then have a do case structure to lookup the value.

    do case
    case cY == "TURN TIME"
    xReturn := aMyStaticValues[hManifest_Constant_For_TURN_TIME]
    case cY == "%MEDIAN"
    xReturn := aMyStaticValues[hManifest_Constant_For_%MEDIAN]
    end case
  • Dave Schwartz
    264
    Got it.
    There is ONE "keep" value or could you have xKEEP,yKEEP,ZKEEP, xFred, TommyBoy and any other number of variables?
  • RanchWest
    503


    Yes, you can have more than one value. My last example there holds the values in an array, but you could pass in multiple parameters. That might get a bit tricky if you're not always passing all of the parameters in and out.
  • Dave Schwartz
    264
    I must be missing something here because I don't see what is gained by calling the function to receive the previous variable.

    If you set xKeep to a value, what is the advantage over simply making xKeep a global variable?

    Since you can only have one xKeep, it is, in effect, a global variable.

    Ah... You could make the function thread-specific.
    Small gain there.

    Am I on the right track?
  • RanchWest
    503
    Let's say you have 10 sections to your handicapping program. And, you use Strength in 6 of those sections. At the top of your program, you can store the Strength value. As you go in and out and in each of the 6 sections where Strength is displayed, you can access it as an already computed value, which is faster than recomputing it every time. And, obviously you are only computing it one time, which means you are only computing it one way... which is clearly way better than the way a beginner might do it, computing in each of the 6 sections, possibly resulting in 6 different ways of calculating the value. Obviously there needs to be a function to calculate Strength.
  • Dave Schwartz
    264
    I understand what you are saying.

    Thank you.
  • RanchWest
    503
    I just had another thought. Organize your calculations between what needs to be re-calculated for scratches and what doesn't.
12Next
bold
italic
underline
strike
code
quote
ulist
image
url
mention
reveal
youtube
tweet
Add a Comment

Please register to see more

Forum Members always see the latest updates and news first. Sign up today.