Pages: 1
  Print  
Author Topic: Returning multiple variables  (Read 1327 times)
Offline (Unknown gender) TheExDeus
Posted on: January 05, 2013, 10:27:38 AM

Developer
Joined: Apr 2008
Posts: 1860

View Profile
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(...);
Logged
Offline (Male) Josh @ Dreamland
Reply #1 Posted on: January 05, 2013, 09:24:49 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
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 function() { return 1.337; }. I could easily enough coerce that for a type, but that isn't the point. The alternative is double() { return 1.337; }, but double() already means "the default value of a double," which is 0d.

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

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 [a,b,c] is in progress, by the way, HaRRi.
« Last Edit: January 05, 2013, 09:54:53 PM by Josh @ Dreamland » Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) polygone
Reply #2 Posted on: January 06, 2013, 12:53:15 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
I say go with function double(), then allow function() as well which will default to variant return type.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) Josh @ Dreamland
Reply #3 Posted on: January 06, 2013, 01:07:31 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
Yeah, return type and parameter types will default to variant.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1
  Print