[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: elseifs and the fact that assignmens are not expressions
- From: Sam Roberts <sroberts@...>
- Date: Wed, 24 Jan 2007 11:27:01 -0800
On Wed, Jan 24, 2007 at 09:17:35AM +0100, Flemming Madsen wrote:
I have the impression that there is some resistance to making ALL
statements into expressions on the part of the lua team. I thing it has
to do with the simplicity of the parser, or some ambiguity in the
syntax.
I'd be interested in knowing what exactly the resistance is, because I
too would like write code as you present it below! It seems simple,
consitent, predictable, comfortable to use. Btw, "&&" is not an operator
in lua, you have to use the english word.
Why is a statement/expression duality necessary in lua? What are some
examples of where it would introduce confusion?
Sam
> local s,e,c,r,line,file,modified,pid,running
> local fd = io.popen("sh -c 'vi -r 2>&1'", "r")
>
> while (line = fd:read("*line")) do
> ^^^^^^
> if s,e,c = string.find(line, "^ *file name: ([%w%p]*)") then
> ^^^^^^^^
> file = c
> elseif s,e,c = string.find(line, "^ *modified: (%a*)") then
> ^^^^^^^^
> modified = c ~= "no"
> elseif s,e,c,r = string.find(line, "^ *process ID: (%d*)(.*)") then
> ^^^^^^^^^
> pid = c
> running = string.find(r, "(still running)", 1, true) ~= nil
>
> if file && modified then
> io.write(string.format("%d %8d%s %s", modified and 1 or 0,
> pid, running and "*" or " ", file)
> end
> file = nil
> running = nil
> end
> end
> fd:close()
>
>
> Obviously this will not work, since assignments are not expressions in lua,
> nor is there any way of embedding assignment in expressions
>
> Is there an easy way around this that i missed. Is this even a candidate
> for the FAQ
>
>
> Best /Flemming*
> *