lua-users home
lua-l archive

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


A suggestion for Lua identifiers: what if the characters "?" and "!" were
allowed in identifier names?

Typically, "?" is used for functions which return true/false and "!" is
used for functions which alter their arguments.

That would allow you to see for example that:

    table.sort!( x )

alters x whereas

    table.sort( x )

does not (and thus probably returns a sorted table).

And of course the "?" is potentially useful for many things:

    table.empty?( x )
    table.contains?( x, "a" )

And of course you could see that:

    table.empty!( x )

isn't a predicate, but rather actually empties the table.

It's easy to replace the "...?" suffix with an "is..." prefix, but the "!"
is handy because it's hard to come up with letters that have the same
"feel".

(These conventions date back to T, the first real implementation of
Scheme.)