Kara-Moon Forum

Developers & Technology => Musical MIDI Accompaniment (MMA) => Topic started by: bvdp on January 26, 2021, 12:41:21 AM



Title: Function arguments
Post by: bvdp on January 26, 2021, 12:41:21 AM
The 1st part of this thread is in the 2020-12.1 announcement thread (http://www.kara-moon.com/forum/index.php?topic=8607.0). I'm re-starting it here 'cause the topic really doesn't belong where it was (and still is because I don't know how to move messages).

The upshot is that sciurius has written a neat little patch which permits default NULL or empty arguments in functions. And, that really is neat. I've done a few tests with the new code and it seems to work just fine!

I even tried to create a function with multiple arguments (Defcall Foo arg1,arg2,arg3...) and assign null/empty values to them. Works like a charm.

Now, I need to explain this is the the docs :)



Title: Re: Function arguments
Post by: sciurius on January 26, 2021, 07:29:58 AM
Something like (to be inserted before "We can assign a value to a variable by using a “variable=value” pair." in section Defaults of Subroutines):

You can use Default to assign an empty default value to a parameter, which can be tested with an IsEmpty (of IsNotEmpty) condition:

Code:
DefCall MySub P
    Default P
    If IsEmpty P
      // P was empty, presumably left out
    EndIf
EndDefCall

Note that the following two calls are indistiguishable from the perspective of the subroutine body:

Code:
Set EmptyVar
Call MySub
Call MySub $EmptyVar




Title: Re: Function arguments
Post by: bvdp on January 26, 2021, 04:29:54 PM
Thanks. Hopefully the documentation-writer muse will find me this week :) Looks like there will be a .2 release earlier than anticipated.