Search code examples
rascal

Appending to lists inside ADT


I am trying to append to a list inside an ADT as follows:

data MyADT = myadt(list[str] s); 
m = myadt([]);
m.s += "test";

Which causes an error:

|prompt:///|(0,3,<1,0>,<1,3>): Expected list[str], but got str
?[Advice](http://tutor.rascal-mpl.org/Errors/Static/UnexpectedType/UnexpectedType.html)

Which seems like it should work because this works:

x = [];
x += "test";

Maybe I am missing something here?

Thanks!


Solution

  • Try this as a workaround:

    rascal>m.s += ["test"];
    MyADT: myadt(["test"])
    

    It looks like a bug.

    By the way we will remove the overloading of + to add both elements and concatenate lists and introduce a special operator for adding elements. It's confusing as it is now.