lua-users home
lua-l archive

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


- SUGGESTIONS -

(1) "#!" in FILE vs CHUNK
It is stated that, to allow Lua to be conveniently used for shell scripts,
Lua ignores the first line of a CHUNK if it starts with "#".

(a) It seems more appropriate to me that it should ignore the first line of
a FILE only, not a chunk (Ie, the processing is a part of "dofile /
loadfile" rather than chunk execution), since only files relate to script
execution.

(b) Scripts actually start with "#!" not "#", so perhaps that should be used
instead. That would retain the symbol "#" for general use, allowing the
option of it being used in later editions of Lua if desired (though not, of
course,  in the sequence of "#" then "!").


(2) (EXP) TRUNCATION
I find the current "(function call)" truncation to a single value to be
rather non-intuitive. While not syntactically ambiguous, to the casual user
it seems odd that the "(,,)" in a function call "f  (a,b,c)" doesn't
truncate while an expression usage such as "f((a,b,c))" does.

Perhaps it would be clearer just to define a standard library function
"one()":
    function one(a) return a end

so that one would simply say "a,b,c = x(), y(), one(z())"


(3) "," AS A BINARY FUNCTION
As a syntax note, rather than "(x,y,z)" being some special operation, I'd
prefer "," to simply be treated as a binary function just like "+ - * / <=
etc". In this mode:

(a) It takes N left and M right arguments, and returns 1+M return values, so
    f() , g()
is the same as
    one(f()) , g()

(b) It has a lower precedence that "+", so:
    a,b = 1+2 , 3+4
behaves as the expected:
    a,b = (1+2) , (3+4)

(c) It is right associative, so:
    f(), g(), h(), i()
is equivalent to
    f() , (g(), (h() , i()) )
This means, in essence, that "," takes an arbitrary number of return values
from the right-most function and repetitvely prepends single values to the
front of that return value list from each preceeding function in turn.


(4) GLOBAL [exp]=exp
Consider:
    t = {x=123, ["y"]=456}

Normal global variables are basically an assignment to a global table, eg:
    x = 123
It would be consistent, then, to allow:
    ["y"] = 456

Would that cause any syntax problems? I don't know... I haven't checked yet.
But computationally it makes sense! :-)


(5) AND/OR MULTI-RETURN
"and" and "or" should probably return multiple arguments (since they are in
essence being used to replace the "bool ? exp1 : exp2" functionality of C.

Ie, since I can say:
  if t[i] then
    return i,t[i]
  else
    return nil
  end

then it makes sense to be able to say:
  return t[i] and (i,t[i]) or nil

Of course the current "(exp)" truncation to a single return value kibitzes
that. But then that syntax is already rather shaky and I'd like to see it go
:-).

Alternately, Lua should have a true "a ? b : c" operation.


(6) Want INEXT

Rather than
    for i,v in pair(t) do ... end

I prefer the more explicit form:
    for i,v in next,t do ... end

Likewise for:
    for i,v in ipair(t) do ... end

I'd prefer to say:
    for i,v in inext,t do ... end

However "inext()" doesn't exist.

I could write it of course:
    function inext(t,i)
        i = i and i+1 or 1
        if t[i] then return i,t[i] else return nil end
    end

But it seems to me that "inext()", being as far as I can tell more
fundamental than "ipair()", is more deserving of a place in the basic
library.


(7) VERSION

Should version be only returned as a string? It would seem more appropriate
(and easier to manipulate) to have a version function such as:
    name, major, minor, bugfix = version()

Or perhaps:
    name, major_dot_minor, bugfix = version()


*cheers*
Peter Hill.