3

I am trying to learn APL (both APL in general and Dyalog APL, which seems to be actively under development and in use here in Stockholm).

When doing so, I have observed, in my Ubuntu Linux environment, that dyalog (in fact a file called mapl, which is reached through a symbolic link named /usr/bin/dyalog) seems to be behave differently when having stdin associated with a pipe or open disk file instead of the terminal driver.

It seems that the interpreter no longer understands ]DISPLAY when I replace my terminal driver with a pipe as standard input.

Here the ]DISPLAY command/function seems to work :

Command: dyalog without arguments or stdin redirection :

Dyalog APL/S-64 Version 16.0.30320
Unicode Edition
Mon Aug 14 19:27:14 2017
      ]DISPLAY 42

42

Here, the interpreter seems to be confused about ]DISPLAY :

root@lenovo201707:/home/u/20170814# ( echo "]DISPLAY 42" ; echo ")off" ) |         dyalog
Dyalog APL/S-64 Version 16.0.30320 Unicode
For i86_64
Created: Jul  7 2017 at 02:48:48
Copyright (c) Dyalog Limited 1982-2017
      ]DISPLAY 42

VALUE ERROR
root@lenovo201707:/home/u/20170814# 

Is there a simple way to not lose the ]DISPLAY function when loading and executing my APL code from an existing UTF-8 encoded file ?

Best regards ! Hans Davidsson

Lobachevsky
  • 1,222
  • 9
  • 17
Harley
  • 83
  • 7
  • My problem is now solved. ( echo "{s←⎕NS ⍬ ⋄ 6::_←s.enableSALT ⋄ ⊢s.⎕CY'salt'}⍬" ; echo "]DISPLAY ,42" ; echo ")off" ) | dyalog -script is the trick. Both the "{s←⎕NS ⍬ ⋄ 6::_←s.enableSALT ⋄ ⊢s.⎕CY'salt'}⍬" part and the "-script" option to the dyalog command was needed (creds to Adám). I still, however, have much to learn about APL namespaces and more. – Harley Aug 24 '17 at 16:08
  • I realized that -script is also turning off the replication of commands (for example APL code) from stdin to stdout, But I can live with that. :) – Harley Aug 24 '17 at 16:30
  • I now also found that MBaas (Thanks !) solved the problem in an easy way, several days ago by only adding a workspace specification, "salt", to the "dyalog" command. That seems to be an even better solution for me just now. – Harley Aug 26 '17 at 07:11
  • could you please accept one of the answers (click the checkmark left to it), so that the question is no longer shown as !open"? – MBaas Aug 26 '17 at 11:31

2 Answers2

2

Updated answer: the following should solve your request:

( echo "]DISPLAY 42" ; echo ")off" ) |  /opt/mdyalog/16.0/64/unicode/mapl salt  

The only detail that has changed is that we're now loading the salt-workspace before attempting to execute the UCMD. SALT will (through its ⎕LX) set up the environment so that it can handle UCMDs.

My initial reply: I'm a Windows-User and must admit that I never worked with Linux Pipes, so I can't help with the general mechanism.

But I have an answer for the specific question re. ]DISPLAY: you may call any UCMD under program control using ⎕se.UCMD'{ucmd & args}', so for example: ⎕se.UCMD'DISPLAY ⍳3 3'

BTW, I personally call ⎕se.Dyalog.Utils.disp MyVar which avoids the UCMD-Mechanism and is even easier to use when calling from a fn.

MBaas
  • 7,248
  • 6
  • 44
  • 61
  • Thanks fir the answer, but it seems that< it did not help in my case: – Harley Aug 16 '17 at 22:04
  • Thanks fir the answer, but it seems that< it did not help in my case: u@lenovo201707:/tmp$ ( echo "MyVar ← ((1 2 3) (4 5 6))" ; echo "MyVar" ; echo "⎕se.Dyalog.Utils.disp MyVar" ; echo ")off" ) | dyalog Dyalog APL/S-64 Version 16.0.30320 Unicode For i86_64 Created: Jul 7 2017 at 02:48:48 Copyright (c) Dyalog Limited 1982-2017 MyVar ← ((1 2 3) (4 5 6)) MyVar 1 2 3 4 5 6 ⎕se.Dyalog.Utils.disp MyVar VALUE ERROR ⎕SE.Dyalog.Utils.disp MyVar ∧ u@lenovo201707:/tmp$ – Harley Aug 16 '17 at 22:10
  • Sorry for bad formatting. I am not yet a friend of the editor in Stackoverflow. There seems to be different formatting rules when writing comments – Harley Aug 16 '17 at 22:16
  • It, however, works well when starting an interactive dyalog process and pasting the code in: Dyalog APL/S-64 Version 16.0.30320 Unicode Edition Thu Aug 17 00:13:16 2017 MyVar ← ((1 2 3) (4 5 6)) ⎕se.Dyalog.Utils.disp MyVar ┌→────┬─────┐ │1 2 3│4 5 6│ └~───→┴~───→┘ MyVar 1 2 3 4 5 6 – Harley Aug 16 '17 at 22:22
  • Ok - so it seems the interpreter does not set up the UCMD-Enviroment for redirected sessions. I'll check that and will try to get an answer... – MBaas Aug 17 '17 at 05:08
  • Thanks MBaas ! That updated answer works very well. It seems that there are a workspace, named salt, that contains the optimal starting state for my interpreter, for my purposes, even when piping the commands/code in. In contrast to alternative solutions, like using the "-script" option and enabling salt by the initial commands in the pipe, this also keeps the replication of the interpreters input to the output, which is good for readability of the results when I play around with APL. – Harley Aug 26 '17 at 07:07
  • Yes, the salt-workspace which is loaded through this slight modification enables the UCMDs, so that `]display` is available. – MBaas Aug 26 '17 at 07:11
2

Note: Click any of the code lines below to try it on the Try it Online website. That service pipes the content of its Input text field (which the links will populate with the appropriate code) into a Linux APL, and so is completely analogous to your environment.


Dyalog APL does not populate ⎕SE when running scripted (e.g. receiving piped input). If you just want the display functionality, you can copy the equivalent as a utility from dfns:

'display'⎕CY'dfns'

However, this still forces you to use a full namespace path to call display from other namespaces than #. To actually have user commands available, you have to enable SALT manually:

⎕CY'salt' ⋄ enableSALT

To avoid cluttering your workspace and session, you can do use this dfn:

{s←⎕NS ⍬ ⋄ 6::_←s.enableSALT ⋄ ⊢s.⎕CY'salt'}⍬

Adám
  • 6,573
  • 20
  • 37
  • @Harley I'm not sure under what circumstances you get a domain error. If you click the code line, you can see the result of it running on a real APL system. – Adám Aug 21 '17 at 18:13
  • Thnx! "'display'⎕CY'dfns'" seems to be a hit, but your 2nd example line, resulted in a DOMAIN ERROR, when piped in: ⎕CY'salt' ⋄ enableSALT DOMAIN ERROR enableSALT[3] ed←'⎕SE'⎕WG'Editor' ⋄ ed.⎕WX←3 ⋄ ev←↑ed.Event,⊂'onFix' 0 ∧ I guess that I may have installed a different version than that used on tio.run, or I may have failed to complete the installation with proper configuration. My good workaround seems to be to frame my experimental code between a "'display'⎕CY'dfns'" line and an ending ")off" and using "display" instead of "]DISPLAY". Many thanks ! – Harley Aug 21 '17 at 18:58
  • It is like the piped scenario is not makeing it possible for the interpreter to load and/or use SALT, while the interactive one seems to complain with "SALT is already enabled!", when I give a "⎕CY'salt' ⋄ enableSALT" command. – Harley Aug 21 '17 at 19:07
  • @Harley That doesn't sound right. TIO is piped and SALT loads fine. Which version number are you using? And are you piping into `dyalog.exe` or `dyalogrt.exe`? Also, are you using Classic or Unicode? – Adám Aug 21 '17 at 19:12
  • linux_64_16.0.30320_unicode.zip piping into /usr/bin/dyalog which is through a couple of symbolic links pointing to the script with absolute path "/opt/mdyalog/16.0/64/unicode/mapl". I am using the Unicode version. I installed from the zip file mentioned above, or from the "linux_64_16.0.30320_unicode.x86_64.deb" file inside it to be more precise. I am using Ubuntu 16.04.2 LTS and I also have GNU APL installed on the same computer. – Harley Aug 21 '17 at 20:09
  • @Harley OK, that's fine. Could it be that `/opt/mdyalog/16.0/64/unicode/ws/` is not in your path? Run `printenv` and see if `WSPATH=/opt/mdyalog/16.0/64/unicode/ws` is on the list. – Adám Aug 21 '17 at 20:13
  • Could we be sure that the version on TIO is not putting some extra commands at the beginning of the pipe or is using some command line options to load SALT (which is a tool that I have not yet tried to learn about how it is used). – Harley Aug 21 '17 at 20:28
  • @Harley You can see [here](https://github.com/TryItOnline/tryitonline/blob/master/wrappers/apl-dyalog) exactly what TIO does. Note the line `WSPATH=$DYALOG/ws`. – Adám Aug 21 '17 at 20:30
  • I just tried "PATH="/opt/mdyalog/16.0/64/unicode/ws:"${PATH} dyalog < "$tmpfile" in the wrapping script, without any visible positive effect on the interpreter. – Harley Aug 21 '17 at 20:50
  • @Harley Looking back at your comments, I see that your system in fact does find salt.dws, as you end up suspended in `enableSALT`. At this point recommend [contacting Dyalog's support](https://www.dyalog.com/contact-us.htm). – Adám Aug 21 '17 at 21:00
  • Nice, I will try to reproduce the effect of the script in the "here" link above, but now it seems that it starts to be late here in Stockholm, and (off topic) the cats are calling for food, too. :) – Harley Aug 21 '17 at 21:12
  • Yes, I have asked for an invoice for Personal DSS subscription and think that that is a good idea. – Harley Aug 21 '17 at 21:14
  • @Harley God natt då! – Adám Aug 21 '17 at 21:16
  • Thanks, Adám !What finally was needed was the -script option to the dyalog command. – Harley Aug 24 '17 at 16:02