@@ -990,16 +990,22 @@ def to_python(self, *args, **kwargs):
990990 Null -> None
991991 Symbol -> '...'
992992 String -> '"..."'
993+ Function -> python function
993994 numbers -> Python number
994995 If kwarg n_evaluation is given, apply N first to the expression.
995996 """
996997 from mathics .builtin .base import mathics_to_python
997-
998998 n_evaluation = kwargs .get ('n_evaluation' )
999+ head_name = self ._head .get_name ()
9991000 if n_evaluation is not None :
1001+ if head_name == 'System`Function' :
1002+ compiled = Expression ("System`Compile" , * (self ._leaves ))
1003+ compiled = compiled .evaluate (n_evaluation )
1004+ if compiled .get_head_name () == "System`CompiledFunction" :
1005+ return compiled .leaves [2 ].cfunc
10001006 value = Expression ('N' , self ).evaluate (n_evaluation )
10011007 return value .to_python ()
1002- head_name = self . _head . get_name ()
1008+
10031009 if head_name == 'System`DirectedInfinity' and len (self ._leaves ) == 1 :
10041010 direction = self ._leaves [0 ].get_int_value ()
10051011 if direction == 1 :
@@ -1008,6 +1014,7 @@ def to_python(self, *args, **kwargs):
10081014 return - math .inf
10091015 elif head_name == 'System`List' :
10101016 return [leaf .to_python (* args , ** kwargs ) for leaf in self ._leaves ]
1017+
10111018 if head_name in mathics_to_python :
10121019 py_obj = mathics_to_python [head_name ]
10131020 # Start here
0 commit comments