[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: string literals lack string methods - why?
- From: "Dr. Markus Walther" <walther@...>
- Date: Wed, 11 Feb 2009 16:26:02 +0100
Hi all,
Lua has been said to operate by the principle of 'least surprise' -
but I was surprised that string methods apply to string variables, but
raise an exception with literals:
s = "abcd" ; print(s:match("^%x%x"))
vs.
print("abcd":match("^%x%x"))
I guess I mentally apply a kind of
instantiation-doesn't-change-semantics principle here, hence the surprise.
Question: any deeper reasons for the above behaviour? Can/should this be
rectified?
--Markus