471,624 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Composite predicates

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
Jul 21 '05 #1
2 1655

"Thong Nguyen" <tu*@veridicus.spamless.com> wrote in message
news:O2**************@TK2MSFTNGP15.phx.gbl...
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.
Jul 21 '05 #2

"Thong Nguyen" <tu*@veridicus.spamless.com> wrote in message
news:O2**************@TK2MSFTNGP15.phx.gbl...
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.
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by dayzman | last post: by
reply views Thread by AshifToday | last post: by
18 posts views Thread by Thomas A. Anderson | last post: by
1 post views Thread by Thong Nguyen | last post: by
4 posts views Thread by Ismail Rajput | last post: by
4 posts views Thread by Arun Srinivasan | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.