Message Boards Message Boards

0
|
252971 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Set up a package with Needs[]?

Posted 7 years ago

By steps Insert/FilePath, I got a file path: "D:\Mathematica\Mathematica Programer II\MATHPROG\LOGICPROGRAMMING.M", but

Needs["D:\\Mathematica\\Mathematica Programer \
II\\MATHPROG`LOGICPROGRAMMING.m`"]

Mathematica always says

    Needs::cxt: Invalid context specified at position 1 in
 Needs[D:\Mathematica\Mathematica Programer II\MATHPROG`LOGICPROGRAMMING.m` ]. 
A context must consist of valid symbol names separated ` 

In fact I put `, What's wrong?

POSTED BY: Math Logic
4 Replies
Posted 7 years ago

Got it !(See below run result.) In fact, all the packages and the files in the directory, hold CAPITAL LETTERS. However, inner the files.m , the self-names are stated in lower case like MathProg, LogicProgramming.m. Now I transformed all in lowercase, and run successfully. Thank you very much for your help ![enter image description here][1]

Attachments:
POSTED BY: Math Logic

you need to add a prime at the end of the context name, and delete it from the file name:

Needs["MATHPROG`LOGICPROGRAMMING`", "D:\\Mathematica\\Mathematica \
Programer II\\MATHPROG`LOGICPROGRAMMING.m"]

Also, are you sure your context in the .m file is in all capital letters like that? -- make sure to match the case of the Begin[...] in the .m file.

POSTED BY: Neil Singer
Posted 7 years ago

enter image description hereThanks!enter image description here But still failed, running see result image.

Mathematica sometimes does run when code meet their syntax!

POSTED BY: Math Logic

The first argument of Needs is not the path, but the context. You can give the path as second argument. Something like this:

Needs["MATHPROG`LOGICPROGRAMMING", "D:\\Mathematica\\Mathematica \
Programer II\\MATHPROG`LOGICPROGRAMMING.m`"]

but you will probably have to retype the context and path. You can use Get with the path only.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract