Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional modifier to operation parameter #75

Open
jryannel opened this issue Apr 18, 2018 · 2 comments
Open

add optional modifier to operation parameter #75

jryannel opened this issue Apr 18, 2018 · 2 comments
Milestone

Comments

@jryannel
Copy link
Collaborator

An operation paraterm shall be able to be optional. This would lead in a C++ generator to an overloaded operation.

void add(int a, optional b);

This feature shall be in the extended language profile

@jryannel
Copy link
Collaborator Author

jryannel commented May 2, 2018

Having several parameters which are optional will make code-generation complicated.

int add(optional int a, optional int b, optional int c)

You would need to generate several operation in a C++ generator

int add()
int add(int a, int b)
int add(int a, int b)
int add(int a, int b, int c)

This will really difficult in the templates to a) recognise and be handle accordingly.

{{ for par in operation.parameter }}
  {{if par.optional }}
  ???
  {{ endif }}
{{ endfor }}

The generator developer would be required to develop its own extension. This seems to be utterly complex. Better choice would be to have the permutations already ready in the parser, but this would require knowledge about the target language, as for example a python generator would handle these optional parameters differently.

def add(a=None, b=None, c=None):
  pass

Currently I do not see a correct solution here, so this feature will not come if I am not getting enlighted :-)

@jryannel
Copy link
Collaborator Author

jryannel commented May 2, 2018

Maybe we could add a special value to the default value, e.g. None.

void add(a = None, b = None, c = None)

This seems to be more in line with default values:

void add(a ="0", b = "0", c = "0")

We then could also use this for properties:

interface Contact {
  property Address address = None
}

Maybe this is also relevant: https://en.wikipedia.org/wiki/Null_object_pattern

void add(int a = Null, int b = Null, int c = Null)

It's then about the code generator to decide if the Null expands to 0 or to an operation override or in case of a complex symbol a null object.

@jryannel jryannel added this to the Cleanup milestone Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant