Reputation: 843
I now know how to use the APL interpreter, but I'm quite confused about how to write APL into a file and then run the said file. I currently write Dyalog APL using RIDE. What I now want to do is to:
Most of the documentation online refers to an "APL session", which makes me think that perhaps there's some Smalltalk-like thing going one, where one can only distribute the "live image" or some such. If that is the case, I have a different set of questions:
In general, I'm quite confused about how to write software in APL!
I'm on Ubuntu, and I'd like to target Linux in general. Windows/macOS support would be a plus, but I'm currently interested in Linux support.
Upvotes: 5
Views: 2171
Reputation: 7616
For now, the ability to create a stand-alone executable (a single .exe file) only exists on Windows, but Dyalog is working on making this possible cross platform. However, you can get pretty close. Before we get to that, let me answer your initial questions:
- Use the ride IDE to develop programs (how else do I access the keybindings?).
There are several convenient ways to enter the glyphs outside RIDE, both through editor extensions and separate system-wide methods for prefix and/or shifting key input. For details, have a look at APL Wiki's article on typing glyphs.
- Run the program from the command line, with command line arguments (how do I take command line arguments?)
⊢2⎕NQ#'GetCommandLineArgs'
returns the command and the arguments to the command that was used to start the current application. This works cross-platform. Try it online under Linux!
The "live image" you talk about would be what APLers call a workspace. Once your application is working as you want, enter set the ⎕LX
(Latent eXpression) variable to a statement that starts your application and then closes APL when done, e.g. ⎕LX←'myApp.Run ⋄ ⎕OFF'
.
Next, save your application as a workspace with )save /tmp/myapp
.
You should now be able to run your application with dyalog -hello=world /tmp/myapp
etc. You can of course put this in a shell script for ease of use.
What you'll distribute to your customers would at a minimum be the workspace and the runtime interpreter, but you probably want to package some companion files/dependencies too. However, before making money off your application, look at Dyalog's prices and Licences.
Upvotes: 5
Reputation: 7882
This is how I do it (not an official Dyalog recommendation):
Use the ride IDE to develop programs (how else do I access the keybindings?).
RIDE is cool (I'm biased), especially in the beginning when you want to explore the language interactively.
But in practice I prefer to edit plain text files with Vim with this plugin. It provides keybindings with a configurable prefix key. I think there's also a way to configure Vim or Emacs as an external editor for RIDE - that way you could have both the shiny session interface and the brutally efficient editor familiar to your fingers.
Alternatively, for the keybindings you could do:
setxkbmap -layout us,apl -option grp:win_switch
Pressing the "Windows key" and another key together inserts an APL char in any X11 app - convenient for email, chat, etc.
Save my program to a file. Run the program from the command line,
I put this on top:
#!/bin/bash
(echo ∇M;tail -n+3 $0;echo -e '∇\nM\n⎕off')|dyalog -script;exit $?
⎕io←0⋄⎕ct←0⋄⎕pw←32767 ⍝ opinionated :)
and do
chmod +x file.dyalog
./file.dyalog
with command line arguments (how do I take command line arguments?)
That's a bit of a problem. There's 2⎕NQ#'GetCommandLineArgs'
for Windows but no working solution I'm aware of for Linux.
See the comments below and Adám's answer.
Distribute my program so others can use them.
Any way you like - github, gitlab, bitbucket, your own site, pigeons, etc
"APL session"
That's just the traditional APL term for "REPL".
Upvotes: 3