lua-users home
lua-l archive

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


2013/2/11 Richter, Jörg <Joerg.Richter@pdv-fs.de>:

> Still thinking that string.sub( str, 0 ) should return "".

Extending a function beyond its natural domain of definition
always sacrifices something.

E.g. arithmetic with Inf. You can't satisfy all the axioms
of the real numbers, whether including projective Inf or
affine +Inf and -Inf, neither choice works for everything.

Now, the natural domain for string.sub is 1 to #str,
which we can alias as -#str to -1, but that alias does
not carry continuously to 0. No matter what you make
str:sub(0) mean, it will be in some way illogical.

My opinion is that str:sub(0) should return nil if not
an actual error, but that is a personal choice. So is
yours, the empty string, a personal choice. Lua 5.2.1
has another personal choice, probably dictated by
some application in which making it mean the same
as str:sub(1) was the least among evils.