3
$\begingroup$

In a notebook, I can easily search an expression for a custom symbol.

In[237]:= Position[{mySym, 1, 2}, mySym]
Out[237]= {{1}}

However, if I write a function and place it within a package;

FindSym[x_] := Position[x, mySym]

In[234]:= Clear@"PA`"
<< PA`
PA`Private`FindSym[{mySym, 1, 2}]
Out[236]= {}

The symbol can no longer be found. However, if instead of searching on a symbol, I search on a literal (string or number) or even a built-in name, the package version works.

I feel I'm missing something subtle. If anybody could give me pointers, I would be grateful.

$\endgroup$

1 Answer 1

4
$\begingroup$

If you literally have

FindSym[x_] := Position[x, mySym]

in your package, then this mySym is probably created in PA`Private` (depending on your package setup). PA`Private`mySym is distinct from Global`mySym . You were searching for the former when only the latter was present.

$\endgroup$
1
  • $\begingroup$ Doh! I felt it was something like that. Thank you Szabolcs. $\endgroup$ Commented Sep 23, 2021 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.