-
Notifications
You must be signed in to change notification settings - Fork 14
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
Feature request - multiple returns from a function #138
Comments
I have some plan for returning additional values from functions. My intent is to do so through function parameters declared as output, i.e.
This approach seems easier to implement in the parser/grammar. I need to rewrite the grammar anyway and I hope I'll be able to get to it soon. |
Cool! I think like C# it should be a compile error for the caller to not explicitly mark a variable as out
In C# there are two types of out. There is out and ref. out defines a variable in the function for the caller to use. ref requires the caller to have already created a variable, so the function receives an initialized variable to modify. If you want to do just one, ref is probably the more useful one. The example
Note that here I am wanting to use t_startup1 / 2 as a ref, but doing it via a global. It would have also been better to pass fuel_1 as ref also.
|
I do envision both I don't want to invent new syntax at all costs, but there are no references in mlog. Marking the parameter as On the other hand, Explicitly marking the variable in the function call is also a good idea. |
This is now covered by #142. |
Allow functions to "pack tuples" of return values and unpack them on assignment. If the number of return values does not match the calling line then that is an error.
This lets you do some processing and return multiple useful things per item you processed.
Naturally one workaround for non-reentrant functions is to return additional values in globals.
The text was updated successfully, but these errors were encountered: