The issue is with this line:
squares := !squares :: (!x * !x);
Essentially, the cons operator (::) takes in an element and a list and returns a list which you are doing but in the wrong order. So from my understading the line should be replaced with:
squares := (!x * !x) :: !squares;