# Assigning ::usage in a package for in Private generated symbols?

I'm having difficulties assigning ::usage in a Mathematica package for symbols in a list or dataset, that will only be defined later in a Private subcontext.

In Private I have something like this:

list = Dataset[
{<|"name" -> "Alpha", "age" -> 123|>,
<|"name" -> "Beta", "age" -> 456|>,
<|"name" -> "Gamma", "age" -> 789|>
}];

Do[Evaluate[Symbol["my" <> list[i, "name"]]] = list[i, "age"], {i, 1, Length[list]}];


How can I now generically specify a ::usage for the symbols myAlpha, etc. before they are even generated? I would like to, as usual, do something like this right after BeginPackage[]

Do[Evaluate[Symbol["my" <> list[i, "name"]]]::usage = "", {i, 1, Length[list]}];


but now obviously list is not yet defined. Can I somehow set this delayed or on hold or anything until the dataset was generated? I couldn't get it working so far.

Thanks alot,

T

• Will list be created before you start defining any of my* symbols? In which context should they be created? – Kuba Sep 2 '16 at 12:49
• If you need to create the symbols in a specific context, prepend that context to their name (I mean the string in Symbol). – Szabolcs Sep 2 '16 at 12:56
• @Kuba Yes, list is created before the my* symbols, just as stated in my question. I'd like them all to be in context Private, but use ::usage to be able to auto-complete the my* symbols with their correctly assigned values ("age" in this case). – T_202 Sep 2 '16 at 13:12
• I'm assuming autocomplete in a notebook. So they are not private, they are meant to be Package . Then, as Szabolcs suggested use "MyPackagemy"<>. – Kuba Sep 2 '16 at 13:18
• Is that what you need? – Kuba Sep 5 '16 at 5:43

Is this what you want?

I've changed your Evaluate[Symbol["my" <> list[i, "name"]]] =... to something more flexible. Read more in: How do you programatically load data into symbols?

BeginPackage["Test"];

Begin["Private"];

list = {<|"name" -> "Alpha", "age" -> 123|>, <|"name" -> "Beta",
"age" -> 456|>, <|"name" -> "Gamma", "age" -> 789|>};

ToExpression[
"Testmy" <> #name, StandardForm, Function[name, name = #age, HoldFirst]
] & /@ list;

ToExpression[
"my" <> #name, StandardForm, Function[name, name::usage = "test", HoldFirst]
] & /@ list;
(*notice that the second time they are mentioned they will be found on \$ContextPath*)

privateSymbol = {myAlpha, myGamma};

End[];

EndPackage[];


I've dropped Dataset till this problem is solved: Problems with Dataset's querying on a fresh Kernel

• Thanks alot @Kuba, that helps and also thanks for pointing out the bug with the Datasets! With respect to this, hopefully this also helped others. – T_202 Sep 12 '16 at 8:20