lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


--- Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> We would say that the normal case is to keep only one value, and the 
> special case is to allow multiple values when the function is the last (or 
> the only) one in a list ;-) In Lua, the same function may return different 
> number of values; so, it would be very difficult to understand something 
> like 
> 
>   a,b,c = f(), g()
> 
> if f() can (dynamically) return 1 or 2 values.

Ahh, that's the "idiom where this is useful" that I was wondering about.  It makes sense, seeing
your example, that the only valid place for a function that can dynamically return different
numbers of args would be at the end of the argument list.

> > Are there idioms where this is genuinely useful?
> 
> Not that I know. But if you think that the special case is when Lua keeps
> multiple returns, then for sure there are many useful idioms (for instance 
> «assert(readfrom"name")») 

I was thinking the special case was when Lua discarded return values.  It's easy to see how not
discarding them is useful.  Now I see why sometimes discarding them is simply necessary.

Thanks,
Eric

__________________________________________________
Do You Yahoo!?
Yahoo! Messenger - Talk while you surf!  It's FREE.
http://im.yahoo.com/