Creating Predicates

Hey all,

I'm not quite sure if this is the right forum - it's a fairly advanced question, and I'm also not exactly a beginner. Still, I figure here's a decent place to start.

I'd like to be able to create boolean predicates. Not a boolean type, nor a function that returns a boolean - I just want to be able to create a predicate, which can be tested later.

For example, I want to be able to create a predicate (x == y), define x and y upon its creation WITHOUT actually testing to see if x==y, store it in a structure, and then test it when it's called upon. If possible, I'd like to avoid creating a class to encapsulate it, but if there's no other way then I'll do it. Thanks in advance, let me know if you need additional clarification.
Can you give an example of how you would use such a thing?
I'd use it to test objects in an environment (i.e. check to see if x == y, where x and y are two variables in the environment). However, I'd like the actual predicate that tests x == y to be generated by the code (so it creates x, creates y, and then creates some sort of boolean predicate equal to (x == y). Then I'd like to store the predicate for testing later by some other function.

The (extremely!) pseudo-code would look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13

bool p [5];

function makepredicate (x, y) {
  return (x==y)
}

function testpredicate(p) {
  return (test p)
  }

p[0] = makepredicate(x,y)
testpredicate(p[0])



Note that under makepredicate, I don't want to actually return the value of (x==y) - I want to return the actual predicate (x==y). Does this help any? I know this can be done in lisp-family languages, I just want to know if you can do it in C++
Last edited on
Topic archived. No new replies allowed.