Velocity Reviews > epiphany

# epiphany

Roy Smith
Guest
Posts: n/a

 04-25-2013
In article <51792710\$0\$29977\$c3e8da3\$(E-Mail Removed) om>,
Steven D'Aprano <(E-Mail Removed)> wrote:

> > It also says, "Its truth value is true". Why would they document that
> > fact if you weren't supposed to use it as a boolean operand?

>
> You can use *anything* in Python in a boolean context. That's a language
> feature: all objects are either truthy or falsey. As for why it is
> documented for NotImplemented, I guess that's because some people might
> guess that it is falsey, like None.

That was part of what added the epiphanality to the experience. My
first guess was exactly as you say, that bool(NotImplemented) would be
false. Once I discovered that it was true, the rest immediately fell
into place and many lines of code got replaced by the simple:

return all(r(...) for r in rules)
^
|
+---- stuff that I'm not showing goes here

88888 Dihedral
Guest
Posts: n/a

 04-28-2013
Roy Smith於 2013年4月25日星期四UTC+8上午7時50分33秒 寫道：
> I discovered something really neat today.
>
>
>
> We've got a system with a bunch of rules. Each rule is a method which
>
> returns True or False. At some point, we need to know if all the rules
>
> are True. Complicating things, not all the rules are implemented.
>
> Those that are not implemented raise NotImplementedError.
>
>
>
> We used to have some ugly logic which kept track of which rules were
>
> active and only evaluated those.
>
>
>
> So, here's the neat thing. It turns out that bool(NotImplemented)
>
> returns True. By changing the unimplemented rules from raising
>
> NotImplementedError to returning NotImplemented, the whole thing becomes:
>
>
>
> return all(r() for r in rules)

Problems of rules in Boolean algebra or the bi-level logic
inference engine in AI were all solved long time ago
in the text book about AI.

There are some variations about the multi-level or
the continuous level logic engine with some new phases
in Fuzzy theory in the expert system.

A dynamical typed language is better to be used in this kind of
problems.