Am 21.03.2023 um 19:51 schrieb Cottrell, Allin:
One more go on this...

On Tue, Mar 21, 2023 at 1:53 PM Sven Schreiber
<sven.schreiber@fu-berlin.de> wrote:

<hansl>
function void level2 (string s2)
    eval exists(s) ? s : "nothing"
end function
[ BTW note confusion between s2 and s here ]
Yes, that was a typo, sorry. In this example it is inconsequential, however, because the point is what happens when "null" is passed in.
The second null-setting is never necessary. Revised version:
...
function void level1 (string s1[null])
   level2(exists(s1) ? s1 : null)
end function

This was in fact also my first version of the example, but then I decided to make it visually more explicit. I mean what you do there in the ternary statement is also a second and explicit null-setting, that's why you have to write the keyword "null" again. So I don't think this serves as a valid counter-example. Or am I missing your point?

Let me get back to your answer in the first reply message: "If level2() wants to permit skipping the s2 argument..." -- No, that's not really the aim. The real-world problem is that sometimes a top-level function gets some kind of input which _might_ be null, and it wants to pass on that input to a nested-level function. This kind of "pass-through" operation is currently not possible with some overhead checking (and/or explicitly null-setting) code like the stuff above.

To put it differently, we don't want to skip s1 in the call to level2, because we don't know in general what its value is going to be at runtime.

Let me give you another example which might be more realistic and thus perhaps more useful; it's based on an options bundle that may or may not be provided by the caller:

<hansl>

function void level1 (bundle opts[null])
    bundle defaults = _(x=5)
    bcheck(&defaults, opts)  # causes an error in this example
end function
level1()

</hansl>

Again, to overcome this problem we could add the explicit null-setting, as in these lines:

bundle b = null
bcheck( &defaults, exists(opts) ? opts : b )

Another way would be:

bcheck( &defaults, exists(opts) ? opts : defbundle() )

But --BTW-- what does _not_ work here for me in this bundle case are these variants (on snapshot March 6th):

1) bcheck( &defaults, exists(opts) ? opts : null )

2) bcheck( &defaults, exists(opts) ? opts : _() )

thanks!

sven