grouped creation of atoms

59 views
Skip to first unread message

jcdouet

unread,
Oct 3, 2015, 4:16:28 PM10/3/15
to pyDatalog
I have noticed that while working with pydatalog.create_terms, a tedious task of single-letter variable creations ('X,Y,Z,P...') was needed to be able to then write a query either on a logical function "func[]" or on a "set()".
It reminded me of "Sympy", which copes with the same kind of issues :

    Sympy : http://www.sympy.org
    core symbol management : http://docs.sympy.org/latest/modules/core.html#module-sympy.core.symbol

Perhaps a helper function would be very useful in pyDatalog, as "from pyDatalog import symbols" et voila ! Here are the variables X,Y,Z and others...

Moreover, the sympy guys have a dreadful function, "lambdify".
http://docs.sympy.org/dev/modules/utilities/lambdify.html

A string is supplied in the sympy objects' machinery, it is converted into a formula, for instance it is derived from "X", then the result is collected to be converted into a Pythonic lambda.
I had the idea that such a functionality could be implemented into pyDatalog, convert a rules & facts defined function into a pythonic lambda.

In so far as the "lambda" is not lexically closed (which is often a problem for devs), and that on the pyDatalog side the knowledge base is in a registry (if I have undersstood correctly), both concepts could match entirely on a memory management point of view ...?

Pierre Carbonnelle

unread,
Oct 13, 2015, 11:57:24 AM10/13/15
to pyDatalog
Indeed, term creation can be cumbersome. However, it can be avoided by the use of functions prefixed with the @pyDatalog.program() decorator. This is used in examples\python.py within a class definition, but it can be applied to standalone functions too. Maybe we could promote this more in documentation and examples.

Eventually, a program should be able to import a module written in pyDatalog, in the same way that it can import a module written in Lisp using Hy (see pypi). IN that case, term declaration would be made implicit. Something to add to the TODO list...

Pierre Carbonnelle

unread,
Oct 15, 2015, 3:40:47 PM10/15/15
to pyDatalog
Hi,

I have now updated a few sample programs to use the @pyDatalog.program() decorator. I hope you'll like it.

hashtag example: https://github.com/pcarbonn/pyDatalog/blob/master/pyDatalog/examples/hashtag.py

Best regards,
Pierre C.

Reply all
Reply to author
Forward
0 new messages