Paramater passing bug or feature?

2007-01-15
2013-05-02
  • Hi,

    I noticed that, in the syntax highlighter, calls do not pass any parameters already defined in the current context on to the subroutine being called.  Is this the intended behavior?

    A situation where you would want parameters to be accumulated is the following.  One syntax description calls another and passes a parameter.  That parameter is intended to change some behavior of the latter syntax description.  The behavior to be altered is implemented in a subroutine.  What is a situation where it would be undesirable to accumulate parameters?

    One advantage to not automatically accumulating parameters is that parameters can be accumulated manually, but doing so results in very ugly code.  If parameters are automatically accumulated, then there is no way to prevent the accumulation, since there is no way to undefine parameters.

    Here is an example.  The following syntax highlighter description highlights everything blue:

    blue.jsf:
    =Default
    =Red            red
    =Green          green
    =Blue           blue
    =Yellow         yellow

    :initial Default
            *       initial noeat call=.sub(X)

    .subr sub

    :sub Default
            *       initial noeat call=.subsub(Y)

    .end

    .subr subsub

    .ifdef X
    .ifdef Y
    :subsub Red
    .else
    :subsub Green
    .endif
    .else
    .ifdef Y
    :subsub Blue
    .else
    :subsub Yellow
    .endif
    .endif
            *       subsub

    .end

    It is possible, if ugly, to accumulate parameters manually.  The following syntax highlighter description highlights everything red:

    red.jsf:
    =Default
    =Red            red
    =Green          green
    =Blue           blue
    =Yellow         yellow

    :initial Default
            *       initial noeat call=.sub(X)

    .subr sub

    :sub Default
    .ifdef X
            *       initial noeat call=.subsub(X Y)
    .else
            *       initial noeat call=.subsub(Y)
    .endif

    .end

    .subr subsub

    .ifdef X
    .ifdef Y
    :subsub Red
    .else
    :subsub Green
    .endif
    .else
    .ifdef Y
    :subsub Blue
    .else
    :subsub Yellow
    .endif
    .endif
            *       subsub

    .end

    Charles J. Tabony

     
    • I should mention that, while parameters cannot be undefined, it is still possible to get the behavior of non-accumulating parameters if parameters accumulate.  When making a call, you can add a parameter like ignore_param.  Then wrap every use of param with a test for ignore_param.

      Basically, either default behavior results in ugly code when the other behavior is desired.

      Charles J. Tabony