@@ -132,6 +132,18 @@ def functionalize(node):
132132 out .args .args [0 ].ctx .lineno , out .args .args [0 ].ctx .col_offset = x .lineno , x .col_offset
133133 node .args [i ] = out
134134
135+ for keyword in node .keywords :
136+ if (node .func .id , keyword .arg ) in expectFunction :
137+ x = keyword .value
138+ numargs = highestDollar (x )
139+ if numargs > 0 :
140+ out = ast .Lambda (ast .arguments ([ast .Name ("$args" , ast .Param ())], None , None , []), dollarToArg (x ))
141+ out .lineno , out .col_offset = x .lineno , x .col_offset
142+ out .args .lineno , out .args .col_offset = x .lineno , x .col_offset
143+ out .args .args [0 ].lineno , out .args .args [0 ].col_offset = x .lineno , x .col_offset
144+ out .args .args [0 ].ctx .lineno , out .args .args [0 ].ctx .col_offset = x .lineno , x .col_offset
145+ keyword .value = out
146+
135147 for field in node ._fields :
136148 subnode = getattr (node , field )
137149 if isinstance (subnode , ast .AST ):
@@ -173,9 +185,18 @@ def executeWithDollars(source):
173185 h = executeWithDollars ('''
174186def addEmUp(x, y):
175187 return x + y
176-
177188Bin(10, -5.0, 5.0, addEmUp($1, $2))
178189''' )
179190 h .fill ((1.0 , 2.0 ))
180191 h .fill ((- 2.0 , - 1.0 ))
181192 print (h .toJsonString ())
193+
194+ h = executeWithDollars ("Bin(quantity=$1 + $2, num=10, low=-5.0, high=5.0)" )
195+ h .fill ((1.0 , 2.0 ))
196+ h .fill ((- 2.0 , - 1.0 ))
197+ print (h .toJsonString ())
198+
199+ h = executeWithDollars ("Bin(10, -5.0, 5.0, lambda xs: xs[0] + xs[1])" )
200+ h .fill ((1.0 , 2.0 ))
201+ h .fill ((- 2.0 , - 1.0 ))
202+ print (h .toJsonString ())
0 commit comments