[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUA4.0 : Bug with maths
- From: Roberto Ierusalimschy <rieru@...>
- Date: Tue, 12 Feb 2002 12:12:12 -0600 (CST)
On Tue, 12 Feb 2002 RLake@oxfam.org.uk wrote:
> Fair enough. But "pseudo-predicates" can be quite useful. By
> pseudo-predicate I mean a function which returns either a false value or a
> useful true value. A good example of a pseudo-predicate is strfind.
A pseudo-predicate is not a predicate. I agree that pseudo-predicates
should return nil when there is no useful value to return. (After all,
that is the meaning of nil.
> Pseudo-predicates are extremely useful, both for clarity and for
> efficiency. "Logically" a pseudo-predicate returns nil (the absence of a
> value) if it can't find anything better to return, but that clouds the
> issue for consumers of the functions (my point above, slightly elaborated.)
I don't see your point. A consumer *must* know whether a function is
a predicate or a pseudo-predicate; after all, this is the return type of
the function (boolean x numbers/strings/whatever). If he doesn't know
whether the function returns booleans (possibly false) or numbers (possibly
nil), he shouln't even call it ;-)
But even if the programmer is crazy enough to use the return of a
function without knowing what it is, he can still play safe:
T[x] = (P(x) and Q(x)) or false
or
T[x] = (P(x) and Q(x)) or nil
-- Roberto