lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Antero Vipunen wrote:

> I follow `escape magic characters everywhere' convention
> (even if it is not necessary).

This is a respectable policy.  I don't follow it because I
find it easy to remember that only a select few characters
are magic within square brackets (this is also how POSIX
regular expressions work).  I do, however, usually follow
the policy of %-escaping nonmagical punctuation so I don't
have to remember Lua's (admittedly small) set of magic
characters, and also as a form of future-proofing.

On a similar topic, here's a quiz about a silly little
program:

io.write([[
"Four score XXX seven years ago"

What would you like to replace "XXX" with?

> ]])
local Input = io.read("*l")
Input = string.gsub(Input, "\n$", "")
local NewStr = string.gsub("Four score XXX seven years ago",
  "XXX", Input)
print(NewStr)

Under what circumstance will the program either disobey the
user's request or or actually error out?  What's the fix?

(Things don't work if the user enters a null byte, but
I'm interested in something else.)

-- 
Aaron