1111from mathics .core .expression import Expression
1212
1313
14-
1514class Function (PostfixOperator ):
1615 """
1716 <dl>
@@ -57,62 +56,62 @@ class Function(PostfixOperator):
5756 = 3
5857 """
5958
60- operator = '&'
59+ operator = "&"
6160 precedence = 90
62- attributes = (' HoldAll' ,)
61+ attributes = (" HoldAll" ,)
6362
6463 messages = {
65- ' slot' : "`1` should contain a positive integer." ,
66- ' slotn' : "Slot number `1` cannot be filled." ,
67- ' fpct' : "Too many parameters to be filled." ,
68- ' 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`" ,
6968 }
7069
7170 def apply_slots (self , body , args , evaluation ):
72- ' Function[body_][args___]'
71+ " Function[body_][args___]"
7372
74- args = list (chain ([Expression (' Function' , body )], args .get_sequence ()))
73+ args = list (chain ([Expression (" Function" , body )], args .get_sequence ()))
7574 return body .replace_slots (args , evaluation )
7675
7776 def apply_named (self , vars , body , args , evaluation ):
78- ' Function[vars_, body_][args___]'
77+ " Function[vars_, body_][args___]"
7978
80- if vars .has_form (' List' , None ):
79+ if vars .has_form (" List" , None ):
8180 vars = vars .leaves
8281 else :
8382 vars = [vars ]
8483
85-
8684 # print([v.get_head_name()=="System`Pattern" or v.is_symbol() for v in vars])
8785 args = args .get_sequence ()
8886 if len (vars ) > len (args ):
89- evaluation .message (' Function' , ' fpct' )
87+ evaluation .message (" Function" , " fpct" )
9088 else :
9189 # Allows to use both symbols or Blank patterns (z_Complex) to state the symbol.
9290 # this is not included in WL, and here does not have any impact, but it is needed for
9391 # translating the function to a compiled version.
94- var_names = (var .get_name () if var .is_symbol ()
95- else var .leaves [0 ].get_name () for var in vars )
96- vars = dict (list (zip (var_names , args [:len (vars )])))
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 )])))
9797 try :
9898 return body .replace_vars (vars )
9999 except :
100100 return
101101
102102 # Not sure if DRY is possible here...
103103 def apply_named_attr (self , vars , body , attr , args , evaluation ):
104- ' Function[vars_, body_, attr_][args___]'
105- if vars .has_form (' List' , None ):
104+ " Function[vars_, body_, attr_][args___]"
105+ if vars .has_form (" List" , None ):
106106 vars = vars .leaves
107107 else :
108108 vars = [vars ]
109109
110110 args = args .get_sequence ()
111111 if len (vars ) > len (args ):
112- evaluation .message (' Function' , ' fpct' )
112+ evaluation .message (" Function" , " fpct" )
113113 else :
114- vars = dict (list (zip ((
115- 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 )])))
116115 try :
117116 return body .replace_vars (vars )
118117 except :
@@ -148,13 +147,14 @@ class Slot(Builtin):
148147 = #0
149148 """
150149
151- attributes = (' NHoldAll' ,)
150+ attributes = (" NHoldAll" ,)
152151
153152 rules = {
154- 'Slot[]' : 'Slot[1]' ,
155- 'MakeBoxes[Slot[n_Integer?NonNegative],'
156- ' f:StandardForm|TraditionalForm|InputForm|OutputForm]' : (
157- '"#" <> ToString[n]' ),
153+ "Slot[]" : "Slot[1]" ,
154+ "MakeBoxes[Slot[n_Integer?NonNegative],"
155+ " f:StandardForm|TraditionalForm|InputForm|OutputForm]" : (
156+ '"#" <> ToString[n]'
157+ ),
158158 }
159159
160160
@@ -179,13 +179,12 @@ class SlotSequence(Builtin):
179179 = ##1
180180 """
181181
182- attributes = (' NHoldAll' ,)
182+ attributes = (" NHoldAll" ,)
183183
184184 rules = {
185- 'SlotSequence[]' : 'SlotSequence[1]' ,
186- 'MakeBoxes[SlotSequence[n_Integer?Positive],'
187- 'f:StandardForm|TraditionalForm|InputForm|OutputForm]' : (
188- '"##" <> ToString[n]' ),
185+ "SlotSequence[]" : "SlotSequence[1]" ,
186+ "MakeBoxes[SlotSequence[n_Integer?Positive],"
187+ "f:StandardForm|TraditionalForm|InputForm|OutputForm]" : ('"##" <> ToString[n]' ),
189188 }
190189
191190
@@ -210,14 +209,14 @@ class Composition(Builtin):
210209 = Composition[f, g, h]
211210 """
212211
213- attributes = (' Flat' , ' OneIdentity' )
212+ attributes = (" Flat" , " OneIdentity" )
214213
215214 rules = {
216- ' Composition[]' : ' Identity' ,
215+ " Composition[]" : " Identity" ,
217216 }
218217
219218 def apply (self , functions , args , evaluation ):
220- ' Composition[functions__][args___]'
219+ " Composition[functions__][args___]"
221220
222221 functions = functions .get_sequence ()
223222 args = args .get_sequence ()
@@ -240,5 +239,5 @@ class Identity(Builtin):
240239 """
241240
242241 rules = {
243- ' Identity[x_]' : 'x' ,
242+ " Identity[x_]" : "x" ,
244243 }
0 commit comments