It seems this is a commonly asked question as stated in this link. The reason is that variable a
inside swim
becomes a local variable as soon as there is an assignment to a
. It shadows the external a
, and local a
is not defined before assignment in function swim
, so the error rises.
Thanks for all your guys' answers!