Kara-Moon Forum
November 27, 2021, 11:41:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: You can go back to the main site here: Kara-Moon site
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Function arguments  (Read 492 times)
bvdp
Kara-Moon Master
****
Posts: 1364


WWW
« 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 Smiley

Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 422



« Reply #1 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


Logged
bvdp
Kara-Moon Master
****
Posts: 1364


WWW
« Reply #2 on: January 26, 2021, 04:29:54 PM »

Thanks. Hopefully the documentation-writer muse will find me this week Smiley Looks like there will be a .2 release earlier than anticipated.
Logged

My online life: http://www.mellowood.ca
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.054 seconds with 20 queries.