Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arlie
Wanderer


Joined: 09 Jun 2006
Posts: 62
Location: Florida

PostPosted: Tue Nov 06, 2007 6:49 pm   
 
So basically... void functions or "subroutines" then. That would be great, I have to agree.
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: 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!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: 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. Very Happy
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: 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
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net