On Tue, Mar 21, 2023 at 6:43 PM Sven Schreiber <sven.schrei...@fu-berlin.de> wrote: > > 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.schrei...@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.
Not totally inconsequential, in that passing "null" as an argument keyword would automatically fail for level2() as written, since a missing argument is not permitted by the function's signature. > 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? Well, I didn't take my example as a case of "null-setting" (as in with your string, where you created a named, empty string variable). My case just uses "null" as a keyword, meaning "don't pass any argument corresponding to this parameter". If one wanted something less terse than the ternary expression, the equivalent would be if exists(s1) level2(s1) else level2() endif > 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> 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 Moreover, the second argument to bcheck() is not optional, so passing null as a substitute is not going to work. If in context the opts bundle is supposed to contain at least one required key + setting, then the function whose role is to pass opts to bcheck() should not permit null in place of opts. However, thinking about the 3-argument usage of bcheck(), perhaps I'm beginning to see what you mean. I need to think about it some more. Allin _______________________________________________ Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it Website: https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/