Skip to content

Commit c489245

Browse files
committed
handle RuleDelayed in Map over Association expressions. Adding a comment
1 parent e2570e7 commit c489245

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

mathics/builtin/functional/apply_fns_to_lists.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,22 @@ def callback(level):
179179
Map $f$ onto each element (denoted by 'level' here) at this level.
180180
With exception for expr as Association, which is mapped on values only.
181181
"""
182-
if is_association and level.has_form("Rule", 2):
182+
# TODO: This special behavior applies when the whole expression
183+
# is of the form Association[__(Rule|RuleDelayed)], i.e., when
184+
# the expression is a well-formatted Association expression.
185+
# For example,
186+
# `Map[F, Association[a->1,b->2, NotARule]`
187+
# produces in WMA
188+
# `Association[F[a->1], F[b->2], F[NotARule]`
189+
# instead of
190+
# `Association[a->F[1], b->F[2], F[NotARule]`]
191+
#
192+
# Fixing this would require a different implementation of this eval_ method.
193+
#
194+
195+
if is_association and level.has_form(("Rule", "RuleDeyaled"), 2):
183196
return Expression(
184-
SymbolRule,
197+
level.get_head(),
185198
level.elements[0],
186199
Expression(f, level.elements[1]),
187200
)

0 commit comments

Comments
 (0)