Message Boards Message Boards

Display the line number in a mathematica package?

Posted 5 years ago

for example ,

BeginPackage[ "Package`"]

  MainFunction::usage = 
    "MainFunction[ x] computes a simple function."

  Begin[ "Private`"]

  MainFunction[ x_] :=
    Module[ {y},
      y = x^2;
      y + 1
    ]

  End[]

  EndPackage[]

i don't know how to display the line number in a mathematica's .m file. Thank you in advance!

POSTED BY: zhu xiaoming
10 Replies

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.

POSTED BY: Shenghui Yang
Posted 5 years ago

Nice to meet you. I have a question about wolfram workbench. I want to talk to you in private. My email address is 1262043385@qq.com

POSTED BY: zhu xiaoming
Posted 5 years ago

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.:

ParallelEvaluate[Needs["myPackage.m"]]

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.

B

POSTED BY: Bernard Gress
Posted 5 years ago

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.

enter image description here

POSTED BY: Hans Milton
Posted 5 years ago

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.

enter image description here

POSTED BY: Hans Milton
Anonymous User
Anonymous User
Posted 5 years ago

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".

POSTED BY: Anonymous User

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

POSTED BY: Jason Biggs

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.

POSTED BY: Jason Biggs
Posted 5 years ago

I see?thank you very much!

POSTED BY: zhu xiaoming
Anonymous User
Anonymous User
Posted 5 years ago

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

POSTED BY: Anonymous User
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