Skip to content

Commit 5a78087

Browse files
committed
Merge pull request #1216 from mathics/improvestringsplit
`StringSplit`: adding support for handling lists as a first argument
2 parents cead2cf + f5082d2 commit 5a78087

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGES.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ Enhancements
2626
``Compile[] and CompiledFunction[]`` every expression can have a compiled form,
2727
as a Python function.
2828
* ``Equal[]`` now compares complex against other numbers properly.
29-
* Improvements in handling products with infinite factors: ``0 Infinity``-> ``Indeterminate``, and ``expr Infinity``-> ``DirectedInfinite[expr]`.
30-
* ``SetDelayed`` now accept several conditions impossed both at LHS as well as RHS.
29+
* Improvements in handling products with infinite factors: ``0 Infinity``-> ``Indeterminate``, and ``expr Infinity``-> ``DirectedInfinite[expr]``
30+
* ``StringSplit`` now accepts a list in the first argument.
31+
* ``SetDelayed`` now accepts several conditions imposed both at LHS as well as RHS.
32+
3133

32-
3334
Bug fixes
3435
+++++++++
3536

mathics/builtin/strings.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ class StringSplit(Builtin):
868868
<dd>splits $s$ at the delimiter $d$.
869869
<dt>'StringSplit[$s$, {"$d1$", "$d2$", ...}]'
870870
<dd>splits $s$ using multiple delimiters.
871+
<dt>'StringSplit[{$s_1$, $s_2, ...}, {"$d1$", "$d2$", ...}]'
872+
<dd>returns a list with the result of applying the function to
873+
each element.
871874
</dl>
872875
873876
>> StringSplit["abc,123", ","]
@@ -885,6 +888,9 @@ class StringSplit(Builtin):
885888
>> StringSplit["a b c", RegularExpression[" +"]]
886889
= {a, b, c}
887890
891+
>> StringSplit[{"a b", "c d"}, RegularExpression[" +"]]
892+
= {{a, b}, {c, d}}
893+
888894
#> StringSplit["x", "x"]
889895
= {}
890896
@@ -921,6 +927,11 @@ class StringSplit(Builtin):
921927

922928
def apply(self, string, patt, evaluation, options):
923929
"StringSplit[string_, patt_, OptionsPattern[%(name)s]]"
930+
931+
if string.get_head_name() == "System`List":
932+
leaves = [self.apply(s, patt, evaluation, options) for s in string._leaves]
933+
return Expression("List", *leaves)
934+
924935
py_string = string.get_string_value()
925936

926937
if py_string is None:

0 commit comments

Comments
 (0)