diff --git a/CHANGES.rst b/CHANGES.rst index 428203e582..8847bb94a7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -35,6 +35,7 @@ Enhancements * ``FileNames`` returns a sorted list (#1250). * ``FindRoot`` now receives several optional parameters like ``Method`` and ``MaxIterations``. * ``FixedPoint`` now supports the ``SameTest`` option. +* ``Prepend`` works with ``DownValues`` Issue #1251 * ``Prime`` and ``PrimePi`` now accept a list parameter and have the ``NumericFunction`` attribute. * ``Read`` with ``Hold[Expression]`` now supported. (#1242) * ``ReplaceRepeated`` and ``FixedPoint`` now supports the ``MaxIteration`` option (#1260). diff --git a/mathics/builtin/lists.py b/mathics/builtin/lists.py index 2f5e577400..93df17d205 100644 --- a/mathics/builtin/lists.py +++ b/mathics/builtin/lists.py @@ -2918,8 +2918,11 @@ def apply(self, s, item, evaluation): class Prepend(Builtin): """
-
'Prepend[$expr$, $item$]' -
returns $expr$ with $item$ prepended to its leaves. +
'Prepend[$expr$, $item$]' +
returns $expr$ with $item$ prepended to its leaves. + +
'Prepend[$expr$]' +
'Prepend[$elem$][$expr$]' is equivalent to 'Prepend[$expr$,$elem$]'.
'Prepend' is similar to 'Append', but adds $item$ to the beginning diff --git a/test/test_lists.py b/test/test_lists.py new file mode 100644 index 0000000000..6d267d98ff --- /dev/null +++ b/test/test_lists.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from .helper import check_evaluation + + +def test_calculus(): + for str_expr, str_expected, message in ( + ( + "DownValues[foo]={x_^2:>y}", + "{x_ ^ 2 :> y}", + "Issue #1251 part 1", + ), + ( + "PrependTo[DownValues[foo], {x_^3:>z}]", + "{{x_ ^ 3 :> z}, HoldPattern[x_ ^ 2] :> y}", + "Issue #1251 part 2", + ), + ( + "DownValues[foo]={x_^3:>y}", + "{x_ ^ 3 :> y}", + "Issue #1251 part 3", + ), + + ): + check_evaluation(str_expr, str_expected, message)