[racket] Parameterizing tables in Datalog queries
I just pushed some improvements here.
https://github.com/plt/racket/commit/744fde1fa85aa52cd9a969d9deffa726ca94af37
Jay
On Sat, Dec 21, 2013 at 12:58 AM, Evan Donahue <emdonahu at gmail.com> wrote:
> That would be a welcome change for me as well. It would be nice to be able
> to interact with the theory more readily from an embedding, interactive
> application.
>
> Thanks,
> Evan
>
>
> On Fri, Aug 16, 2013 at 11:29 AM, Jay McCarthy <jay.mccarthy at gmail.com>
> wrote:
>>
>> 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
>> <mikko.tiihonen at tmtiihonen.fi> 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
>> >> <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
>> >
>>
>>
>>
>> --
>> 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
>>
>> ____________________
>> 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