@@ -56,61 +56,68 @@ class Function(PostfixOperator):
5656 = 3
5757 """
5858
59- operator = '&'
59+ operator = "&"
6060 precedence = 90
61- attributes = (' HoldAll' ,)
61+ attributes = (" HoldAll" ,)
6262
6363 messages = {
64- ' slot' : "`1` should contain a positive integer." ,
65- ' slotn' : "Slot number `1` cannot be filled." ,
66- ' fpct' : "Too many parameters to be filled." ,
67- ' iassoc' : "Invalid association item `1`"
64+ " slot" : "`1` should contain a positive integer." ,
65+ " slotn" : "Slot number `1` cannot be filled." ,
66+ " fpct" : "Too many parameters to be filled." ,
67+ " iassoc" : "Invalid association item `1`" ,
6868 }
6969
7070 def apply_slots (self , body , args , evaluation ):
71- ' Function[body_][args___]'
71+ " Function[body_][args___]"
7272
73- args = list (chain ([Expression (' Function' , body )], args .get_sequence ()))
73+ args = list (chain ([Expression (" Function" , body )], args .get_sequence ()))
7474 return body .replace_slots (args , evaluation )
7575
7676 def apply_named (self , vars , body , args , evaluation ):
77- ' Function[vars_, body_][args___]'
77+ " Function[vars_, body_][args___]"
7878
79- if vars .has_form (' List' , None ):
79+ if vars .has_form (" List" , None ):
8080 vars = vars .leaves
8181 else :
8282 vars = [vars ]
8383
84+ # print([v.get_head_name()=="System`Pattern" or v.is_symbol() for v in vars])
8485 args = args .get_sequence ()
8586 if len (vars ) > len (args ):
86- evaluation .message (' Function' , ' fpct' )
87+ evaluation .message (" Function" , " fpct" )
8788 else :
88- vars = dict (list (zip ((
89- var .get_name () for var in vars ), args [:len (vars )])))
89+ # Allows to use both symbols or Blank patterns (z_Complex) to state the symbol.
90+ # this is not included in WL, and here does not have any impact, but it is needed for
91+ # translating the function to a compiled version.
92+ var_names = (
93+ var .get_name () if var .is_symbol () else var .leaves [0 ].get_name ()
94+ for var in vars
95+ )
96+ vars = dict (list (zip (var_names , args [: len (vars )])))
9097 try :
9198 return body .replace_vars (vars )
9299 except :
93100 return
94101
95102 # Not sure if DRY is possible here...
96103 def apply_named_attr (self , vars , body , attr , args , evaluation ):
97- ' Function[vars_, body_, attr_][args___]'
98- if vars .has_form (' List' , None ):
104+ " Function[vars_, body_, attr_][args___]"
105+ if vars .has_form (" List" , None ):
99106 vars = vars .leaves
100107 else :
101108 vars = [vars ]
102109
103110 args = args .get_sequence ()
104111 if len (vars ) > len (args ):
105- evaluation .message (' Function' , ' fpct' )
112+ evaluation .message (" Function" , " fpct" )
106113 else :
107- vars = dict (list (zip ((
108- var .get_name () for var in vars ), args [:len (vars )])))
114+ vars = dict (list (zip ((var .get_name () for var in vars ), args [: len (vars )])))
109115 try :
110116 return body .replace_vars (vars )
111117 except :
112118 return
113119
120+
114121class Slot (Builtin ):
115122 """
116123 <dl>
@@ -140,13 +147,14 @@ class Slot(Builtin):
140147 = #0
141148 """
142149
143- attributes = (' NHoldAll' ,)
150+ attributes = (" NHoldAll" ,)
144151
145152 rules = {
146- 'Slot[]' : 'Slot[1]' ,
147- 'MakeBoxes[Slot[n_Integer?NonNegative],'
148- ' f:StandardForm|TraditionalForm|InputForm|OutputForm]' : (
149- '"#" <> ToString[n]' ),
153+ "Slot[]" : "Slot[1]" ,
154+ "MakeBoxes[Slot[n_Integer?NonNegative],"
155+ " f:StandardForm|TraditionalForm|InputForm|OutputForm]" : (
156+ '"#" <> ToString[n]'
157+ ),
150158 }
151159
152160
@@ -171,13 +179,12 @@ class SlotSequence(Builtin):
171179 = ##1
172180 """
173181
174- attributes = (' NHoldAll' ,)
182+ attributes = (" NHoldAll" ,)
175183
176184 rules = {
177- 'SlotSequence[]' : 'SlotSequence[1]' ,
178- 'MakeBoxes[SlotSequence[n_Integer?Positive],'
179- 'f:StandardForm|TraditionalForm|InputForm|OutputForm]' : (
180- '"##" <> ToString[n]' ),
185+ "SlotSequence[]" : "SlotSequence[1]" ,
186+ "MakeBoxes[SlotSequence[n_Integer?Positive],"
187+ "f:StandardForm|TraditionalForm|InputForm|OutputForm]" : ('"##" <> ToString[n]' ),
181188 }
182189
183190
@@ -202,14 +209,14 @@ class Composition(Builtin):
202209 = Composition[f, g, h]
203210 """
204211
205- attributes = (' Flat' , ' OneIdentity' )
212+ attributes = (" Flat" , " OneIdentity" )
206213
207214 rules = {
208- ' Composition[]' : ' Identity' ,
215+ " Composition[]" : " Identity" ,
209216 }
210217
211218 def apply (self , functions , args , evaluation ):
212- ' Composition[functions__][args___]'
219+ " Composition[functions__][args___]"
213220
214221 functions = functions .get_sequence ()
215222 args = args .get_sequence ()
@@ -232,5 +239,5 @@ class Identity(Builtin):
232239 """
233240
234241 rules = {
235- ' Identity[x_]' : 'x' ,
242+ " Identity[x_]" : "x" ,
236243 }
0 commit comments