You could eval the datalog macro to do it at runtime.

I could also expose the underlying protocol that ! and ? use, which IS
based on runtime symbols. That would be more like exposing a database
engine API than a Datalog API though.

Jay

On Fri, Aug 16, 2013 at 11:04 AM, Mikko Tiihonen
<[email protected]> wrote:
> Thank you for the clarification!
>
> Do I understand right that since the tables do not have any binding, there is 
> no way to parameterize them in runtime? The macro approach works if the table 
> is known in compile-time, but I am at loss to think of a way of providing the 
> table to the query in a variable that gets its value during runtime.
>
> Actually, since I'm doing just some preliminary exploration, this was a 
> valuable and timely piece of advice and I will return to the drawing board 
> and take this into consideration.
>
> Have a nice weekend!
>
> Best,
>
> Mikko T.
>
> Jay McCarthy kirjoitti 16.8.2013 kello 19:36:
>
>> 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
>> <[email protected]> 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 <[email protected]>
>> Assistant Professor / Brigham Young University
>> http://faculty.cs.byu.edu/~jay
>>
>> "The glory of God is Intelligence" - D&C 93
>



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

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

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to