JESS: [EXTERNAL] Using tests in query variables

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JESS: [EXTERNAL] Using tests in query variables

Sam Sarjant
Hello.
  Is it possible to use tests as variables submitted to queries? Or do variables always have to be concrete facts (or already bound facts)?

For example, given the facts (num 0) (num 1) (num 2)..., is it possible to perform a query that looks something like (run-query* numQuery ?X&:(<= 0 ?X 5)) which will return all nums between 0 and 5 (inclusive).

I gave the above example a go (with the proper definitions and such), but it threw an exception at me, telling me 'No such variable X'. This is mostly a question out of curiosity, as I don't absolutely need queries to accept test variables, but it would be nice if there was some sort of functionality to perform this task.

--
- Thanks, Sam Sarjant
Reply | Threaded
Open this post in threaded view
|

Re: JESS: [EXTERNAL] Using tests in query variables

Wolfgang Laun-2
Within a (defquery) you use (declare (variables ...)) to specify query parameters, and the (run-query*) function lets you provide values for them.

Usually the condition would have to be part of the query pattern, with only the value being provided by the run-query* parameter.

-W

On 23 November 2011 00:34, Sam Sarjant <[hidden email]> wrote:
Hello.
  Is it possible to use tests as variables submitted to queries? Or do variables always have to be concrete facts (or already bound facts)?

For example, given the facts (num 0) (num 1) (num 2)..., is it possible to perform a query that looks something like (run-query* numQuery ?X&:(<= 0 ?X 5)) which will return all nums between 0 and 5 (inclusive).

I gave the above example a go (with the proper definitions and such), but it threw an exception at me, telling me 'No such variable X'. This is mostly a question out of curiosity, as I don't absolutely need queries to accept test variables, but it would be nice if there was some sort of functionality to perform this task.

--
- Thanks, Sam Sarjant