for example ,
"MainFunction[ x] computes a simple function."
MainFunction[ x_] :=
y = x^2;
y + 1
i don't know how to display the line number in a mathematica's .m file. Thank you in advance!
you shouldn't need to? :)
you can use mathematica's developers tools. some are built in. one is a separate product.
did you find Trace in Help? that should lead you to other (tutorial and such). you'll probably find out you don't "need" a list of lines with line numbers if you work in suggested manners
also there is a way (a notebook with methods that) split normal functions in to lines so one can debug and edit by line, then re-constitute the lines back into a function automatically when done: but it's a niche hit, i don't think many would be interested
I rarely edit a Mathematica package file using Mathematica, but instead edit them in Eclipse with the workbench plugin. See here for more information about using Eclipse.
Showing line numbers by default in Eclipse is a simple setting to change.
I see，thank you very much!
Mathematica has an editor that's great for working on ... Math. Mathematica automatically saves Notebooks as "Packages". I don't think switching to a "free editor" to gain line numbers is what most people would consider "an advantage" but rather a loss of being limited to a line editor front end.
I disagree "eclipse' shows "line numbers". Eclipse doesn't know how Mathematica Kernel labels lines and former Input numbers.
"Wolfram Workbench: Eclipse-based IDE for the Wolfram Language", requires one has "wolfram workbench" which includes an "eclipse plugin". But i mentioned wolfram has separate developer front end to find above.
I would also warn that "IDEs" have an issue. You have to specify your project in "it's click language" and if changes are made you must "import" or loose your whole effort. Old project files often cannot be shared with others - who have a different version of the IDE.
I wouldn't say do not use x-code for developing iPhone apps I'd say it's the only good choice.
But I would say don't use a programming IDE (if you are not building a huge interface) without thinking through if it will really benefit you. For example "workbench" says jlink is included: but web things and jlink can be done with a normal notebook: workbench isn't needed to use jlink. workbench has debugging (but see Trace, mathematica has some debugging): however computer classes teach to avoid lengthy bouts with bug chasing: it's worth the time to insure you have no bugs and work in a way small oversights are easily known and resolved before they become a "problem".
There are a host of advantages to using an integrated development environment when working with packages, showing line number is just one of them. If the notebook satisfies all of your needs then that's great.
But many people choose to write their Wolfram Language code in another editor, and have written great plugins for those editors. See the list here: https://arnoudbuzing.github.io/wolfram/editors.html
A Mathematica package file, .m or .wl, can easily be opened in a text editor. Which can display the line numbers. The picture below is from using UltraEdit.
A Mathematica package file, .m or .wl, can easily be opened in a standard text editor. Which can display the line numbers. The picture below is from using UltraEdit.
I have never required line numbers while programming Mathematica EXCEPT in one particular important case: when writing a package in a notebook that then gets converted to a '.m' file (which is plaintext). If one makes some sort of syntax error like an extra comma or such, then when one goes to load the package there will be an error message about the syntax error, and the package will fail to load. Unfortunately, however, there is no mention of where in your package the error might actually be. If one has a large package then this clearly becomes an issue.
There is a workaround, however. Parallel kernels do have some magic ability to tell one the exact line number where syntax errors occur. If one does e.g.:
then each and every one of the kernels will return a message with the line number of your error.
It would, of course, be nice if this were just the default behavior without having to do this workaround.
I feel quite comfortable to work with Mathematica package with Visual Studio code. There are several add-ons in vs code to show syntax highlighting and function name detection.