[racket] Parameterizing tables in Datalog queries

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Aug 16 12:36:16 EDT 2013

The table position is not an expression position because tables are
not values and do not have any binding. In particular, they are not
symbols as you assume in your example.

I could imagine trying to supporting something like your example, but
it would be backwards incompatible and unlike any other Datalog system
as far as I can tell. Do you have any opinions about this?

You can do something similar with a simple macro:

(define-syntax-rule (param-query table)
  (datalog family
           (? (table 'joseph2 X))))

(param-query parent)

On Fri, Aug 16, 2013 at 5:08 AM, Mikko Tiihonen
<mikko.tiihonen at tmtiihonen.fi> wrote:
> Hi!
>
> I've been trying to parameterize Datalog queries and have stumbled into a problem with the tables in queries. As an example (from Datalog documentation):
>
> #lang racket
> (require datalog)
> (define family (make-theory))
> (datalog family
>          (! (parent joseph2 joseph1))
>          (! (parent joseph2 lucy))
>          (! (parent joseph3 joseph2)))
>
> -now if I run the query as shown in the documentation
>
>         (let ([x 'joseph2])
>           (datalog family
>               (? (parent x X))))
>
> the answer is as expected:
>
>         '(#hasheq((X . joseph1)) #hasheq((X . lucy)))
>
> However, if I parameterize the table:
>
>         (let ([x 'parent])
>           (datalog family
>               (? (x 'joseph2 X))))
>
> the query fails:
>
>         '()
>
> Are there any workarounds for this? I am grateful for any suggestions...
>
> Best regards,
>
> Mikko Tiihonen
>
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.