Am 22.03.2023 um 10:19 schrieb Sven Schreiber:
Am 22.03.2023 um 02:49 schrieb Cottrell, Allin:

Sorry, I don't really understand this example. If opts is not supplied
there's nothing to be checked, so one should simply do

if exists(opts)
   bcheck(&defaults, opts)
endif
Yes, again the point is: why do we need this if block with the exists() check in the first place when all we want to do is to channel opts to bcheck?

One addendum to this problem, based on real-world code: It is not unusual that there is a middle function layer before the bcheck() function comes into play. In a stripped-down pseudo example:

<hansl>

function void toplevel (matrix myinput, bundle options[null])
    matrix someneededstuff = middlelayer(options) # fails when options is absent
    # then continue to act on myinput and someneededstuff
end function
#
function matrix middlelayer (bundle options[null])
    bundle defaults = _(x = 1)
    if exists(options)
        bcheck(&defaults, options)
    endif
    # here one would do some useful stuff
    return mshape(defaults.x, 2,2)    # just a placeholder
end function
#
toplevel(I(2))

</hansl>

This example will currently fail at the first line inside toplevel(), even though the bundle arg is marked as optional at all function levels! Sure, one can insert more checking code with exists(), and that is currently the workaround. But does it have to be that way forever?

thanks

sven