ENIGMA Forums

Contributing to ENIGMA => Proposals => Topic started by: TheExDeus on January 05, 2013, 10:27:38 am

Title: Returning multiple variables
Post by: TheExDeus on January 05, 2013, 10:27:38 am
Hi! I know this was mentioned before and Josh even made up a way on how it would work, but I would just stress how much this is needed. In GM the biggest problem I ever had is that I cannot return more than one variable in scripts. This makes me use either globals (which is just ugly) or several scripts (which is just slow, because things like find_line_intersect_x and find_line_intersect_y calculate the same thing, but I have to do it twice to return both x and y). So please please please please, hook up the parser and do this as the first great thing that will ever happen.

[x,y] = find_line_intersect(...);
Title: Re: Returning multiple variables
Post by: Josh @ Dreamland on January 05, 2013, 09:24:49 pm
I'm hijacking this thread. This thread is now about determining a syntax for functions declarations.

My plan to allow doing what you are describing is to use the Definitions resource that's been on Ism's plate for six centuries to allow declaring EDL functions.

Do we stick to C++ syntax, or somehow incorporate a function keyword?

ENIGMA handles its declarations manually, so we can do basically anything.

The benefit to using the function keyword is that it makes closures syntactically unambiguous. Consider [snip=js]function() { return 1.337; }[/snip]. I could easily enough coerce that for a type, but that isn't the point. The alternative is [snip=edl]double() { return 1.337; }[/snip], but [snip=edl]double()[/snip] already means "the default value of a double," which is 0d.

The hybrid alternative is a little uglier, but completely unambiguous: [snip=edl]function double() { return 1.337; }[/snip], or [snip=edl]function double my_script() { return some_double; }[/snip].

If these functions can't have return types, then there's no point to having them over scripts. So the question is, which do we want more: closures, or not having to use the function keyword?

An array type for [snip=edl][a,b,c][/snip] is in progress, by the way, HaRRi.
Title: Re: Returning multiple variables
Post by: polygone on January 06, 2013, 12:53:15 pm
I say go with function double(), then allow function() as well which will default to variant return type.
Title: Re: Returning multiple variables
Post by: Josh @ Dreamland on January 06, 2013, 01:07:31 pm
Yeah, return type and parameter types will default to variant.