lua-users home
lua-l archive

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


OK, I'm trying to come to terms with false. I've started going through my
code looking for places where I assign the result of a boolean expression
to a table expecting nil to delete the key (since false will no longer do
that). Maybe I'm the only person with this problem.

I've realised that I will need a lot more if statements and local variables
than I used to have. It would be really nice if the syntax of "if" were
extended to include

if local-variable-list = expression-list then ...

The scope of the local variables would be from the "then" to the matching
"end", and the test would be on the truth value of the first variable in
the list. The one problem with this syntax is that it would mask syntax
errors resulting from the use of = instead of ==, but I think I could live
with that.

I was going to ask for the same thing with while, but I realised that
scoping rules would make this less useful than it at first appeared.
However, a combination of an if and a repeat until would generally do the
trick.

Rici.

ej:

if t = function_which_might_return_false(x) then
     a[x] = t
  else
     a[x] = nil
end

replaces the casual
   t = function_with_might_return_nil(x)

and:

if k, v = setFirst(set, nil) then repeat
  -- do something with k and v
  k, v = setNext(set, k)
  until not k
end

is more or less equivalent to the c "for" statement with local variables. I
know that these are slightly contrived examples, but I hope they give the
flavour of what I'm looking for.

"for" cannot be extended in this fashion, as far as I can see, because it
would be hard to parse, and I'm hesitant to suggest new statement keywords
like:

with vlist=elist while condition
   then
     -- advance chunk
   do
    -- action chunk
   finally
   -- exception chunk
end

because it's probably a bit much for Lua and it involves the introduction
of too many new reserved words.

It's a minor cosmetic; I could write:

do local v1, v2 = e1, e2
     if v1 then
        -- do something
       else
        -- do something else
     end
end

It just makes the code a little shorter, and therefore a little easier to
read.

Thanks.


Oxfam works with others to find lasting solutions to poverty and suffering.

Oxfam GB is a member of Oxfam International, a company limited by guarantee and registered in England No. 612172.
Registered office: 274 Banbury Road, Oxford OX2 7DZ.
Registered charity No. 202918.

Visit the web site at http://www.oxfam.org.uk