|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Nov 06, 2007 4:52 pm
Implicit function returns? |
How hard would it be to add an implicit #return 1 to the end of a function without a #return command? There could be some deliberate reason why it's not like that already, I suppose, but it's just a thought. Sometimes you want to create functions that're pretty much just aliases, but not meant to be called from the command line. It'd make doing that slightly more simple.
|
|
|
|
Arlie Wanderer
Joined: 09 Jun 2006 Posts: 62 Location: Florida
|
Posted: Tue Nov 06, 2007 6:49 pm |
So basically... void functions or "subroutines" then. That would be great, I have to agree.
|
|
|
|
JQuilici Adept
Joined: 21 Sep 2005 Posts: 250 Location: Austin, TX
|
Posted: Tue Nov 06, 2007 8:21 pm |
It's not clear to me that '1' is the best default return value from a function (I can make a good argument for '0' or a null string, for instance). I'd rather just see the parser choke and alert you so that you can add a return value.
If you're just looking for private aliases...just put 'em in a private (i.e. local) module. Can't be called from the command line or outside your package. |
|
_________________ Come visit Mozart Mud...and tell an imm that Aerith sent you! |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Nov 06, 2007 8:46 pm |
What the return is is pretty irrelevant, really, since if you cared about what the function returns, you'd've given it an explicit return. 0 or "" are fine.
|
|
|
|
JQuilici Adept
Joined: 21 Sep 2005 Posts: 250 Location: Austin, TX
|
Posted: Tue Nov 06, 2007 8:49 pm |
Fang Xianfu wrote: |
What the return is is pretty irrelevant, really, since if you cared about what the function returns, you'd've given it an explicit return. |
True enough. |
|
_________________ Come visit Mozart Mud...and tell an imm that Aerith sent you! |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Nov 06, 2007 8:52 pm |
I can certainly make it return "" or null be default. That's very easy. I'll see what I can do.
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Tue Nov 06, 2007 9:06 pm |
I think null or 0 would be better then the current return of whatever is left on the stack. As long as the implicit return value behaves according to whatever type is set for the function it is perfect. I would say autotype, array, and comobject should have implicit returns of null string.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Nov 06, 2007 9:12 pm |
Well, it will *still* return the last thing on the stack if there is something there. That was needed to make it easy to convert existing variable-type functions into real functions. I'm not going to change that.
The change I am talking about only applies if there is nothing on the stack when the function exits. Right now it gives an error, and Fang is just asking for it to return null instead of given an error message.
The return value is an "auto-typed null value". This looks like an empty string, or a zero, or an actual nil/null value for comobjects, arrays, etc. |
|
|
|
|
|