Skip to content

Commit 125849f

Browse files
committed
improving handling of non compilable functions
1 parent 7ee446e commit 125849f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

mathics/builtin/functional.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from mathics.core.expression import Expression
1212

1313

14+
1415
class Function(PostfixOperator):
1516
"""
1617
<dl>
@@ -81,13 +82,22 @@ def apply_named(self, vars, body, args, evaluation):
8182
else:
8283
vars = [vars]
8384

85+
86+
# print([v.get_head_name()=="System`Pattern" or v.is_symbol() for v in vars])
8487
args = args.get_sequence()
8588
if len(vars) > len(args):
8689
evaluation.message('Function', 'fpct', )
8790
else:
88-
vars = dict(list(zip((
89-
var.get_name() for var in vars), args[:len(vars)])))
90-
return body.replace_vars(vars)
91+
# Allows to use both symbols or Blank patterns (z_Complex) to state the symbol.
92+
# this is not included in WL, and here does not have any impact, but it is needed for
93+
# 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)])))
97+
try:
98+
return body.replace_vars(vars)
99+
except:
100+
return
91101

92102
# Not sure if DRY is possible here...
93103
def apply_named_attr(self, vars, body, attr, args, evaluation):
@@ -103,7 +113,10 @@ def apply_named_attr(self, vars, body, attr, args, evaluation):
103113
else:
104114
vars = dict(list(zip((
105115
var.get_name() for var in vars), args[:len(vars)])))
106-
return body.replace_vars(vars)
116+
try:
117+
return body.replace_vars(vars)
118+
except:
119+
return
107120

108121

109122
class Slot(Builtin):

0 commit comments

Comments
 (0)