[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sunday afternoon whishlist
- From: spir ☣ <denis.spir@...>
- Date: Sun, 9 May 2010 19:19:28 +0200
On Sun, 9 May 2010 17:36:02 +0200
Klaus Ripke <paul-lua@malete.org> wrote:
> Could indexing anything but a table, or at least indexing nil,
> return nil instead of throwing an error?
> I don't see why x.z conveniently gives nil, if there is no z in x,
> but x.y.z requires an extra check for x.y .
> This makes working with structures with lots of optional parts pretty
> tedious - and if it's external input, basically everything is optional.
>
> Really I'd love to see nil behave like an empty value of
> the expected type most of the time, Perl style.
I find this both useful and consistent with the rest if nil's semantics, esp. that a function returns nil by default.
But: I would prefere a kind of UNDEF pseudo-value (that cannot be assigned to a var), distinct from nil, and on which the only possible operation is a boolean test (if x then ...).
UNDEF thus only has _Lua_ semantics of "undefined thingie", on which any operation (else checking for existence) raises an error, including assignment (y=x when x is undefined). Such a pseudo-value may replace nil as language-generated placeholder for missing return values, parameters, etc... It would have a logical value of false, thus its possible use in tests.
While nil is free for _application_ semantics, such as "yet unavailable data".
For me, the confusion of language and application semantics in nil makes its various use unclear.
Denis
________________________________
vit esse estrany ☣
spir.wikidot.com