[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: When is a string not a string?
- From: Kenneth Lorber <keni@...>
- Date: Wed, 23 Jan 2019 10:03:12 -0500
(A related question was posed in a different manner back in 2007 but the discussion didn't go anywhere after noting a grammar conflict that IMHO is not relevant for useful use cases. [1])
When is a string not a string? When it's string literal.
Here's a trivial example adapted from a different context[2]:
> function string:alike(other) return self:lower() == other:lower() end
> s = "WomBat"
> s:alike"wombat"
true
> "wombat":alike(s)
stdin:1: unexpected symbol near '"wombat"'
Since according to the manual there is one metatable for strings and the string library sets it, we're missing the opportunity to write:
io.write("This is the value: '%d'\n":format(x))
There are other useful cases, but this is the one I think is best (that is, useful and clear) should be enough for people to tell me this is a bad idea :-)
Opinions please: Why is letting a string literal be more like a string a good or bad idea?
Thanks,
Ken
[1] http://lua-users.org/lists/lua-l/2007-05/msg00059.html
[2] http://lua-users.org/lists/lua-l/2007-03/msg00493.html