Skip to content

$IterationLimit is not limiting evalation expansion #1476

@rocky

Description

@rocky

Description

$IterationLimit is not limiting expression expanion

How to Reproduce

$mathics -c 'Block[{$IterationLimit = 20}, yin := yang; yang := yin; yin]'

Output Given

Traceback (most recent call last):
  File "/tmp/.pyenv/versions/3.13.7/bin/mathics", line 7, in <module>
    sys.exit(main())
             ~~~~^^
  File "/tmp/Mathics3/mathics-core/mathics/__main__.py", line 591, in main
    result, evaluation = run_it()
                         ~~~~~~^^
  File "/tmp/Mathics3/mathics-core/mathics/__main__.py", line 583, in run_it
    return evaluation.parse_evaluate(expr, timeout=settings.TIMEOUT), evaluation
           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 168, in parse_evaluate
    return self.evaluate(expr, timeout)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 271, in evaluate
    result = evaluate()
  File "/tmp/Mathics3/mathics-core/mathics/core/evaluation.py", line 244, in evaluate
    self.last_eval = query.evaluate(self)
                     ~~~~~~~~~~~~~~^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/tracing.py", line 171, in wrapper
    result = func(expr, evaluation)
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 585, in evaluate
    expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/tracing.py", line 171, in wrapper
    result = func(expr, evaluation)
  File "/tmp/Mathics3/mathics-core/mathics/core/expression.py", line 1360, in rewrite_apply_eval_step
    result = rule.apply(new, evaluation, fully=False)
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 176, in apply
    self.pattern.match(
    ~~~~~~~~~~~~~~~~~~^
        expression,
        ^^^^^^^^^^^
    ...<5 lines>...
        },
        ^^
    )
    ^
...
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 387, in match_symbol
    pattern_context["yield_func"](pattern_context["vars_dict"], None)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 148, in yield_match
    new_expression = apply_fn(expression, vars, options, evaluation)
  File "/tmp/Mathics3/mathics-core/mathics/core/rules.py", line 279, in apply_rule
    new = self.replace.replace_vars(vars)
  File "/tmp/Mathics3/mathics-core/mathics/core/symbols.py", line 549, in replace_vars
    assert all(fully_qualified_symbol_name(v) for v in vars)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

Expected behavior

$IterationLimit::itlim: Iteration limit of 20 exceeded.
$Aborted

Additional context

Discovered reading Wagner's Programming with the Mathematica Kernel. Example is taken from that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions