From 1efe0d076dd93ba6be6def91cc3456a2989e0a6f Mon Sep 17 00:00:00 2001 From: "R. Bernstein" Date: Sun, 5 Jan 2025 04:44:06 -0500 Subject: [PATCH] Add SequenceForm... (#1258) It is used in CombinatoricaV201 even though it is deprecated. --- CHANGES.rst | 1 + SYMBOLS_MANIFEST.txt | 1 + mathics/builtin/forms/other.py | 50 ++++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9c4713370..4156b4251 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,7 @@ New Builtins * ``CheckAbort`` * ``FileNameDrop`` * ``SetEnvironment`` +* ``SequenceForm`` By `@davidar `_: diff --git a/SYMBOLS_MANIFEST.txt b/SYMBOLS_MANIFEST.txt index 6673fc6e4..d8f58101b 100644 --- a/SYMBOLS_MANIFEST.txt +++ b/SYMBOLS_MANIFEST.txt @@ -1069,6 +1069,7 @@ System`SetDirectory System`SetEnvironment System`SetFileDate System`SetOptions +System`SequenceForm System`SetStreamPosition System`Share System`Sharpen diff --git a/mathics/builtin/forms/other.py b/mathics/builtin/forms/other.py index acca73a60..6c3ea7699 100644 --- a/mathics/builtin/forms/other.py +++ b/mathics/builtin/forms/other.py @@ -9,6 +9,50 @@ from mathics.builtin.makeboxes import MakeBoxes from mathics.core.atoms import String from mathics.core.element import EvalMixin +from mathics.eval.strings import eval_ToString + + +class SequenceForm(FormBaseClass): + """ + + :WMA link: + https://reference.wolfram.com/language/ref/SequenceForm.html + +
+
'SequenceForm[$expr1$, $expr2$, ..]' +
format the textual concatenation of the printed forms of $expi$. +
+ 'SequenceForm' has been superseded by :Row: + /doc/reference-of-built-in-symbols/layout/row + and 'Text' (which is not implemented yet). + + >> SequenceForm["[x = ", 56, "]"] + = [x = 56] + """ + + in_outputforms = False + in_printforms = False + + options = { + "CharacterEncoding": '"Unicode"', + } + + summary_text = "format make an string from a template and a list of parameters" + + def eval_makeboxes(self, args, form, evaluation, options: dict): + """MakeBoxes[SequenceForm[args___, OptionsPattern[SequenceForm]], + form:StandardForm|TraditionalForm|OutputForm]""" + encoding = options["System`CharacterEncoding"] + return RowBox( + *[ + ( + arg + if isinstance(arg, String) + else eval_ToString(arg, form, encoding.value, evaluation) + ) + for arg in args.get_sequence() + ] + ) class StringForm(FormBaseClass): @@ -31,9 +75,9 @@ class StringForm(FormBaseClass): in_printforms = False summary_text = "make an string from a template and a list of parameters" - def eval_makeboxes(self, s, args, f, evaluation): + def eval_makeboxes(self, s, args, form, evaluation): """MakeBoxes[StringForm[s_String, args___], - f:StandardForm|TraditionalForm|OutputForm]""" + form:StandardForm|TraditionalForm|OutputForm]""" s = s.value args = args.get_sequence() @@ -53,7 +97,7 @@ def eval_makeboxes(self, s, args, f, evaluation): if 1 <= index <= len(args): arg = args[index - 1] result.append( - to_boxes(MakeBoxes(arg, f).evaluate(evaluation), evaluation) + to_boxes(MakeBoxes(arg, form).evaluate(evaluation), evaluation) ) if pos < len(s): result.append(to_boxes(String(s[pos:]), evaluation))