lua-users home
lua-l archive

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


Consistency is good :) I can live with that.
Being more intuitive is always helpful though. I know that gsub always returns all values, but I was thinking of the filter that is inherent in any assignment that involves discards. Intuitively, it makes sense for the single bracket usage to get the single output, multiple (double) brackets for multiple returns yielding more information beyond the processed string. I can't help thinking that if I knew what it was that made this odd reversal necessary, I'd also know something very useful about Lua as a whole.

David Given <dg@cowlark.com> wrote:
(29/08/2004 22:00)

>
>It's not a special request; gsub *always* returns multiple values. It's
>just that if you just say x = string.gsub(...) then all except the first
>one are discarded.
>
>It just so happens that if a function that returns multiple values is
>the last item in an argument list or a table definition, then all the
>values are appended. If you'd done:
>
>	io.write(string.gsub(...), 4)
>
>...then you would have seen the expected result (one string followed by
>a 4).
>
>So Lua is behaving completely consistently, if a little unintuitively.
>
>-- 
>[insert interesting .sig here]