Message Boards Message Boards

What's the difference between *.m and *.wl file format?

Hello, as a slow beginner this week i am learning about contexts and writing a basic package. Unfortunately I cannot find any explanation about what all the differences between these 2 file formats are. Saving a notebook (including a few initialization cells) as either format seems to produce the identical file?

In Maeder's book, knowledge about contexts and creating packages comes in the first chapter. To him, it is essential knowledge, everything else builds upon. In Wellin's book it comes last, last chapter. This makes me wonder how common it is for the majority of Mma users to write and save their own packages at all, as opposed to just using Mma "directly", i.e. working only with .nb files, without making any/much use of switching contexts, writing own packages, loading own .m .wl package files, and all that spiel.

POSTED BY: Raspi Rascal
5 Replies

.m and .wl are one and the same. The only practical difference is that .wl won't be recognized by Mathematica pre-version-10.0.

One advantage you will get from .wl is that it is unique to Mathematica (while .m is also used by MATLAB, in case you have that installed).

Personally, I still use .m.

POSTED BY: Szabolcs Horvát

I usually write packages in a .nb file and change "AutoGeneratedPackage" to "Automatic" in the Option Inspector. Notebook Options->File Options->AutoGeneratedPackage.

This lets me use the formatting features of .nb files and generate the package file automatically when it is saved.

Regards,

Neil

POSTED BY: Neil Singer

There is no difference. You can change the extension in the Finder (or the equivalent in Windows/Linux), and Mathematica will do the same thing. I wouldn't recommend doing this with files you did not write, since the programs that load the package may look for a specific extension. As far as I know, Needs[] does not, and that is the recommended way to load files anyway.

There are a lot more .m files inside the Mathematica than .wl because the .m files have been around a lot longer, and Wolfram Research does not change stuff for cosmetic reasons generally.

You can, of course, have a file with a single function that is not in a package. There are exercises in the various "learning Wolfram Language" books to do this, as well as to make files that contain data. How something like this ended up inside the Mathematica distribution may have an interesting history. Obviously, the .m or .wl extension is preferred over the .nb because there is less cruft.

You can have a package for a single function that is used in multiple locations. You can have multiple functions as well. One of the nice things is that you can hide auxiliary functions in the package and the end user will not see them or have access to them.

You can even have a package inside a .nb notebook. I do this sometimes when I want to send a file to someone and I don't want them to have to install a package file (.wl) in the appropriate context. A Package, after all is defined by the context BeginPackage[], ... , EndPackage[], and not where it is.

The .wl files are intended to hold only packages, with documentation.

When the .wl file extension come out, I did ask support about it. The assured me that the .m and .wl file formats are the same, and the the .m extension has essentially been deprecated, although it will remain as a valid extension essentially forever. So I don't expect that there will ever be any official documentation about the change.

I think that there is a need for a book beyond Stephen's Introduction that will cover topics like packages in the same style without all the extra knowledge that is assumed in Maeder's or Wellin's books. The Wolfram Language documentation is quite good as far as it goes, but for someone who is not familiar with the concepts, it is a bit cryptic.

The .m suffix is the old way of saving package files, and is used only for backwards compatibility. Use .wl for new stuff.

If you only write use-once code, then there is no need for making packages. I suppose that the majority of Mathematica users use the language as an interactive calculator, and so would never need to build a package. However, if you write code that will be used again, then making a package has advantages. It is the closest thing in Wolfram Language to source code files, such as .c or .swift files.

If you open a .wl and a .nb file in a text editor, you will see another difference. The .nb file has a lot of information on creation dates, modifications, etc. that are useful for a notebook file, but not so much for computer source code. For this reason, source management systems, such as GitHub, are much more effective with .wl files.

Maeder's book is older than Wellin's book, and his emphasis is on package development, as opposed to Wellin's book, which emphasizes programming using Wolfram Language. Maeder's book assumes that you already know much of what Wellin is presenting, although a lot of stuff in the newer book did not exist in versions 1 or 2 of Mathematica which is the time frame of the older books. There is still a lot of useful stuff in Maeder's books, but you need to "translate" it into the world of Mathematica 11 or 12.

In my own work, I do explorations using notebooks. I typically produce what are now called computational notebooks using just .nb files. However, when a project warrants it, I will make a package so that 1) the code is better organized, and 2) it can be reused in other projects.

You can do almost everything you need to do to make packages from within Mathematica or Wolfram|One itself, except preparation of fancy documentation like you see int he documentation center. For that you will need Wolfram Workbench, which adds an extra level of complexity into the process.

My suggestion is that you use the File menu to start a package project. It makes things easier to manage. You can convert a .nb file to a .wl file, but you need to know what you are doing. In my case, when I am ready to make a package with some code I have created in a notebook (.nb), I start a new package file and cut and paste the code.

Hope this helps.

I suppose that the majority of Mathematica users use the language as an interactive calculator, and so would never need to build a package.

Great post, thanks so much for it! Yes, this helps a lot.

So there is no difference in form, content, application, or concept between a .m and .wl file? I am also going to suppose that the creation/handling of packages by end users was more a common thing in the past than it is nowadays? Looking at literature, libraries, archives, repositories, directories (also on HDD, see your Mma install dir), there seems to exist so many more .m files than .wl files.

I browsed through the contents of .wl files from my Mma install dir: some of them contained packages, others contained code for a single function. And the code tended to have more framework-related functionality than expanding the end user's session with added mathematical functions. The code/content of those files looked less structured to me, providing maybe auxiliary functionality to the overall system, not to the end user's end in the end. Well, that was my impression, and i could be wrong.

Both file types contain source code in input form, with no information on cell properties as seen in .nb files.

I cannot find any official online tutorials or documentation treating the .m .wl difference topic, so maybe we should not bother either?

POSTED BY: Raspi Rascal
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