Skip to content

Commit

Permalink
Add SequenceForm... (#1258)
Browse files Browse the repository at this point in the history
It is used in CombinatoricaV201 even though it is deprecated.
  • Loading branch information
rocky authored Jan 5, 2025
1 parent fedbb14 commit 1efe0d0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ New Builtins
* ``CheckAbort``
* ``FileNameDrop``
* ``SetEnvironment``
* ``SequenceForm``

By `@davidar <https://github.com/davidar>`_:

Expand Down
1 change: 1 addition & 0 deletions SYMBOLS_MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ System`SetDirectory
System`SetEnvironment
System`SetFileDate
System`SetOptions
System`SequenceForm
System`SetStreamPosition
System`Share
System`Sharpen
Expand Down
50 changes: 47 additions & 3 deletions mathics/builtin/forms/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
<url>
:WMA link:
https://reference.wolfram.com/language/ref/SequenceForm.html</url>
<dl>
<dt>'SequenceForm[$expr1$, $expr2$, ..]'
<dd>format the textual concatenation of the printed forms of $expi$.
</dl>
'SequenceForm' has been superseded by <url>:Row:
/doc/reference-of-built-in-symbols/layout/row
</url> 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):
Expand All @@ -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()
Expand All @@ -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))
Expand Down

0 comments on commit 1efe0d0

Please sign in to comment.