I'm fairly new to Mathematica but I'm in the process of setting up some basic analysis based off someone else's work. They had a number of shared functions stored in a shared code directory and were using Get
to import them; however, their code was stored in .txt
files. I'd like to replicate that setup but use .m
files instead to take advantage of Mathematica formatting / debugging, but when I try to import the code from my files the function definitions don't seem to come through. Get
isn't returning any errors, but my functions seems to remain undefined (e.g. name in blue, returned as symbolic). Any help would be greatly appreciated, thanks!
-
$\begingroup$ Is it possible to link to the files? If not it's hard to debug the problem. $\endgroup$ – Jonathan Shock Jul 1 '13 at 21:28
-
$\begingroup$ The basics can be downloaded from here, thanks! $\endgroup$ – orenyk Jul 1 '13 at 21:40
-
$\begingroup$ perhaps this? $\endgroup$ – cormullion Jul 1 '13 at 22:58
One of your files, expMatrices.m
, looks like this outside Mathematica:
You can see that every line is commented out.
If I open this file in Mathematica, it looks like this (I've switched the toolbar on):
This looks OK (you can see that only some of the contents are comments, not the whole thing), but the code is in cells that have the Input style; for this type of file they should be in Code style. To do this, select them, and choose Code from the style menu (or Format>Style>Code):
This is now going to work as you expect.
If someone knows a good documentation reference for this not very intuitive design, please add it to this answer. I couldn't find anything particularly informative (except for rm-rf's answer that I mentioned in my comment).
-
$\begingroup$ Cells don't really have to be given
Code
style; the cells just need have the propertyInitialization Cell
$\endgroup$ – m_goldberg Jul 2 '13 at 13:09 -