[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: default values of 'false' in data description
- From: Sam Roberts <sroberts@...>
- Date: Fri, 15 Sep 2006 08:32:35 -0700
On Thu, Sep 14, 2006 at 05:20:03PM -0300, Roberto Ierusalimschy wrote:
> "Most things" is quite different from "everything". If you count, probably
> most things are already expressions in Lua ;)
> (+, -, *, /, .., and, or, not, function calls, constructors, etc.)
> I will try to answer the "everything" part.
>
> - Several statements have no natural meaning as expressions. Among them,
> return, break, while, and repeat. Actually, I guess that only "if" and
> assignment (with all complexities of multiple assignment) have a natural
> meaning.
Return and break I see your point. But (do, while, repeat, if, for)
could all evaluate to the value of their last expression or the argument
to a break.
local verbosity
if opts[1] == "-q" then
verbosity = 1
else
verbosity = 2
end
could be simply
local verbosity = if opts[1] == "-q" then 1 else 2 end
or
t = { "helo", "sam", "bye" }
...
i_of_sam = for i,v in ipairs(t) do
if v == "sam"
break(i)
end
end
-- => i_of_sam is 2
or
value = do local l0, l1; ... code ...; lastexpression; end
I guess this is currently possible with an idiom like:
v0 = (function () ... code ...; return something; end)()
which makes me wonder if changing
v0 = ... code ...
into the former is what the token filter patch is for.
I can live without this, of course, my expectations have not fully
adapted to lua yet (from my little lisp and lots of ruby), but if
- it doesn't invalidate currently valid syntax (just makes things
that used to be illegal becomel legal)
- doesn't bloat the implementation, compiler, etc.
maybe it is worth considering?
Sam
Its interesting the decisions designers make. In ruby, the control
structures are expressions, but not method definitions (though maybe in
upcoming releases, its oft requested). In lua, its the exact opposite!
And in lisp, its all expressions...
Lisp seems to be a primeval hunting ground for language features, but
different languages are bringing different parts back to the table!