Process-palette and Mathematica

Hello !
This message refers to:

  • Windows 10.0.17763.107
  • Atom 1.55.0 x64
  • Package Process-palette

I’m a newcomer about Atom: may be my question can sound a bit rudimentary to you.

I’m trying to use Atom to program in Mathematica.

(1)

I have an “Hello world!” file (“file-12.m”) working in Mathematica’s FrontEnd.
It prints a string, asks user for a new one and print the latter uppercase.

Print[ "Hello world Mathematica !" ];
var = InputString[ "input a string: " ];
Print @ OutputForm @ StringJoin @ { "Your input uppercased: ", ToUpperCase @ var };

(2)

It’s also ok fire it from a batch file (“file-12.bat”), calling the Mathematica’s computational engine (“the kernel”) wihitout the Mathematica’s Front End.

@echo off
cls
"c:\Program Files\Wolfram Research\Mathematica\9.0.1.0\math.exe" -script "c:\Atom-test-docs\projects\file-12.m"
pause

(3)

Despite of many efforts I can’t make it work properly with Process-palette, basically because it print the first string and get stuck (as far as I can see: may be I’m badly wrong, as I said I’m a newbie about Atom).

Not even calling the interpreter (cmd.exe) and passing to it {fileabspath} as command saves the day

cmd.exe /c "{fileabspath}"

(4)

Any suggestion will be very appreciated. Thanks in advances !

Helen

P.S.
In case you wonder what makes me prefer coding using Atom rather than Mathematica, the point is
that Mathematica’s FrontEnd is an highly customizable and really satisfactory editor for notebook (.nb files), but
when it comes to packages (.m files) it looks ugly. For a long time it wasn’t a concern, but recentely I have developed some visual
impairment and the “gray-over-gray” look of packages editor reveals uncomfortable to me.

Take note that in Settings the exact syntax of Atom variables (upper and lower case characters) should be used …

Your example is incorrect …
cmd.exe /c “{fileabspath}”

There is a button to the right of the command field allowing the builtin syntax to be used as snippets.

I am on Ubuntu so I cannot comment on your Windows example.

image

[P.S.] I do have Wolfram command line installed although it is dormant.
I plan to use this for evaluation of some equations, using process-palette.

Another tip. You can pass all the Atom variables as args to an external python script through just one custom command and then fan out using the args to build your own link between Atom and Mathematica. This way you need only get one custom command to work and let the external python script interface with Mathematica using subprocess to run the commands. I have a proxy script which does this and for example I can pass variables to VSCode (I wrote this up in an earlier thread … search for "Atom and VSCode in tandem" In your case it will be “Atom and Mathematica in tandem”. Same principle applies to other external tools and IDES, where Atom is part of a tool chain.

Further reference on Mathematica via command line (such as process-palette or intermediate python script) found here.

Hi !

i’m so sorry: my post is mistyped, the command in process-palette contains {fileAbsPath} as it is supposed to do.
[PS]
I have always used Mathematica so I don’t know Wolfram command line.
In case it presents any limitations, fell free to send me your code (obviously, not obfuscated) and I will execute for you.

In Windows I don’t believe that you write cmd.exe (with extension) … it should be written simply as

cmd MathKernel {fileAbsPath}

For example In Ubuntu here are some sample commands I have written … (no cmd prefix is required, since I am in Ubuntu)

Alternatively you can try powershell (ps) instead of cmd.

This command runs Atom editor file as Python
python3 -u {fileAbsPath}

This command runs R file:-
Rscript {fileAbsPath}

This command runs Lua file:-
lua {fileAbsPath}

This command applies PHP to a file and pipes result to a file:
php -f {fileAbsPath} > output.md

This command passes all Atom variables to an external python script for application in external IDE’s.:

cd ~/.atom-scripts/ && python3 Atom-argparse.py {clipboard} {fullCommand} {fileExt} {fileName} {fileNameExt} {filePath} {fileDirPath} {fileDirAbsPath} {fileProjectPath}

Meanwhile if you can experiment with Actiona to build up automation scripts … such Actiona scripts (similar to AutoIT) can be launched from Atom as

actexec {fileDirPath}/myscript.ascr

or in Windows (I guess here)

cmd actexec {fileDirPath}\myscript.ascr

Now it is working this way:

  • No cmd is required.
  • It’s necessary call MathKernel.exe, no Math.exe as I did before.
  • The command line must cointain the argument -script

Putting all togheter:

“c:\Program Files\Wolfram Research\Mathematica\9.0.1.0\MathKernel.exe” -script {fileAbsPath}

It correctly asks for the user input. But InputString function doesn’e show its argument as prompt. I think it’s inevitable because this task requires the graphical capapibilities 0f the Front End.

About your tip ragarding the intermediate python script. Do you mean something similar to passing
Atom variables to a batch script as argument (%1, etc,) or are you suggesting a more advanced processing ? The subject is intriguing because can be seen the possibility to comminicate with an already running Mathematica code, rather simply launch it. Am I wrong?

I think that you now have the general idea that you can use Atom as a “choreographer” of external processes, including “driving” external IDE’s and programs. process-palette is your connector.

Atom and Mathematica can share the same files.

But also you can, from within Atom, send commands to services such as webMathematica. I suggest webMathematica since Mathematica as a kernel only runs on Windows, and I am on Ubuntu.

Atom can send through an automation script (I suggested one such utility earlier) to drive the webMathematica user interface - through the browser. Thus you might copy into clipboard, within Atom, and pass control to webMathematica. It is a powerful concept. I have found such automation scripting tools which can work across Windows/Linux/Mac but my focus is on Ubuntu.

Also explore wolframscript which is entirely through command line, this being ideal for process-palette usage. But there are so many Wolfram commands I found it much easier to pass all the Atom variables as args to a python script and then call a popup dialogue in Actiona utility so that I can choose the Wolfram command to run - external to Atom.

If you must stay with MathKernel in the desktop then the same principles apply. The Mathematica UI is driven by an intermediate automation script wolfram.ascr sitting between Atom and MathKernel IDE.

Actually on studying the API deeper I see that it is much easier to leverage wolframscript thorough process-palette commands. Wolfram script automatically runs kernel if it is installed.

Example of commands

wolframscript -code ‘$SystemID’

wolframscript -cloud -code ‘$SystemID’

The first script runs code in MathKernel the second runs in the cloud if MathKernel is not installed.

I’m really grateful to you for sharing your remarkable skill. I’m meditating on your hints.

(1)

“I suggest webMathematica since Mathematica as a kernel …”

Do you mean “Here I mention webMathematica (just) because … I am on Ubuntu.” or something like “I advise using webMathematica as preferable options” ? I’m confused about that because below you say "Actually on studying the API deeper I see that it is much easier to leverage wolframscript ".

(2)
You cite Actiona. Do you refer to GitHub - Jmgr/actiona: Cross-platform automation tool ?

(3)
By “Mathematica UI” you intend Mathematica’s FrontEnd, do you ?

(4)

“… intermediate automation script wolfram.ascr sitting between Atom and MathKernel IDE.”

Is any example available ?

(5)
If I understand precisely, a developer can, in principle, aim the marriage Atom - Mathematica toward three different goals:

  1. To use Atom as a sort of user interface for Mathematica programs.
  2. To use Atom as “choreographer”, as you said, to make Mathematica dialog with other applications
  3. To use Atom as and advanced, smart, editor for coding in Mathematica, endowed with language specific features, and capable of, as example,

At present moment I’m mainly focused on

  1. fine tuning syntax highlighting (because of some limitation of my vision) and
  2. what is present in point (3) above.

Can you, please,

  • provide a basic comparision of capabilities of Atom /Wolfram Language PLugin by JetBrains / Wolfram Workbench plugin for Eclipse
  • mention general purpose coding helper Atom’s packages easily adaptable to Wolfram Language ?

There is a lot to respond to.

But perhaps the most important consideration is accessibility - your reduced vision.

If you run the command

apm list

you see the list of Atom packages installed (Core and Community sets).

You can experiment with dark themes which might be better than light themes.

Investigate tweaking styles.less to change environment such as font size, colours. Edit > Stylesheet.

==================================

Now we turn to Mathematica.

I have a number of development experiments underway, using Atom at the core. Mathematica is on my “to do list” and I had already installed wolframscript. Currently I am studying workflows integrating Julia + R + Jupyter Notebooks.

But I can break off this for a while and look at Mathematica. I will be using Mathematica later in my project plans, so it helps my own thinking.

I have explained that I am on Ubuntu 20.04 and so my workflow will differ from Windows. But the same principles apply.

Principle explained so far:

Atom can be part of an engine of microservices.

My view is - dispense with the idea that Atom should be a “one stop shop hackable editor”. Instead, Atom can be part of an ecosystem where other tools and microservices interact - through process-palette as the connector.

Atom can be the primary editor of resources, but editorial control over any file might be passed to another cooperating microservice (desktop or cloud).

I already apply this thinking in interacting with IntelliJ IDEA. But for Java rather than Mathematica. I have now installed the extensions for Mathematica and Wolfram Language. However they require subscription accounts.

We can consider how to connect Atom to IntelliJ IDEA. I have no plans so far to use Eclipse. I have also tried NetBeans.

Using common resources

Thus we start with shared folders and files and assets. This can be in Github or in project folders. They might be in Dropbox folder if shared with cloud based services such as webMathematica.

We might start editing a file in Atom but then pass control to an IDE such as IntelliJ IDEA. These two worlds - Atom and IntelliJ IDEA - do provide a considerable degree of overlap of functionality. But the principle of collaborative working - considering these IDE’s as microservices - can work well. We can even pass control from Atom to VSCode.

The small utility I suggested - Actiona - acts as an important helper in the automation.

Tip: Using Actiona script, Atom and other IDE’s might be arranged to appear in different desktop virtual workspaces. This makes it easier to toggle between these desktop virtual workspaces.

I suggest that you first install Actiona as I proposed. Then when you have done this, confirm back here, and I can follow up later with workflows as scripts.

Regarding suggestions on the list of Atom packages to support Wolfram Language, you might leverage packages for autocompletion (emmet) and adding snippets of Wolfram code.

Search “wolfram” in packages to review packages to try.

One advantage of passing automation scripts between cooperating users (remote team members) is that you apply these to your real instance of Atom/Mathematica/IntelliJ. This is an improvement over squinting at screencasts in YouTube. Of course the source of such scripts (executable bots) should be trusted since they have potential to cause damage if applied without thinking. Less risk if you develop your own automation scripts using the GUI.

A further step.

Install Atom package language-mathematica
Apply command Window:Reload to refresh Atom instance.
Create a project file test.wl
In bottom status bar we see Mathematica as file type
Type typical Wolfram syntax.
It should autocomplete.

Reference

Hi !

Sorry for being late in answering, but It’s because I read through your inspiring post and I have been pondering on it.

  • I have installed Actiona and I like it a lot: powerful yet simple. I’m sure i will make use of it.
  • Of course, I have installed Atom’s packages related to Mathematica, also.
  • If you want to share folders with me, I propose Dropbox. Unfortunately , I have always pushed back learning to use Github; if you consider enough basic functionalities that I can quickly learn I will open an account on Github.
  • Surely because I lack the required the expertise (refactoring, metaprogramming, … ), I still feel like I couldn’t truly grasp the big picture.

If I may, I would shift, for a moment, the focus from the tools to the job the are supposed to do.


What I’m working on is:

  1. How can I get rid of boilerplate Mathematica code ?
  2. How far can I push the concept of “programming by means of code description / documentation” rather than “programming by means of direct coding” ?

Two themes strictly entwined. As an example, until today when I write a function I have to explicitly take care of

  • What happens if, by mistake, no argoment are supplied to it ?
  • What happens if, by mistake, too few arguments are supplied to it ?
  • What happens if, by mistake, too many arguments are supplied to it ?
  • What happens if, by mistake, a right number of arguments is supplied to it, but some have wrong Head ?
  • What happens if, by mistake, a right number of arguments is supplied to it, but some are outside the range ?
  • Should the function throw an exception when the first argument fails the pertinent check or should it return a complete report on them all ?
  • Should the whole code be wrapped in a Catch function or only its most risky parts ?
  • Should the function check if the value it is going to return is correct respect Head and range ?

Furthermore, just to mention a few, even more boring, I must:

  • Write error messages one by one and ascertain that they conform the standard I have adopted
"ERROR: timestamped_unique_message_id: functionName:  topic: message: details"

namely something like

errorMessage = To String @ StringForm[ "ERROR: 20210314150918: readDataFromFile:  topic: 
Wrong argument Head: Required: String, found: `1`", Head @ fileIn ]
  • manage the dubugMode (Boolean) and the debugLevel (an Integer)
  • manage the logging process and adjust it for the development or debugging or deployment.

Until today I had at my disposal two only tools: Mathematica itself and XML. The core concept is to code writing XML descriptor, more or less, like

<functionName>
<logging>
  ...  
  <verbose></verbose>
  ...
</logging>
  <arguments>
    <argument>
      <argumentName></argumentName>
      <argumentHead></argumentHead>
      <argumentRange></argumentRange>
      <argumentDescription></argumentDescription>
    </argument>
    <argument>
      <argumentName></argumentName>
      <argumentHead></argumentHead>
      <argumentRange></argumentRange>
      <argumentDescription></argumentDescription>
    </argument>
  </arguments>

...

</functionName>

and “compiling” them in real Mathematica code.

It shouldn’t reveal rocket science I hope, but now I think that the process requires more than Mathematica and an XML editor, to be maneuverable. A CLI tool could perform the “compilation” and diagnostic. And even generate visual appealing HTML/CSS report.

The question is: what role can we imagine for the editor in all that ?
Puppet master, or “typing sparer”, sounds kind of restrictive, albeit extremely useful.

This discussion has moved on beyond the scope of applying process-palette to drive Actiona and thence Mathematica

I am still unsure about your project goals:

  • to learn Mathematica?

  • to tutor other Mathematica learners?

  • to develop a Mathematica testing framework?

  • to develop a front end compiler/generator of Mathematica code?

  • to generate HTML reports using Mathematica results?

Can you please summarise your goals?

And you pose the question what does Atom contribute to this landscape? Remember that Atom’s description on the can is “hackable text editor” and so it must collaborate with other systems/processes/compilers/services.

Now the tools and workflow I suggested will take you part way.

I have not taken the step of actually subscribing to Mathematica (until I need it). But I can go a long way in passing resources to Mathematica from Atom. The final step of receiving images and embedding into HTML/CSS must wait.

I would ask if are you planning to go beyond the capabilities of Jupyter Notebooks?

Now on the matter of writing a front end to generate Mathematica code, this can be started in Atom. You mention XML without giving reasons for adopting this. But I do something similar for other external tools which adopt XML structure.

I use PHP server with PHP in Atom to generate XML code.
If you study Actiona *.ascr it is in fact XML format.

So you can, in Atom, develop a PHP front end dialogue to compose Mathematica expressions which are then passed to the Wolfram Kernel.

Atom → PHP code → PHP server → generate XML code → generate Wolfram code → process-palette → Actiona → Mathematica Kernel → results to shared files

Given time I will experiment with this workflow (just a few examples).

The valid point you make about testing will be covered by integrating with Mathematica Testing Framework. See references below.

Reference 1

Reference 2

Reference 3

============================

[P.S.] The possibility of using Pandoc was also followed up.

The author of Pandoc writes at end of that thread that Wolfram format is proprietary but there is no reason why the steps outlined could not be tested. Pandoc integrates nicely in Atom. See markdown-preview-enhanced.

I agree. Are private messages allowed on this platform ?

image<------- click
If you click on my ico at top left of this post you can send messages by email …