[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.gsub and its need for variables..
- From: The Doctor <the_doctor@...>
- Date: Sun, 29 Aug 2004 22:13:54 +0100
'Not intuitive', we were saying, not 'not consistent' :)
Still, I agree with what you said about the missing two and three. Also, to stress one phrase in your own text:
Intuitively, it makes sense for a function to return all it's values
all the time (as they do now) and for [I]all those values to be used in
all contexts where multiple values are expected[/I]...
This is just it, not all those values would be expected if all you wanted to do was print the processed string as a one-off event. It might be neater if that case called for the 'filtering' for one value returned, as it might also be if a single bracketing had been used. Then, you'd either use the double brakets for mutliple return, or, more usefully, an explicit queue of variables, X,Y.. to recieve the individual values.
Eric Tetz <erictetz@gmail.com> wrote:
(29/08/2004 21:54)
>
>The Doctor wrote:
>> 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.
>
>Well, that's not really where the inconsistency lies. That's here, on
>line 7:
>
>1: function bar() return 1,2,3 end
>2: a,b,c = bar() -- a=1, b=2, c=3
>3: a,b = bar() -- a=1, b=2
>4: a = bar() -- a=1
>5: print(bar()) -- 1 2 3
>6: print(0,bar()) -- 0 1 2 3
>7: print(bar(),4) -- 1 4 Huh? Where's 2 and 3?
>
>Intuitively, it makes sense for a function to return all it's values
>all the time (as they do now) and for all those values to be used in
>all contexts where multiple values are expected (line 2-7 above
>above). So line 7 is a bit inconsistent.
>
>The brackets are just a shortcut syntax for this.
>
> first_ret_val = bar()
> print(first_ret_val)
>
>Brackets aren't really inconsistent (or consistent) with anything.
>They are a special case.
>
>Cheers,
>Eric