lua-users home
lua-l archive

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

On Tue, 2019-07-23 at 16:59 +0200, nobody wrote:
> On 23/07/2019 16.10, Pedro Tammela wrote:
> > In Python 3.8 there will be a new feature introducing Assignment 
> > Expressions[1]. One of the reasons for such feature is to improve
> > code readability, among other things.
> > 
> > Would assignment expressions improve Lua code readability?
> > 
> > [1]
> (What about multiple-return expressions:  Can you assign only the
> first
> value or all of them?  If only the first, do the return values
> truncate
> to one result or do they still all go through?  Is this a pure
> side-effect (assign x, result is x) or a store-read (assign x, read x
> (which may have been changed by __newindex/__index))? Etc. etc. …)
> -- nobody

I actually think that this isn't bad idea overall, but there's my point
of view onto this: assignment should pass its results after assigning
them (like it does in C/C++). Consider this:

a,g = = local b = {},{}

This creates table, assigns it to local `b`, stores it into ``
and assigns it to global `a`, without indexing `self` and *as well*
assigns different table to `b`.

This may come handy in other cases as well, but multireturn make it
uglier sometimes. For example:

local err,_ -- Define local _
if local val = _,err = returnValOrErr() then

is pretty ugly and it always will be when you need some complicated

However, I do approve this idea if it will allow to define variable
inside `if` condition.

v <>