Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Improve Monomial ordering.

### Bugs Fixed

1. [\#2003](https://github.com/Mathics3/mathics-core/issues/2003) `Riffle[{a}, x]` gives `{a}`: a non-list separator is inserted only between elements

## 10.0.1

April 18, 2026
Expand Down
14 changes: 7 additions & 7 deletions mathics/builtin/import_export/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,15 +778,15 @@ class ExportString(Builtin):

>> ExportString[{{1,2,3,4},{3},{2},{4}}, "CSV"]
= 1,2,3,4
. 3,
. 2,
. 4,
. 3
. 2
. 4

>> ExportString[{1,2,3,4}, "CSV"]
= 1,
. 2,
. 3,
. 4,
= 1
. 2
. 3
. 4
>> ExportString[Integrate[f[x],{x,0,2}], "SVG"]//Head
= String
"""
Expand Down
8 changes: 7 additions & 1 deletion mathics/builtin/list/rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,13 @@ def eval(self, list, sep, evaluation: Evaluation):
if sep.has_form(SymbolList, None):
result = riffle_lists(list.elements, sep.elements)
else:
result = riffle_lists(list.elements, [sep])
# A non-list separator goes only between elements, never
# after the last one: Riffle[{a}, x] is {a}.
result = []
for i, element in enumerate(list.elements):
if i > 0:
result.append(sep)
result.append(element)

return list.restructure("List", result, evaluation, deps=(list, sep))

Expand Down
11 changes: 11 additions & 0 deletions test/builtin/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@
"{{{1, 1, 1}, {1, 1, 2}, {1, 2, 1}, {1, 2, 2}}, {{2, 1, 1}, {2, 1, 2}, {2, 2, 1}, {2, 2, 2}}}",
None,
),
# Riffle
(
"Riffle[{a}, x]",
None,
"{a}",
"non-list separator goes only between elements",
),
("Riffle[{a, b}, x]", None, "{a, x, b}", "Issue #2003"),
("Riffle[{}, x]", None, "{}", "Degenerate Riffle on empty list"),
("Riffle[{a}, {x}]", None, "{a, x}", "equal lengths: separator list appended"),
("Riffle[{a, b}, {x, y}]", None, "{a, x, b, y}", None),
# Union and Intersection
(
"Union[{1, -1, 2}, {-2, 3}, SameTest -> (Abs[#1] == Abs[#2] &)]",
Expand Down