Pierre Carbonnelle avatar Pierre Carbonnelle committed 53cc72d

add support for format_ in in-line queries

Comments (0)

Files changed (2)

pyDatalog/examples/tutorial.py

 """
 
 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) 

pyDatalog/pyDatalog.py

         args = [arg.strip() for argl in args for arg in argl]
         for arg in set(args + ['_sum','sum_','_min','min_','_max','max_',
         '_len','len_','concat','concat_','rank','rank_','running_sum','running_sum_',
-        '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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.