[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Having trouble with variable number of arguments

Having trouble with variable number of arguments

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1  2 

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Thu 11 Sep 2008 09:31 PM (UTC)
Message
Quote:

c = { [xxx] = "a" } -- assigns "a" to c.q
d = { "xxx" = "a" } -- error: '}' expected near '='


I'd expect the last table to work and have (d.xxx == "a") as a result. Why is -that- assignment not supported?


I think the answer would be, it would be ambiguous.

On the face of it, it would seem reasonable to support stuff like:


t = {
     "a" = 22,    -- t ["a"] = 22
     45 = 68,   -- t [45] = 68
     true = 99,  -- t [true] = 99
    2 + 2 = 55,  -- t [4] = 55
    }


Effectively by allowing any sort of constant there. However then you would expect any expression there too (like in the case of 2 + 2).

Now you hit a big problem:


foo = 42
t = {
     foo = 99,  -- t [42] = 99
    }


The entry "foo" is an expression, which happens to be a variable containing 42. However we are already used to that actually meaning:


foo = 42
t = {
     foo = 99,  -- t ["foo"] = 99
    }


So, exceptions would have to be made, to be consistent with what currently happens. The whole thing would probably become a mess.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #16 on Thu 11 Sep 2008 11:04 PM (UTC)
Message
Good reason, I am satisfied. ^_^

(Although I still say it's the wrong way around.. dum dum.)
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #17 on Thu 11 Sep 2008 11:33 PM (UTC)
Message
Well, you wouldn't have to allow arbitrary expressions -- you could stick with identifiers and string literals only. Of course, then you have an inconsistency of sorts of only allowing string constants.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


40,649 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]