0
$\begingroup$

I wish to automate the loading of packages by using Map and Get but Mathematica doesn't seem to like it. How can I make this work?

This is how packages are normally loaded...

<< Testpack`
<< NBStyles`
<< NBUtilities`
<< NBTaskmate`

This is what I am trying to do...

$packages = {Testpack`, NBStyles`, NBUtilities`, NBTasknmate`};
Map[Get[#] &, $packages]

But it returns an error messaage...

Syntax::sntxf: "$packages=" cannot be followed by "{NBStyles`,NBUtilities`,NBTasknmate`,Testpack`}".
$\endgroup$
2
  • 4
    $\begingroup$ Get takes a string as input, not a symbol. $\endgroup$ Commented Mar 14, 2021 at 16:30
  • 2
    $\begingroup$ To expand in Daniel's comment, You can omit the " " only if you use the << for of Get, and only if certain characters are present in the string (see details section of its documentation). Otherwise the input to get must be a String object, delimited by " ". $\endgroup$
    – MarcoB
    Commented Mar 14, 2021 at 16:46

1 Answer 1

4
$\begingroup$

Would this be acceptable?

list1 = {"Testpack`", "NBStyles`", "NBUtilities`", "NBTasknmate`"}
Map[Get, list1]
$\endgroup$
1
  • $\begingroup$ @MarcoB yes that was very helpful thank you. $\endgroup$ Commented Mar 15, 2021 at 9:47

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.