lua-users home
lua-l archive

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


Am 19.04.2014 09:47 schröbte Dirk Laurie:
2014-04-19 8:46 GMT+02:00 Philipp Janda <siffiejoe@gmx.net>:

Unless I miss something, it seems the `defineclass` function is supposed to
modify some global state in the pattern matching engine. I thought we agreed
by now that this is a bad idea ...

For a given meaning of "we"?

I'll confess to agreeing that it is a bad idea to modify built-in functions,
and my examples demonstrate that.

string.defineclass("%u",utf8.charpatt)
stdin:1: attempt to redefine a built-in character class

The proposal allows for customizable character classes. We already
have that. Nothing (except the vast effort of actually doing it) stops you
from defining your own locale, activating it by os.setlocale(), and hey
presto! the character classes %l, %u, %g, %s and maybe other
classes too (the manual only says "and other character groups")
denote whatever you like.

Do you think that locales were a good idea? We inherited those from C but there's no reason to make the same mistake again just because C made it decades ago.


So all I'm actually proposing is to make custom character classes
explicitly visible as unfamiliar escape sequences, defined from inside
Lua, instead of hiding them in the impenetrable reaches of the
user's OS.

They are hidden and they remain hidden, you just add another layer.
Maybe those configurable character classes are better left to something like LPeg where you can pass them around explicitly.

Philipp