PC Review


Reply
Thread Tools Rate Thread

Composite predicates

 
 
Thong Nguyen
Guest
Posts: n/a
 
      21st Mar 2005
I wrote my own Predicate class for .NET 1.1 which allowed composite
predicates using operator overloading...

for example:

Predicate p1 = {...};
Predicate p2 = {...};

Predicate p1andp2 = ~(p1 ^ p2); // ^ is the AND operator in logic notation

which is requivalent to:

Predicate p1andp2 = delegate(object o) { return !(p1(o) && p2(o)); };

Predicates in .NET/C# 2.0 are delegates, not a class like my implementation
so it's not possible (using C#) to add overloaded operators to the Predicate
delegate. There is no such limitation in the runtime or IL.

What I would like to see is Microsoft add logical compositing operators for
the Predicate delegate in Whidbey. Predicates have a potential to be used
pretty much everywhere where a boolean decision needs to be made (for
flexibility reasons, it can/should replace bool in many areas of the BCL)
and being able to combine many distinct predicates into a single predicate
with an easy to use syntax would be nice....

^Tum


 
Reply With Quote
 
 
 
 
Daniel O'Connell [C# MVP]
Guest
Posts: n/a
 
      21st Mar 2005

"Thong Nguyen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I wrote my own Predicate class for .NET 1.1 which allowed composite
>predicates using operator overloading...
>
> for example:
>
> Predicate p1 = {...};
> Predicate p2 = {...};
>
> Predicate p1andp2 = ~(p1 ^ p2); // ^ is the AND operator in logic notation
>
> which is requivalent to:
>
> Predicate p1andp2 = delegate(object o) { return !(p1(o) && p2(o)); };

<snip>
> What I would like to see is Microsoft add logical compositing operators
> for the Predicate delegate in Whidbey. Predicates have a potential to be
> used pretty much everywhere where a boolean decision needs to be made (for
> flexibility reasons, it can/should replace bool in many areas of the BCL)
> and being able to combine many distinct predicates into a single predicate
> with an easy to use syntax would be nice....


I think you could easily just provide a method to achieve this(using dynamic
methods). While compositing has some interesting concepts, I'm not sure its
really worth *THAT* much as to change the language for one specific case.

Also, even though ^ may be and in logic notation, using it in C# is a
mistake, IMHO. You'll confuse far more people by using an operator the
language already has noted as xor than you will by using one the logic does
not use.

It is an interesting concept, however.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Predicates explained: three ways to declare predicates raylopez99 Microsoft C# .NET 0 11th Sep 2008 12:25 AM
top predicates =?Utf-8?B?Znl0b3M=?= Microsoft Access Queries 3 28th Jun 2006 09:09 AM
predicates =?Utf-8?B?dmFzc2lsaXM=?= Microsoft Access Queries 2 30th Nov 2005 10:07 PM
Composite predicates Thong Nguyen Microsoft Dot NET 1 21st Mar 2005 09:01 PM
Composite control with dynamic composite controls sleigh Microsoft ASP .NET 1 12th Feb 2004 06:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:28 PM.