Skip to content

Commit

Permalink
Merge branch 'dpbutter-fix-join'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Peeters committed Dec 7, 2023
2 parents c663605 + 99dead0 commit 2011909
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/pythoncdb/py_ex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ namespace cadabra {
auto ret = std::make_shared<Ex>("\\comma");

for(const Ex_ptr& ex: exs) {
auto loc = ret->append_child(ret->begin(), ex->begin());
if(*ex->begin()->name=="\\comma")
ret->flatten_and_erase(loc);
// skip ex if empty
if (ex->size() > 0) {
auto loc = ret->append_child(ret->begin(), ex->begin());
if(*ex->begin()->name=="\\comma")
ret->flatten_and_erase(loc);
}
}
// Note: ret could still \comma{} or \comma{x}
auto it = ret->begin();
if (ret->number_of_children(it) < 2) {
ret->flatten_and_erase(it);
}
return ret;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/programming.cdb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ def test14():
ex4= join(ex1, ex2, ex3)
assert(ex4==${A,C,D,E}$)
print("Test 14g passed")
ex1:= A;
ex4 = join(ex1, Ex(""))
assert(ex4==$A$)
print("Test 14h passed")
ex1:= A;
ex2:= \comma{};
ex4= join(ex1, ex2)
assert(ex4==$A$)
print("Test 14i passed")

test14()

Expand Down

0 comments on commit 2011909

Please sign in to comment.