Skip to content

Commit ff52d8f

Browse files
committed
adding comment about lambdify compilation side-effects
1 parent 1830fbd commit ff52d8f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mathics/core/convert/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def expression_to_callable_and_args(
134134
vars: Optional[list] = None,
135135
evaluation: Optional[Evaluation] = None,
136136
debug: int = 0,
137-
vectorize=False,
137+
vectorize: bool = False, # By now, just vectorize in drawing plots.
138138
) -> Tuple[Callable, Optional[list]]:
139139
"""
140140
Return a tuple of Python callable and a list of CompileArgs.

mathics/core/convert/lambdify.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ def lambdify_compile(evaluation, expr, names, debug=0):
5353
# Evaluate the expr first in case it hasn't been already,
5454
# because some functions are not themselves sympy-enabled
5555
# if they always get rewritten to one that is.
56+
# Comment MM:
57+
#
58+
# Suppose we define `F[x_,y_]:=(a=x; Do[a=a+1,{y}];a)`
59+
# which essentially is a convoluted way to say x+y.
60+
#
61+
# Now, what is expected from this function is to produce
62+
# lambda function which implements the loop, and when
63+
# evaluated on `(1,2)` produce `3`. However, with this implementation,
64+
# what we obtain is a function that returns its first input:
65+
# since the evaluation of the loop fails, `a` takes the value `x`,
66+
# and `new_expression` results in `x`.
67+
#
68+
# Also, a side affect is produced, since after compiling the function,
69+
# `a` now takes the value `x`.
70+
#
71+
# For this reason, I guess here we need an special way of evaluating
72+
# expressions, which avoid rules like the one associated to `Do`
73+
# or `*Set*`.
74+
#
5675
try:
5776
new_expr = expr.evaluate(evaluation)
5877
if new_expr:

0 commit comments

Comments
 (0)