Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > epiphany

Reply
Thread Tools

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
 
Reply With Quote
 
 
 
 
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
2010 Epiphany Photo mmyvusenet Digital Photography 5 01-12-2010 04:06 PM
An epiphany Gary G. Taylor Computer Support 2 11-26-2004 12:17 AM



Advertisments