[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Are parenthesis-free calls a Good? (was Re: patch: C-style string lexing)
- From: Doug Rogers <rogers@...>
- Date: Thu, 31 Jan 2008 10:16:26 -0500
Luiz Henrique de Figueiredo wrote:
> Eric Tetz wrote:
>> I just posted a small patch to the wiki that allows C-style string
>> lexing, where string literals separated by whitespace are collected
>> as a single string.
> This will break expressions like f "A" "B", which is interpreted as
> f("A")("B"). The program below prints "A<TAB>and<TAB>B". Try it in your
The patch definitely breaks this Lua feature.
Like Asko, I haven't really missed C-style concatenation since Lua has
'[[ ]]' and '..'. As David points out, constant folding in the
interpreter could make Lua's form of concatenation result in a single
constant (in fact, I was under the mistaken impression that it already
did so!), though there is this thread
(http://lua-users.org/lists/lua-l/2007-02/msg00209.html) to consider.
But I dislike the omitted parentheses in function calls. It seems like
an unnecessary extension of Lua's beautiful tiny grammar, an exception
that brings minor advantage but carries with it hidden disadvantages.
Among these are a deterrent to other language modifications and the
less-than-obvious-without-the-BNF 'f "A" .. "B"' is 'f("A") .. "B"'.
I have a vague memory of another post where 'f "A"' would be broken by a
proposed modification to the language. I looked for it in the archives
but could not find it. But there was a post just this month about
extending this syntactical form to numbers
(http://lua-users.org/lists/lua-l/2008-01/msg00303.html). It's natural
to ask 'Why this type and not another?' These instances make me think
that there's cause for re-evaluation of the trade-offs for this feature.
Is there a reason for 'f "A"' (and 'f{}') other than saving keystrokes?
Does that reasoning apply to other Lua types?
I know from Lua's early history and from my own early Lua programming
that 'f{}' can be useful, especially in configuration files. But over
the years I shed my "Wow! This is neat!" view and replaced it with one
that is 'purer'. Now I nearly always use 'f({})' and 'f("A")'; I see the
parentheses as a clearer, more consistent indication of what is actually
happening - a function call.
My future vision of Lua sees these forms in the same way that I view the
old 'n' field for arrays ('#' is more elegant). I suppose the forms will
stay until there is another more compelling form that is syntactically
mutually exclusive. The key thing being 'more compelling', which I don't
believe is true for this particular patch.
Doug
--
Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220