Problem with EXPOSE in Methods

Help
2013-06-25
2013-06-27
  • Tim Tierney
    Tim Tierney
    2013-06-25

    I have encounter what I believe to be a problem with using a variable name list in the EXPOSE keyword. The following code snippet illustrates the issue:

    /-- REXX Procedure: testExpz --/

    lHandl = .testExpose~new( )
    Exit 0

    ::Class testExpose

    ::Method Init
    Expose ( GBLz )

    val01 = "001"
    GBLz = "val01"

    self~MethA()

    Return 0

    ::Method MethA
    Expose ( GBLz )

    trace i
    localLst = GBLz
    localVar = val01

    Return 0

    The trace info from the execution of the above is:

    C:\Windows\system32>testexpz
    23 - localLst = GBLz
    >V> GBLZ => "val01"
    >>> "val01"
    >=> LOCALLST <= "val01"
    24 - localVar = val01
    >V> VAL01 => "VAL01"
    >>> "VAL01"
    >=> LOCALVAR <= "VAL01"
    26 - Return 0
    >L> "0"
    >>> "0"

    I could easily be misunderstanding how this facility should function, so any help is appreciated. Thanks!

     
  • Rick McGuire
    Rick McGuire
    2013-06-25

    Yes, you are misunderstanding how this functions. The EXPOSE instruction will do the following:

    1) Expose the named variable.
    2) Evaluate the variable's value and process the list of names in the value and expose each of those variables in turn.

    So, in your INIT method, the variable GBLz is exposed and evaluated. Since the variable is uninitialized, its value is "GBLZ". As a result, the variable GBLZ is exposed again, which is not an error. The processing of the EXPOSE instruction is done.

    The subsequent assignments of values to GBLz and val01 do NOT result in val01 getting exposed as an object variable and and value assigned to that variable. val01 remains a local variable, and but when GBLz is used in another EXPOSE instruction, it will result in val01 getting exposed, but the variable will still be uninitialized.

     
  • Tim Tierney
    Tim Tierney
    2013-06-25

    OK. I believe I follow that explanation. However, how does one get the EXPOSEd variable - in this case GBLz - initialized so that it can be used to communicate values between methods? When/where do I set the variable GBLz to a usable named list if not in the INIT method? Setting it prior to the ".testExpose~new( )" request shouldn't (and does not) work.

     
  • Rick McGuire
    Rick McGuire
    2013-06-25

    Well, since the init method already knows what variables you are going to expose, just specify those on the initial expose then assign GBLz so that all other methods can use this. Although my preference would be not to even use the dynamic form at all, but just explicitly specify the variables you are going to use in the methods that use them.

     
  • Tim Tierney
    Tim Tierney
    2013-06-25

    Alright - I modified the INIT method EXPOSE to:

    Expose GBLz val01

    and the the previous example worked correctly. As to exposing each variable discretely, I tend to use the name lists in EXPOSEs (as in a "Procedure Expose") to handle the cases were I've needed access to a lengthy set of "global" variables in otherwise isolated subroutines and functions - this is in legacy REXX of course. I'm still trying to adapt to the new world of ooREXX. Thanks for the help.

     
    • Staffan Tylen
      Staffan Tylen
      2013-06-25

      For what it's worth: Instead of trying to remember which variables need to
      be accessible in other methods I've adopted using a stem variable G.
      covering all variable names that need to be exposed. I'm sure there are
      opinions against this but it has worked fine for me and it has saved me lot
      of debugging efforts, that I'm sure of. Whenever I see g.something I know
      it's an exposed (global) variable. And coding wise each method is simply:

      ::method abc
      expose g.

      I'm happy to listen to the arguments against doing it this way :)

      Staffan

      On Tue, Jun 25, 2013 at 6:13 PM, Tim Tierney ttierney@users.sf.net wrote:

      Alright - I modified the INIT method EXPOSE to:

      Expose GBLz val01

      and the the previous example worked correctly. As to exposing each
      variable discretely, I tend to use the name lists in EXPOSEs (as in a
      "Procedure Expose") to handle the cases were I've needed access to a
      lengthy set of "global" variables in otherwise isolated subroutines and
      functions - this is in legacy REXX of course. I'm still trying to adapt to
      the new world of ooREXX. Thanks for the help.


      Problem with EXPOSE in Methodshttps://sourceforge.net/p/oorexx/discussion/408478/thread/611b9c94/?limit=25#58d9

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/oorexx/discussion/408478/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • mukenx
        mukenx
        2013-06-27

        I also used the expose (globalVars) to pass around a long list of variables
        in e.g. a UserDialog subclass. The problem I ran into was that at one point
        it was difficult to see inside a given method (that possibly needed only
        one or two of those global vars) which variables were global and which not.

        Some more thoughts:
        use (private) attributes and dispense with the expose.

        ::Class testExpose

        ::attribute val01 private

        ::Method Init
        self~val01 = "001"

        self~MethA()

        Return 0

        ::Method MethA

        say self~val01

        Return 0

        Madou

        2013/6/25 Staffan Tylen st2430@users.sf.net

        For what it's worth: Instead of trying to remember which variables need to
        be accessible in other methods I've adopted using a stem variable G.
        covering all variable names that need to be exposed. I'm sure there are
        opinions against this but it has worked fine for me and it has saved me lot
        of debugging efforts, that I'm sure of. Whenever I see g.something I know
        it's an exposed (global) variable. And coding wise each method is simply:

        ::method abc
        expose g.

        I'm happy to listen to the arguments against doing it this way :)

        Staffan

        On Tue, Jun 25, 2013 at 6:13 PM, Tim Tierney ttierney@users.sf.net wrote:

        Alright - I modified the INIT method EXPOSE to:

        Expose GBLz val01

        and the the previous example worked correctly. As to exposing each
        variable discretely, I tend to use the name lists in EXPOSEs (as in a
        "Procedure Expose") to handle the cases were I've needed access to a
        lengthy set of "global" variables in otherwise isolated subroutines and
        functions - this is in legacy REXX of course. I'm still trying to adapt to
        the new world of ooREXX. Thanks for the help.


        Problem with EXPOSE in Methods
        https://sourceforge.net/p/oorexx/discussion/408478/thread/611b9c94/?limit=25#58d9

        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/oorexx/discussion/408478/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/


        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/oorexx/discussion/408478/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/