ClearAll
is just needed to be sure you don't have multiple definitions of your BracketedVector
function:
BracketedVector[letter_String,n_Integer] := .......
will not automatically overwrite
BracketedVector[letter_,n_] := ....
So you are left with two definitions! It will first check the most specific one (is your first argument a string, and the second an integer?), if that one doesn't match it will try the second definition.
In your case you don't need to clear letter
. This is part of the pattern (by using an underscore) and is therefore local, In fact you really don't need the module at all:
BracketedVector[letter_, n_] := Table[Symbol[letter][i], {i, n}]
will just work fine, and gives identical results. Module is just needed if you want some local variables, here you don't need any. i
,n
,letter
are all 'local' in some sense: letter
and n
are local because they are part of SetDelayed
, and i
is local because it is used in Table
. To make your code even more easy to read, you can ditch Table and it's variable i
altogether, and use Array:
BracketedVector[letter_, n_] := Array[Symbol[letter], n]
again, same output, incredibly easy to read, no other variables, and better performance!