lua-users home
lua-l archive

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


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