[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A useful useless fact about Lua keywords
- From: Hugo Musso Gualandi <hgualandi@...>
- Date: Mon, 13 Sep 2021 19:48:14 -0300
As of Lua 5.4, there are no two keywords that share the same first and
last letter. There are some that start with the same two letters,
(else/elseif, repeat/return) but if we look at the first and last
letter they are unique. For example, the only keyword that starts with
"e" and ends with "f" is "elseif".
One application of this useless fact would be if one wants to build a
perfect hashing function for just Lua keywords. The hash function
wouldn't have to look at all the characters of the word; just the first
and last one should be enough.
-- Hugo
and break do else elseif end
false for function goto if in
local nil not or repeat return
then true until while