3
$\begingroup$

I am using LocalSymbol to store some database credentials. I put a statement like this in a user-level autoload package:

$PostgresCredentials = LocalSymbol @ "DefaultPostgres";

This returns unevaluated when this package is autoloaded (i.e. it evaluates to LocalSymbol @ "DefaultPostgres"). Evaluate does not fix the issue.

If I reload the package manually after my session has started, then $PostgresCredentials correctly pulls the LocalSymbol. And of course if I define it with SetDelayed it will work.

I am just wondering what the problem is. Is it possible to access a LocalSymbol at the autoload stage?

$\endgroup$
  • 1
    $\begingroup$ I have not tried to reproduce this problem, but I know that there are several things that do not work during kernel initialization. The typical symptoms tend to be different from what you describe though. Take a look at this question and the links within: mathematica.stackexchange.com/q/132212/12 $\endgroup$ – Szabolcs Feb 20 '17 at 22:01
  • $\begingroup$ My point is that there are many limitations during initialization, and you may be forced to roll your own persistent storage implementation. One way is to write/read an .m file to/from $UserBaseDirectory/ApplicationData/YourPackageName. Use Put/Get to do this, not Export/Import. Export/Import does not work during initiailzation. A nice way is to just put an association with string keys into that .m file. $\endgroup$ – Szabolcs Feb 20 '17 at 22:03
  • $\begingroup$ Another thing: I would be cautious with LocalSymbol if you plan to distribute your package. LocalSymbol has trouble with paths that contain spaces. Windows encourages usernames with spaces, which means that LocalSymbol's default storage location will often have spaces on Windows ... $\endgroup$ – Szabolcs Feb 20 '17 at 22:06
  • $\begingroup$ @Szabolcs Thanks. I did intend to use it for packages so I will avoid this can of worms. I'll use your Get suggestion instead. $\endgroup$ – mfvonh Feb 21 '17 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.