Pages: 1
Author Topic: Returning multiple variables  (26,491 Views)
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Posted on: January 05, 2013, 03:27:38 PM
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(...);
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #1 Posted on: January 06, 2013, 02:24:49 AM
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.
Offline (Unknown gender) polygone

Contributor
Joined: Mar 2009
Posts: 794
View profile
Reply #2 Posted on: January 06, 2013, 05:53:15 PM
I say go with function double(), then allow function() as well which will default to variant return type.
Offline (Unknown gender) Josh @ Dreamland

Prince of all Goldfish
Developer
Joined: Feb 2008
Posts: 2,950
View profile
Reply #3 Posted on: January 06, 2013, 06:07:31 PM
Yeah, return type and parameter types will default to variant.
Pages: 1