Pierre Carbonnelle  committed 53cc72d

add support for format_ in in-line queries

  • Participants
  • Parent commits c840ef3

Comments (0)

Files changed (2)

File pyDatalog/examples/

 from pyDatalog import pyDatalog
-pyDatalog.create_atoms('parent,bill,ancestor,descendents,manager, X,Y,Z,N,N1,F,  factorial,odd,even, _split')
+pyDatalog.create_atoms('parent,bill,ancestor,descendents,manager, X,Y,Z,N,N1,F,  factorial, first_remainder, odd,even, _split')
 + parent(bill,'John Adams')
 print(factorial[3]==F) # prints [(6,)]
+# (nested) list
+first_remainder(X, Y, Z) <= (Y==X[0]) & (Z==X[1:])
+print(first_remainder((1,2), Y, Z)) # Y is 1, Z is (2,)
+print((Y==5) & (X==format_('Y is {}', Y))) # X is 'Y is 5'
 # aggregate function
 # calculate the list of descendents, sorted by their name, and separated by ','
 (descendents[X]==concat_(Y, order_by=Y, sep=',')) <= ancestor(X,Y) 

File pyDatalog/

         args = [arg.strip() for argl in args for arg in argl]
         for arg in set(args + ['_sum','sum_','_min','min_','_max','max_',
-        'range_','tuple_']):
+        'range_','tuple_', 'format_']):
             if arg in locals_: 
                 if not isinstance(locals_[arg], (pyParser.Symbol, pyParser.Variable)):
                     raise util.DatalogError("Name conflict.  Can't redefine %s as atom" % arg, None, None)