Skip to content

Commit

Permalink
Add SequenceForm...
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 committed Dec 31, 2024
1 parent 1ed7495 commit 7283573
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
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
2 changes: 1 addition & 1 deletion mathics/packages/Combinatorica-repo

0 comments on commit 7283573

Please sign in to comment.