Optional argument

Hi
I want to tell if a function argument is set or just default.
Basically the equivalent to optional in C++.
How can I do that?
Thanks.

If you are creating a new method it would look like this:

my_method

(Real p1 : 0.0, Real p2)
[
 //...
]

If you were calling it

my_method(, 3.14) // take default parameter for p1
my_method(2.5, 3.14) // specify both parameters

For more examples, look at the auto-generated functions in the GameLib class.

Thanks for replying.
Though setting the default to 0 doesn’t necessary convey the same meaning, I wouldn’t know is 0.0 get passed in or it isn’t set. And I’m not passing a native type.
More specifically, I’m passing in a Vec3 and rotation, both can be optional.

I tried to pass in a None type, like python. But I can’t instantiate a None type.

If you don’t want to associate a special value for the default to a parameter you can essentially make it an optional by indicating that it could either be the type you are looking for (such as Real) or None.

(<Real|None> p1 : nil, Real p2)
  [
  if (p1.not_nil?)
    [
    // Cast away the None and infer Real - same as p1<>Real
    method_taking_real(p1<>)
    ]
  ]

So when calling you can leave it as the default, pass in a real or pass in a nil.

my_method(, 3.14)    // use default parameter for p1
my_method(2.5, 3.14) // specify both parameters
my_method(nil, 3.14) // explicitly specify nil for first parameter

This is a bit different than an optional though it works essentially the same.

In the future I was thinking that we might add some syntactical sugar for <MyType|None> as MyType?.

Perfect. Thanks!
Honestly, I think it would be great if we can explicitly mark some type checking optional. Then we can unlock huge potentials.
I’ve been using python for the last 2 years in work(C++ before that). And with proper testing, it has been working great.

Oh, I recall that SK code get compiled to machine code, right? Then it’s probably not possible to do that. Sad.
The point is, it would be great if we can do meta programming.

On the syntactical sugar, some of them has been a little confusing for me and there are cases where I look at the demo project and don’t know what that line means. And it’s hard to lookup for it. The closure tail look pretty confusing, but haven’t seen any usage of it.
Readability is just too important.

But it might work great after all. Too early to tell, I only started for like a week.