lua-users home
lua-l archive

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

Asko Kauppi a écrit :
"Guido van Rossum eventually chose a surprising syntax:

x = true_value if condition else false_value"

I am _NOT_ suggesting Lua to do the same. But bringing this up, since it does seem relevant. And weird. ;)

Yes, it reminds me a bit of the dreaded Perl...
open LOG, "<$log" or die "Cannot open $log: $!";
print "$msg\n" unless $quiet;

The explanation:
"In many cases where a conditional expression is used, one value seems to be the 'common case' and one value is an 'exceptional case', used only on rarer occasions when the condition isn't met."

Mmm... The examples show:
contents = ((doc + '\n') if doc else '')
level = (1 if logging else 0)

I feel that this syntax isn't very useful when standing on a single line, writing:
if doc then contents = (doc + '\n') else content = '' end
is still usable/readable.

It is more useful in table, indeed, but perhaps we could ask to be able to write:

content = (if doc then return (doc + '\n') else return '' end)

or something similar, unless there is some semantical blocking.

Philippe Lhoste
--  (near) Paris -- France
--  --  --  --  --  --  --  --  --  --  --  --  --  --