lua-users home
lua-l archive

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


On Dec 27, 2019, at 2:20 PM, Sven Olsen <sven2718@gmail.com> wrote:

... took out the tuple handling to simplify things. (Now that it’s [maybe] working I might take a stab at adding it back in, though I doubt I’d ever use it.)

Wait!  Before you go digging any deeper, let's talk about the target semantics!

High level, one of the big warts on any compound assignment implementation is going to be the way it handles (or fails to handle) multi-value assignments.  I've experimented with a couple different rules for multi-value compound assignments.  And, with the benefit of hindsight, I'd say that the one I included in my 2013 power-patch implementation is actually one of the worst rules I've tried.

To review the semantics of that old patch, what I did was to make statements like this one legal:

  a,b,c+=2,f()

That seems like the “correct Lua” way to do it, since that’s how it works with with a normal =. Which isn’t to say I like it--I agree that opens the door to some very confusing code. On the other hand, having a,b,c += 1 increment all three also conflicts with Lua’s = operator:

  a,b,c = 1
  print(a,b,c) -- outputs 1, nil, nil

I’ll dodge the question and throw a parse error if it’s compound-assigning to a list. I still need to add that to the patch..

Many thanks for your feedback, and thank you for that patch in the first place! Every time I have to use Lua without it I lose a bit more hair (and I don’t have much left). :)

-Dave