[Date Prev][Date Next][Thread Prev][Thread Next]
- 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. )
When is a string not a string? When it's string literal.
Here's a trivial example adapted from a different context:
> function string:alike(other) return self:lower() == other:lower() end
> s = "WomBat"
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?