473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1707

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dayzman | last post by:
Hi, M'm writing a program to output the results of transforming logical predicates using deMorgan's. Does anyone know of a library that handles logical predicates? Cheers, Michael
0
by: Michael Andersson | last post by:
Given a set of classes class A { enum [ ID = 0x0001} }; class B { enum [ ID = 0x0002} }; class B { enum [ ID = 0x0004} }; I wish to generate a composite class, perhaps using something like...
0
by: AshifToday | last post by:
this was my and my frineds little project in earlier classes, the program seperates the composite and prime numbers in two sections of the screen ===================== /* This program has...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
1
by: Thong Nguyen | last post by:
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 =...
4
by: Ismail Rajput | last post by:
Is there any option we can use Composite DataKeyField in the DataList and DataGrid?
14
by: dave.dolan | last post by:
Basically I'd like to implement the composite design pattern with leaves that are either of reference or value types, but even using generics I can't seem to avoid boxing (using ArrayList or...
0
by: raylopez99 | last post by:
Inspired by Jon, I did a demo prorgram showing three ways to declare predicates, in for example the "FindIndex" and "FindLastIndex" methods of Lists, but in general you can do this for any...
4
by: Arun Srinivasan | last post by:
Hi I was using a query previously, that was efficient select * from table where pred1 and pred2 and pred3; Later I was asked to introduce new ones, but they were not based on table columns but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.