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

[lang][grammar] Default value for function parameters #2

Closed
gallandarakhneorg opened this issue Feb 4, 2014 · 5 comments
Closed

[lang][grammar] Default value for function parameters #2

gallandarakhneorg opened this issue Feb 4, 2014 · 5 comments
Assignees
Milestone

Comments

@gallandarakhneorg
Copy link
Member

It may be useful to specify default values for the parameters:

def myAction(String a, int b=35) {
}
@srodriguez
Copy link
Member

Steph, that's a great idea. However, should capacity definition allow default values?
For agent or behavior actions, it would be clear.

@gallandarakhneorg
Copy link
Member Author

Yes, I guess.
It may be very helpful for the capacity caller to have default values.

We may discuss on the default parameters in Skills.
I have in my mind the default value in the C++.
Let the Capacity is analog to the declaration in the header, and the Skill is analog to the definition in the code file. It is common to define the default values in the header file and not in the code file.
Consequently, the best practice is to define the default values in the Capacity, and not in the Skill.
Is it possible to generate a compilation error when a default value is written in the Skill?

@gallandarakhneorg gallandarakhneorg self-assigned this May 15, 2014
@gallandarakhneorg
Copy link
Member Author

I propose the following syntax:

def myAction1(a : String, b : int = 35) { CODE1 }
def myAction2(a : String, b : int = 35, c : char) { CODE2 }

The generated Java functions will be:

public void myAction1(String a, int b) { CODE1 }
public void myAction1(String a) { myAction1(a, 35); }
public void myAction2(String a, int b, char c) { CODE2 }
public void myAction2(String a, char c) { myAction2(a, 35, c); }

@gallandarakhneorg
Copy link
Member Author

Let the following code with ambiguity:

def myAction(a : char, b : int = 1, c : int = 2, d : char) { }

The generated Java code may be:

public void myAction(char a, int b, int c, char d) { }
public void myAction(char a, int b, char d) { myAction(a,b,2,d); }
public void myAction(char a, char d) { myAction(a,1,2,d); }

gallandarakhneorg added a commit that referenced this issue May 22, 2014
…th default values (issue #2).

The task is not complete, but it is a first step.
@gallandarakhneorg
Copy link
Member Author

Since we are using Xtext 2.6, (issue #93), the jvm inferrer and the validator are not working any more.

gallandarakhneorg added a commit that referenced this issue May 27, 2014
…sue #2.

The hidden functions are whose corresponding to the different possibilities of function implementation according to parameters with default values.
@gallandarakhneorg gallandarakhneorg changed the title Default value for function parameters [lang][grammar] Default value for function parameters Sep 4, 2014
gallandarakhneorg added a commit that referenced this issue Jun 21, 2016
Signed-off-by: Stéphane Galland <galland@arakhne.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants