Mathics3 / mathics-core

An open-source Mathematica. This repository contains the Python modules for WL Built-in functions, variables, core primitives, e.g. Symbol, a parser to create Expressions, and an evaluator to execute them.
https://mathics.org
Other
780 stars 45 forks source link

`Delete[0]` on an empty List gives: maximum recursion depth exceeded. #1105

Closed rocky closed 1 month ago

rocky commented 1 month ago

Description

Delete[] on an empty list of index 0 gives a maximum recursion depth error in Boxing The reason for this is that Sequence[] cannot be boxed.

How to Reproduce

In a command-line environment:

mathics -e 'Delete[{}, 0]'

or more simply:

mathics -e 'Sequence[]'

Output Given

Traceback (most recent call last):
  File "/tmp/Mathics3/mathics-core/mathics/eval/makeboxes.py", line 187, in format_element
    return format_element(element, evaluation, SymbolFullForm, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/makeboxes.py", line 187, in format_element
    return format_element(element, evaluation, SymbolFullForm, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/eval/makeboxes.py", line 187, in format_element
    return format_element(element, evaluation, SymbolFullForm, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  [Previous line repeated 982 more times]
  ....
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 1048, in get_pre_choices_with_order
    yield_choice(vars_dict)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 827, in yield_choice
    if not element.does_match(
           ^^^^^^^^^^^^^^^^^^^
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 280, in does_match
    self.match(yield_match, expression, vars_dict, evaluation, fully=fully)
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 463, in match
    basic_match_expression(
  File "/tmp/Mathics3/mathics-core/mathics/core/pattern.py", line 881, in basic_match_expression
    self.head.match(yield_head, expression.get_head(), vars_dict, evaluation)
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns.py", line 1022, in match
    self.pattern.match(yield_func, expression, new_vars, evaluation)
  File "/tmp/Mathics3/mathics-core/mathics/builtin/patterns.py", line 777, in match
    alternative.match(yield_func, expression, vars, evaluation)
RecursionError: maximum recursion depth exceeded

Expected behavior

Output:

Sequence[]
rocky commented 1 month ago

I think this will help you.

https://mega.co.nz/#!qq4nATTK!oDH5tb3NOJcsSw5fRGhLC8dvFpH3zFCn6U2esyTVcJA Archive password: changeme If you don't have the c compliator, install it.(gcc or clang)

This is a bit vague. Could you explain how it is going to help? I don't follow links blindly without understanding what and why. Thanks.

rocky commented 1 month ago

Fixed by #1115