# How to load function for use like built-in function

I would like to call a user-defined function in any context. To this end I placed it in $BaseDirectory\init.m: util[x_] := ToString[x] <> "A";  However, to use it in a package it needs to be prefixed with Global. BeginPackage["fun"]; fun; Begin["Private"]; fun[x_] := Globalutil[x + 1]; End[]; EndPackage[]  Is there a way to implement the function so that it is available in any context without Needs or Global? ## 1 Answer System is not dropped from $ContextPath by BeginPackage:

BeginPackage["Test"];
\$ContextPath
EndPackage[];

 {"Test", "System"}


So the way to go can be:

Systemutil[x_] := ToString[x] <> "A"


Just be careful about names, maybe assume a convention Systemcustom{name} just in case to avoid collisions.

• This works well. Thanks. – Chris Degnen Jan 24 '18 at 15:46
• while this works, I hope you are aware of the fact that now your packages depends on that specific entry in init.m. That will make it very complicated error-prone if ever you want to share or move those packages... – Albert Retey Jan 25 '18 at 10:12
• @AlbertRetey I thought this is rather for own use, it should be clear that if you you want to share such feature with someone who may have had the same need then, sooner or later conflicts will happen. Maybe I didn't understand the use case :-/ – Kuba Jan 25 '18 at 10:17
• I was guessing that you and actuall also Chris are well aware of that. I just thought it would make sense to mention it so that other readers will also be warned... – Albert Retey Jan 25 '18 at 10:21
• @AlbertRetey you are right, it makes sense. – Kuba Jan 25 '18 at 10:22