开发者

Mathematica: is it possible to make an automatic init.m file for simple packages

Most of my personal packages are just a single m-file, say Foo.m, but they usually end up as Foo/Foo.m so that I can store related tests and notes in the Foo directory as well. To allow the packages to be loaded with just <<Foo`, I include Foo/init.m as follows:

With[{packagename="Foo"},
  Get@FileNameJoi开发者_如何转开发n@{ 
    DirectoryName@FindFile[packagename<>"`"],
    packagename<>".m"}]

This works fine as long as I remember to update packagename when I copy init.m to new packages, but I was wondering if there is a way of making a completely reusable init.m for this simple case?

Just for completeness, I don't want to rename the implementation implementation.m.


I'm not quite sure to understand your question but here is a guess anyway ...

Did you try something like

packagename = StringDrop[DirectoryName[$Input], -1]  

in your first line?

Edit: for future reference

After Janus test, it became that the correct expression is:

packagename=StringDrop[$Input,-2]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜