From ddf630693952db30688e1171df0a262ca5025a60 Mon Sep 17 00:00:00 2001 From: "R. Bernstein" Date: Thu, 3 Oct 2024 16:54:54 -0400 Subject: [PATCH] Guard against running Delete[] on an empty list. (#1109) Co-authored-by: Juan Mauricio Matera --- mathics/builtin/list/eol.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mathics/builtin/list/eol.py b/mathics/builtin/list/eol.py index d0c6b4965..a78f848a0 100644 --- a/mathics/builtin/list/eol.py +++ b/mathics/builtin/list/eol.py @@ -370,10 +370,15 @@ def eval(self, expr, positions, evaluation): ) return + elements = positions.elements + if len(elements) == 0: + return expr + # Create new python list of the positions and sort it + positions = ( - [t for t in positions.elements] - if positions.elements[0].has_form("List", None) + [t for t in elements] + if isinstance(elements[0], ListExpression) else [positions] ) positions.sort(key=lambda e: e.get_sort_key(pattern_sort=True))