lua-users home
lua-l archive

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


On 1/23/19 6:03 PM, Kenneth Lorber wrote:
> [...]
>
>> function string:alike(other) return self:lower() == other:lower() end
>> s = "WomBat"
>> s:alike"wombat"
> true
>> "wombat":alike(s)
> stdin:1: unexpected symbol near '"wombat"'
> 
> Since according to the manual there is one metatable for strings and the string library sets it, we're missing the opportunity to write:
>  io.write("This is the value: '%d'\n":format(x))
> 
> There are other useful cases, but this is the one I think is best (that is, useful and clear) should be enough for people to tell me this is a bad idea :-)
> 
> Opinions please: Why is letting a string literal be more like a string a good or bad idea?
> 
> Thanks,
> Ken
>
> [...]

Personally I don't like it.


We already have syntax sugar allowing to omit parenthesis when
argument is string literal or table.

Looks like it was added on Python hype. But I think it just adds
obscurity:

  * > print 'Hello' .. ', ' .. 'World'

    does not what it looks like (unlike BASIC languages).

  * > print 0

    does not work, unlike [[ print '0' ]].

So some speech is already needed in mentorship tone: "Look lad, there
is special rule in language grammar, allowing skipping parenthesis
for function call when sole argument is string literal or table
constructor. Not number literal or boolean or nil!"


With your additions new obscure cases will be added:

  * > 'Hello' .. ', ' .. 'World':print()

    does not what it looks like.

  * > 0:print()

    does not work, unlike [[ '0':print() ]].

And almost same explanation speech will be needed.


-- Martin