Message Boards Message Boards

Avoid confusion in Get[] or in Get's documentation

GROUPS:

The documentation for Get states:

Get[stream]: reads from a stream, evaluating each expression in it and returning the last one.

but Get doesn't actually do that (not for .m or .wl files, at least).

To cause Get to perform as documented, it's necessary to set all cells in a .m or .wl file as Initialization Cells, but this is not disclosed by the Mathematica documentation.

POSTED BY: Joe Donaldson
Answer
15 days ago

There is no such thing as a cell in an .m file. An .m file is a plain text file. Open it up with a text editor and look inside.

Cells exist only in rich-text notebook files, which cannot even be read by Get.

There is no bug.


In my previous answer to you I talked about how to automatically generate an .m file from a notebook file. There, I mentioned that only those cells will be exported to the .m file which are marked as initialization cells. This is probably what confused you.

POSTED BY: Szabolcs Horvát
Answer
15 days ago

There is no such thing as a cell in an .m file. An .m file is a plain text file. Open it up with a text editor and look inside.

Cells exist only in rich-text notebook files

Thanks for that clarification.

In my previous answer to you I talked about how to automatically generate an .m file from a notebook file. ... This is probably what confused you

I found your post about automatically generating an .m file to be clear, not confusing.

But your post isn't part of the documentation.

The documentation does not help new customers trying to learn how to evaluate each expression in a file. The current situation impedes the productivity of new customers. What's the point in doing that? To make us regret investing in Mathematica? I get the impression I arrived at Mathematica 20 years too late, and it's no longer intended for new customers. If someone asks me, which computer algebra systems have a clearly documented system for evaluating each expression in a file, I would have to answer, "all computer algebra systems I've seen, except for Mathematica". But it's like, that's not really a bug, because the business model at this time isn't much about getting or keeping new customers.

POSTED BY: Joe Donaldson
Answer
15 days ago

There is some documentation on this: AutoGeneratedPackage

As I remember (I may be wrong), earlier versions of Mathematica always offered to automatically create a package when saving a notebook with initialization files. There was definitely an easy-to-discover graphical way to do this. This functionality was phased out for some reason. Perhaps many people found it confusing. Thus today we need to do more work and go through less well documented avenues to make use of it.

I imagine it is very hard to balance the features so that they are sufficiently powerful yet not too difficult or confusing for newcomers. Wolfram definitely puts effort into making the system approachable. Think about features like natural language input, the suggestions bar, the uniquely excellent documentation, and the many available educational materials (multiple tutorials written by SW himself).

Actually, many of us think that by trying to cater to complete novices, Wolfram made decisions that are ultimately to the disadvantage of most other users. One example is dumping everything into the same namespace instead of structuring the system into packages. Another is the large number of new functions that could be trivially put together from a few building blocks ... but make the language feel cluttered and sometimes don't even perform as well as a trivial implementation (example: Downsample, whose performance was fixed recently). Yet another is providing very high level functions that try to do everything, and try to do it fully automatically, but not providing access to the individual underlying algorithms (or not documenting them sufficiently—see how Method options tend to be severely underdocumented). These are of course my personal opinions, but I know that there are many people who agree with the gist of them ...

The good things I observe are that:

  • Wolfram understand that Mathematica is a programming language and needs to remain a programming language. Some competitors tried to make their systems accessible with menu-and-button interfaces. Looking at the success and failure of other systems, at this point it is clear enough that Wolfram are taking the right approach.

  • They also understand that most users of Mathematica are not programmers, and try to cater to this audience. I think that currently there are more resources to learn Mathematica than ever before, and new users can get help very easily.

POSTED BY: Szabolcs Horvát
Answer
15 days ago

Wolfram definitely puts effort into making the system approachable.

In this case, they have spent their resources deleting the word "bug" from this thread's title, instead of spending those resources correcting the omission in their documentation.

POSTED BY: Joe Donaldson
Answer
13 days ago

Cells exist only in rich-text notebook files, which cannot even be read by Get.

Demonstration of non-cells in .wl files which Mathematica erroneously calls "cells":

enter image description here

POSTED BY: Joe Donaldson
Answer
12 days ago

Since you don't provide any specific example, it is difficult to understand where you are having trouble.

Get[myfile.wl]

or

Get[myfile.m]

behave exactly as documented on my installation (v11.1.1.0). As stated previously by Szabolcs, .m and .wl files are plain text. They don't have cells.

POSTED BY: David G
Answer
12 days ago

.m and .wl files... don't have cells.

Demonstration of non-cells in .wl files which Mathematica erroneously calls "cells":

enter image description here

POSTED BY: Joe Donaldson
Answer
12 days ago

Most of this is a blizzard of confusion thrown at a new user.

Mathematica is not just a programming language. A much better paradigm is that it's a piece of paper, or medium, on which you can write and do mathematics. A very special medium because of its active and dynamic capabilities. Capable for not only doing calculations, but for building capability and the best communication medium of all. And not that difficult to use if new users are not always led up blind alleys.

The statement that .m and .wl files do not have cells is totally misleading. A Mathematica notebook at its most basic level is also a text file, But that is not the level at which most users should or would interact with it. All of these files, .nb., .m, .wl, do have cells. A .m file has a Title cell, (sub)Section cells, Text cells, initialized Code cells and uninitialized code cells where you could retain some old versions of code.

It's easy. Why all this confusion for new and some old users?

POSTED BY: David J M Park Jr
Answer
12 days ago

While it is true that a notebook is also a plain text file, the frontend interprets a notebook file differently than a package file. A package could be interpreted by the kernel at the command line without a frontend. No cells (Cell[...]) required. It seems to me that the context of the OP is with regard to using Get to read a file and define some functions/variables/etc (ie, like a package). This requires no cells or notebooks. It is misleading to say that a package file (.m or .wl) has cells.

POSTED BY: David G
Answer
12 days ago

It is misleading to say that a package file (.m or .wl) has cells.

Demonstration of non-cells in .wl files which Mathematica misleadingly calls "cells":

enter image description here

POSTED BY: Joe Donaldson
Answer
12 days ago

It is NOT a demonstration of a non-cell mistakenly called a cell. It is a Mathematica cell. It has a cell bracket. It has cell properties. What is a non-cell? Are you being ironic? This is all nothing but a confusing diversion from doing math.

I created a test package file (.m) called JoeTest.m and put it at the top level in one of my existing applications (GrassmannCalculus.) I added a statement:

a^2 + b^2 == c^2

which automatically became an Initialization CELL.

I then started a new notebook (.nb). and evaluated

<< GrassmannCalculus`JoeTest`

and it generated the Output cell:

a^2 + b^2 == c^2

So what's the problem?

POSTED BY: David J M Park Jr
Answer
12 days ago

It is a Mathematica cell. It has a cell bracket. It has cell properties. What is a non-cell?

The image I posted was in direct reply to 2 people asserting that .wl files contain no cells. That is logically equivalent to asserting that everything in a .wl file is a non-cell.

Are you being ironic?

When in Rome do as the Romans do, and this community is insisting that those things you and Mathematica call "cells" aren't really "cells". This community would rather make bizarre claims about "cells" than face the substance of this thread's original post.

This is all nothing but a confusing diversion from doing math.

It started as a straightforward bug-report. Bug-reports are not a plot to divert you from doing math. They're an everyday, integral part of the software-development process. Other communities respond to such bug-reports by straightforwardly fixing the reported bugs.

POSTED BY: Joe Donaldson
Answer
11 days ago

When you open a .m or .wl as a notebook in the front end, it will look a lot like a notebook (a fundamental feature of notebooks is the concept of "cells"). But, that doesn't make it notebook (ie, a file with a .nb extension). In the case of .m/.wl, the front end is simply displaying the file contents as one or more cells. This is done so that .m/.wl files can be edited in the front end, just like notebooks. But, when that file is saved, all those cell expressions are stripped from the contents. This is somewhat analogous to the way an .html file is displayed by a web browser. If you open an .html file in a text editor, it won't look much like the same file in a web browser. The same applies to how the Mathematica front end handles .m/.wl files. Mathematica also handles notebook files (.nb) in a similar way. In plain text, notebooks have cell expressions of the form Cell[...]. However, .m/.wl will not have Cell[...] expressions. It is easy to see this by opening .m/.wl/.nb files in a text editor. This is not a bug. Hopefully, you will be able to do some research in the Documentation. Much of this is explained there. Good luck.

POSTED BY: David G
Answer
11 days ago

.m/.wl will not have Cell[...] expressions

But those text files still will reflect whether or not you (while editing in the front-end) set cells as Initialization Cells.

You can confirm this yourself by opening .m/.wl files in a text editor. First create a new .wl file in the font-end, set its cells as not-Initialization-Cells. Save it and view in a text editor. Now back in the front-end, modify the cells so that they are Initialization-Cells. Save it again, and view it again in a text-editor. It makes a difference, and that difference is what I described in the original post:

To cause Get to perform as documented, it's necessary to set all cells in a .m or .wl file as Initialization Cells, but this is not disclosed by the Mathematica documentation.

Then you tell me:

Hopefully, you will be able to do some research in the Documentation. Much of this is explained there.

And I likewise hope you will be able to do some research in the Documentation, and if you do that, you will see what Wolfram discloses about the importance of the Initialization-Cell setting while editing .wl files using the font-end:

http://reference.wolfram.com/language/ref/menuitem/SaveAs.html

Wolfram discloses nothing about the importance of the Initialization-Cell setting while editing .wl files using the font-end. It is an undocumented secret concealed from new customers. It is a misleading deficiency in the documentation. You are saying the emperor's clothes look great, when they really do not look great. You have the luxury that your livelihood doesn't depend on the quality of the Mathematica documentation, but Wolfram employees don't share that luxury. Deficient documentation, if it persists, will hurt sales.

POSTED BY: Joe Donaldson
Answer
11 days ago

It does exist. It is on the page (last paragraph): Naming and Finding Files.

It is also on the page (implied by the subtitle "Packages from Notebooks" followed by Initialization Cell...):

Package Development -> Packages from Notebooks

Finally, if you select File->New->Package (.wl) and then starting typing anything, the cell displayed by the front end will automatically be shown as an Initialization Cell. Note that .m extensions are being deprecated, but still valid. There is no reason to change the cell properties it if you want to save the file as a .wl/.m file. But, there is nothing that is stopping you if you so choose, it depends on your workflow. But, If you change it, then the front end will not save the contents as Wolfram Language "Code". I believe this have been part of Mathematica since version 6. I'm not saying that the Docs couldn't be improved... almost all software docs could be improved. But, this particular feature is not undocumented/hidden.

POSTED BY: David G
Answer
10 days ago

It does exist. It is on the page... It is also on the page....

Cool story.

this particular feature is not undocumented/hidden.

Cool story.

almost all software docs could be improved

I'll leave you to defending software-bugs, and if Wolfram believes their documentation will compete well in the market as is, I'll leave them to that.

POSTED BY: Joe Donaldson
Answer
10 days ago

Group Abstract Group Abstract