"Invalid sequence" in Maple

184 Views Asked by At

I tried to define a procedure in Maple as follows. removeAnElementInList:=proc(i, l) local r, j; r:=[]; for j from 1 to lengthOfList(l) do ( if(j<>i) then r:=append(r, l[j]) end if ) end do; return(r); end proc;

But Maple returns an error: invalid sequence (at "then"). But I don't know where is the problem. I checked the codes for half an hour but didn't find the problem. Any help will be greatly appreciated!

2

There are 2 best solutions below

2
On BEST ANSWER

Now its correct

removeAnElementInList:=proc(i, l) local r, j; r:=[]; for j from 1 to lengthOfList(l) do if (j<>i) then r:=append(r, l[j]) end if end do; return(r); end proc;

4
On

You can do that way more simply, as well as way more efficiently, via

removeAnElementInList := proc(i, l) remove(j -> evalb(j = i), l) end proc;