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
753 stars 43 forks source link

Anything with more than one minus sign on top crashes the program #267

Closed DUOLabs333 closed 2 years ago

DUOLabs333 commented 2 years ago

Description

Title

How to Reproduce

--5 ## Output Given
Traceback (most recent call last):
  File "/home/system/PDM/mathicsscript/__pypackages__/3.10/bin/mathicsscript", line 8, in <module>
    sys.exit(main())
  File "/home/system/PDM/mathicsscript/__pypackages__/3.10/lib/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/system/PDM/mathicsscript/__pypackages__/3.10/lib/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/system/PDM/mathicsscript/__pypackages__/3.10/lib/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/system/PDM/mathicsscript/__pypackages__/3.10/lib/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/system/Repos/mathicsscript/mathicsscript/__main__.py", line 401, in main
    result = evaluation.evaluate(
  File "/home/system/Repos/mathics-core/mathics/core/evaluation.py", line 343, in evaluate
    result = run_with_timeout_and_stack(evaluate, timeout, self)
  File "/home/system/Repos/mathics-core/mathics/core/evaluation.py", line 98, in run_with_timeout_and_stack
    return request()
  File "/home/system/Repos/mathics-core/mathics/core/evaluation.py", line 314, in evaluate
    self.last_eval = query.evaluate(self)
  File "/home/system/Repos/mathics-core/mathics/core/expression.py", line 594, in evaluate
    expr, reevaluate = expr.rewrite_apply_eval_step(evaluation)
  File "/home/system/Repos/mathics-core/mathics/core/expression.py", line 1235, in rewrite_apply_eval_step
    result = rule.apply(new, evaluation, fully=False)
  File "/home/system/Repos/mathics-core/mathics/core/rules.py", line 79, in apply
    self.pattern.match(yield_match, expression, {}, evaluation, fully=fully)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 344, in match
    self.head.match(yield_head, expression.get_head(), vars, evaluation)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 188, in match_symbol
    yield_func(vars, None)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 334, in yield_head
    self.get_pre_choices(
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 482, in get_pre_choices
    yield_func(vars)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 311, in yield_choice
    self.match_leaf(
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 693, in match_leaf
    self.get_wrappings(
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 509, in get_wrappings
    yield_func(items[0])
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 681, in yield_wrapping
    leaf.match(
  File "/home/system/Repos/mathics-core/mathics/builtin/patterns.py", line 1000, in match
    self.pattern.match(yield_func, expression, new_vars, evaluation)
  File "/home/system/Repos/mathics-core/mathics/builtin/patterns.py", line 1203, in match
    yield_func(vars, None)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 661, in match_yield
    self.match_leaf(
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 693, in match_leaf
    self.get_wrappings(
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 509, in get_wrappings
    yield_func(items[0])
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 681, in yield_wrapping
    leaf.match(
  File "/home/system/Repos/mathics-core/mathics/builtin/patterns.py", line 1000, in match
    self.pattern.match(yield_func, expression, new_vars, evaluation)
  File "/home/system/Repos/mathics-core/mathics/builtin/patterns.py", line 1203, in match
    yield_func(vars, None)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 678, in match_yield
    yield_func(new_vars, items_rest)
  File "/home/system/Repos/mathics-core/mathics/core/pattern.py", line 654, in leaf_yield
    yield_func(
  File "/home/system/Repos/mathics-core/mathics/core/rules.py", line 54, in yield_match
    new_expression = self.do_replace(expression, vars, options, evaluation)
  File "/home/system/Repos/mathics-core/mathics/core/rules.py", line 212, in do_replace
    return self.function(evaluation=evaluation, **vars_noctx)
  File "/home/system/Repos/mathics-core/mathics/builtin/assignments/assignment.py", line 108, in apply
    self.assign(lhs, rhs, evaluation)
  File "/home/system/Repos/mathics-core/mathics/builtin/assignments/internals.py", line 743, in assign
    return self.assign_elementary(lhs, rhs, evaluation)
  File "/home/system/Repos/mathics-core/mathics/builtin/assignments/internals.py", line 704, in assign_elementary
    return assign_store_rules_by_tag(self, lhs, rhs, evaluation, tags, upset)
  File "/home/system/Repos/mathics-core/mathics/builtin/assignments/internals.py", line 32, in assign_store_rules_by_tag
    lhs, condition = unroll_conditions(lhs)
  File "/home/system/Repos/mathics-core/mathics/builtin/assignments/internals.py", line 180, in unroll_conditions
    name, lhs_elements = lhs.get_head_name(), lhs._elements
AttributeError: 'Integer' object has no attribute '_elements'. Did you mean: 'get_elements'?

Expected behavior

5

Your Environment

Workarounds

Priority

Additional context

If you add a try in the specified place, you get a 4. Interesting.

DUOLabs333 commented 2 years ago

I tried that and got Set::setraw: Cannot assign to raw object 5, and gave me 4.

TiagoCavalcante commented 2 years ago

@DUOLabs333 that is correct ++ and -- are respectively increment and decrement operators in C and in Mathics.

DUOLabs333 commented 2 years ago

Oh, did not know that. There's still the error message, though.

TiagoCavalcante commented 2 years ago

@DUOLabs333 that is because increment and decrement assign to the variable and 5 is not a variable.

DUOLabs333 commented 2 years ago

Ah, OK.