Skip to content

Commit

Permalink
Correct error results.
Browse files Browse the repository at this point in the history
Thanks mmatera!
  • Loading branch information
rocky committed Apr 21, 2021
1 parent 3866c5c commit bd1d821
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions mathics/builtin/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2099,8 +2099,8 @@ class StringTake(Builtin):
<dt>'StringTake["$string$", {$m$, $n$, $s$}]'
<dd>gives characters $m$ through $n$ in steps of $s$.
<dt>'StringTake["$string$", {$m$, $n$, $s$}]'
<dd>gives characters $m$ through $n$ in steps of $s$.
<dt>'StringTake[{$s1$, $s2$, ...} $spec$}]'
<dd>gives the list results for each of the $si$.
</dl>
>> StringTake["abcde", 2]
Expand Down Expand Up @@ -2134,11 +2134,21 @@ class StringTake(Builtin):
#> StringTake["abc", {0, 0}]
: Cannot take positions 0 through 0 in "abc".
= StringTake[abc, {0, 0}]
#> StringTake[{2, 4},2]
: String or list of strings expected at position 1.
= StringTake[{2, 4}, 2]
#> StringTake["kkkl",Graphics[{}]]
: Integer or a list of sequence specifications expected at position 2.
= StringTake[kkkl, -Graphics-]
"""

messages = {
"strse": "String expected at position 1.",
"mseqs": "Integer or list of two Intergers are expected at position 2.",
"strse": "String or list of strings expected at position 1.",
# FIXME: mseqs should be: Sequence specification (+n, -n, {+n}, {-n}, {m, n}, or {m, n, s}) or a list
# of sequence specifications expected at position 2 in
"mseqs": "Integer or a list of sequence specifications expected at position 2.",
"take": 'Cannot take positions `1` through `2` in "`3`".',
}

Expand Down Expand Up @@ -2173,8 +2183,9 @@ def apply_strings(self, strings, spec, evaluation):
result_list = []
for string in strings.leaves:
result = self.apply(string, spec, evaluation)
if result is not None:
result_list.append(result)
if result is None:
return None
result_list.append(result)
return Expression("List", *result_list)


Expand Down Expand Up @@ -2208,7 +2219,7 @@ class StringDrop(Builtin):

messages = {
"strse": "String expected at position 1.",
"mseqs": "Integer or list of two Intergers are expected at position 2.",
"mseqs": "Integer or list of two Integers are expected at position 2.",
"drop": 'Cannot drop positions `1` through `2` in "`3`".',
}

Expand Down

0 comments on commit bd1d821

Please sign in to comment.