Dyalog APL available for the Pi


20 posts
by mkrom » Fri Jun 07, 2013 3:08 pm
Raspberry Pi programmers now have another powerful language in their toolkit - APL.

Dyalog Limited have just released a Raspbian port of Dyalog APL for the Raspberry Pi. Dyalog APL for the Pi is a complete 32-bit Linux interpreter, with the same APL language features as Dyalog's well-established Windows, AIX and Linux implementations.

APL is an expressive, interactive language that is ideally suited to exploratory programming. It's been widely used to solve STEM* problems, and its concise, mathematically-oriented notation makes it great for education and exposition.

APL has a long history of success as an effective and exciting language for introducing mathematical concepts to students of all ages. We see this popular new platform as a great way for a whole new community of users to find inspiration from APL in a way that's fully aligned with the goals of the Raspberry Pi foundation.

APL is highly effective at solving problems that involve performing complex calculations on lists or arrays of data. Its bit-manipulation capabilities make it a great tool for Embedded, Robotics and Computer Vision applications. Dyalog have been blogging about their embedded experiments at http://cto.dyalog.com/category/raspberry-pi/.

If you want to get a flavour of the language, you can experiment on-line at http://tryapl.org. When you want to explore it further and run it on your Pi you will find installation instructions at http://packages.dyalog.com

* STEM - Science, Technology, Engineering and Mathematics.
Posts: 5
Joined: Fri Jun 07, 2013 5:50 am
Location: Elsinore, Denmark
by Bakul Shah » Sat Jun 08, 2013 9:21 pm
Good to see this!

But I haven't had a chance to play with this. I briefly tried logging in from a mac (no display on the RPi) but couldn't figure out how to input APL chars. Using KAPL font with xterm on the mac at least displays APL chars but not with APL385.

[Edit] I connected a display to the RPi and exactly followed the instructions in the dyalog apl for RPi users and selected the right font from the lxterminal's edit->preferences menu etc. but instead of special chars I see a diamond with a ? in it. If I manually start uxterm and cat aplkeys/xterm I see only a few symbols but not the full complement.
Last edited by Bakul Shah on Sun Jun 09, 2013 9:11 am, edited 1 time in total.
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by RMW5 » Sun Jun 09, 2013 7:37 am
Nice implementation and it runs very well. APL is a very expressive language based on Iversen notation (developed by Ken Iversen who implemented the first version of APL over 40 years ago). It is implemented as an interpreter oerating in an interactive environment, allowing rapid development resulting in arguably less structured code than Python/java/C++ etc. It can be used to express arithmetic processes, including matrix operations very succinctly but has broader applications than arithmetic.
Posts: 47
Joined: Fri Dec 23, 2011 4:31 pm
by mkrom » Mon Jun 10, 2013 11:28 am
Bakul Shah wrote:I briefly tried logging in from a mac (no display on the RPi) but couldn't figure out how to input APL chars. Using KAPL font with xterm on the mac at least displays APL chars but not with APL385

Sorry to hear you are having trouble on the Mac - we have to admit we only properly validated this under Windows and Linux. We do have two members of our development team who use Macs on a daily basis, we're checking things out and will be back when we have some reliable instructions.
Posts: 5
Joined: Fri Jun 07, 2013 5:50 am
Location: Elsinore, Denmark
by mkrom » Mon Jun 10, 2013 11:51 am
RMW5 wrote:Nice implementation and it runs very well.
Thanks for the kind words! But then, this is a complete port of the most advanced APL interpreter on the market (if we say so ourselves), so it better be... ;-)
RMW5 wrote:APL... allows rapid development resulting in arguably less structured code than Python/java/C++ etc.
That was certainly true in the 1980's. Today, Dyalog APL has been extended with:

There should no longer be any technical reason why APL would lead to less structured code, but there may well be human factors that would still contribute to that. The most successful users of APL tend to be "any kind of engineer other than a software engineer". Typically financial, chemical, electrical engineers, physicists, etc.
RMW5 wrote: It can be used to express arithmetic processes, including matrix operations very succinctly but has broader applications than arithmetic.
We think so too :-). For an illustration of the kind of thing that APL makes "fun", see this morning's post on the Dyalog "CTO Blog" (elementary cellular light-emitting automaton).
Posts: 5
Joined: Fri Jun 07, 2013 5:50 am
Location: Elsinore, Denmark
by Jason|Dyalog » Mon Jun 10, 2013 1:08 pm
Bakul Shah wrote:
[Edit] I connected a display to the RPi and exactly followed the instructions in the dyalog apl for RPi users and selected the right font from the lxterminal's edit->preferences menu etc. but instead of special chars I see a diamond with a ? in it. If I manually start uxterm and cat aplkeys/xterm I see only a few symbols but not the full complement.


Hi Bakul.

Sorry to hear you're still having issues, if you select the default monospace font and cat /opt/mdyalog/13.2/32/unicode/aplkeys/xterm do you see the characters? most of the characters exist in the default virtual font, however some look odd which is why we supply our own font for this use.

Could you also let me know the md5sum of both:
/opt/mdyalog/13.2/32/unicode/aplkeys/xterm (c2831f957dabd43e05dae4340738c4c4)
/usr/share/fonts/truetype/dyalog/Apl385.ttf (0f127d59bbed2766e2f8d14ca320404a)

I've included the MD5Sum from my test Pi here which was installed from the live package.

The MD5 of the package which you will be able to find in /var/cache/apt/archives/dyalog-unicode-132_13.2.17959_armhf.deb is ccc160e1a5f294f8220a25847a8d577a.

Could you also confirm that you are able to view other UTF8 characters on the Pi. (You can test with this site: http://www.fileformat.info/info/unicode ... f8test.htm and you can paste them into a terminal to make sure the terminal is also displaying UTF8).

Thanks.

Jason.
Posts: 2
Joined: Mon Jun 10, 2013 12:43 pm
by Bakul Shah » Mon Jun 10, 2013 10:24 pm
Jason|Dyalog wrote:
Bakul Shah wrote:
[Edit] I connected a display to the RPi and exactly followed the instructions in the dyalog apl for RPi users and selected the right font from the lxterminal's edit->preferences menu etc. but instead of special chars I see a diamond with a ? in it. If I manually start uxterm and cat aplkeys/xterm I see only a few symbols but not the full complement.


Hi Bakul.

Sorry to hear you're still having issues, if you select the default monospace font and cat /opt/mdyalog/13.2/32/unicode/aplkeys/xterm do you see the characters?

If I run uxterm I see all the shapes but I don't see a way to select apl385 font for uxterm - it gets whatever default font it has. In xterm I see chars like ââââââ but once I turn on utf8 encoding I see the same thing as in uxterm. [BTW, remote use of either is very slow -- there is really no point in painting blank chars! The original vi (and I think curses) had display update optimizations built in which seem to be lost with ncurses.]

In lxterminal, with monospace I see lots of <?> (reverse video diamond with a ?) -- as if chars outside of ascii range are purposely obscured!

Could you also let me know the md5sum of both:
/opt/mdyalog/13.2/32/unicode/aplkeys/xterm (c2831f957dabd43e05dae4340738c4c4)
/usr/share/fonts/truetype/dyalog/Apl385.ttf (0f127d59bbed2766e2f8d14ca320404a)

These match.

Could you also confirm that you are able to view other UTF8 characters on the Pi. (You can test with this site: http://www.fileformat.info/info/unicode ... f8test.htm and you can paste them into a terminal to make sure the terminal is also displaying UTF8).

In uxterm I can see them but not in lxterminal.

I still have the problem not being able to input APL chars from a mac keybpard. I can cut and paste ⍳(iota) and other characters from the above page but it gets old fast! Mac has keyboard mapping for most natural languages and even dvorak but not APL!

Thanks for looking into this.
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by Bakul Shah » Tue Jun 11, 2013 2:36 am
OK, Problem solved!

I did this:
Code: Select all
cat >> ~/.Xresource <<'EOF'
UXTerm*faceFont: APL386 Unicode
EOF
xrdb -merge ~/.Xresources


So everything works locally using uxterm. lxterminal still misbehaves but I don't care about it. xterm is not in the default Raspbian distro so you'd have to sudo apt-get xterm and may be more.

For the Mac I located a program called Ukelele from SIL.org's website that can be used to define a keyboard layout. And I found people had already used it to produce layouts for A+ and APLX. Does Dyalog have such a mac layout? If not I'll see what I can do starting from the APLX layout.
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by Jason|Dyalog » Tue Jun 11, 2013 11:54 am
Hi Bakul.

We have created a keyboard layout and a draft document on what to do from OS X, the details can be found here: http://www.dyalog.com/resources/ Please let me know if you have any issues with this and we'll try and get them sorted as quickly as we can.

Jason.
Posts: 2
Joined: Mon Jun 10, 2013 12:43 pm
by Bakul Shah » Tue Jun 11, 2013 8:45 pm
Thanks very much, Jason & Dyalog!

Further notes:

In Terminal preferences->settings->keyboard deselect "Use Option as Metakey". If you use Xquartz, in preferences->Input deselect "Option Keys sent Alt_L and Alt_R". Without this change you won't be able to type option+i for iota etc.

⌘; is a handy shortcut for toggling between two keyboard layouts.

The dyalog alt layout swaps backquote (`) and backslash (\) keys on my US keyboard but this is easily fixable.

"tab completion" in zsh/bash seems to stop working with the dyalog layout, even though the tab key seems to be not remapped. (Independent of that) I can't even input anything in this forum posting window in Chrome with this layout is active! Very strange!

Still, all in all a fun toy! [Not in its capabilities but enjoyment.] Thanks!
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by Bakul Shah » Wed Jun 12, 2013 12:36 am
Just kicking tires....

Code: Select all
      x←⍳10000000
      ]cputime x+x

* Benchmarking "x+x"
* Command Execution Failed: WS FULL
      ⎕wa                                                                             
66275016                                                                             


Clearly 66MB is not enough to add two 10M entry integer vectors. Is there a way to allocate more memory?

The following seems to have an O(n^2) behavior. But when + is used instead of {⍺+⍵}, scan (\) is O(n) as I would expect. Strange!
Code: Select all
      ]cputime {⍺+⍵}\⍳100                                                           
 CPU (avg):  130                                                                     
 Elapsed:    134                                                                     
      ]cputime {⍺+⍵}\⍳1000                                                         
 CPU (avg):  13480                                                                   
 Elapsed:    13509                                                                   
      ]cputime {⍺+⍵}\⍳2000                                                         
 CPU (avg):  55280                                                                   
 Elapsed:    55388                                                                   


More tests later...
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by mkrom » Wed Jun 12, 2013 12:12 pm
Bakul Shah wrote:Clearly 66MB is not enough to add two 10M entry integer vectors. Is there a way to allocate more memory?

APL is starting with the default workspace size of 64Mb (67.1 million bytes). You can change by setting the MAXWS= environment variable - either by adding a setting like "MAXWS=100M" to the file ~/.dyalog/config or by prepending a new value for the variable when starting APL, for example:
Code: Select all
MAXWS=200M dyalog
At present, the config file will overwrite the command line setting, that is something we intend to change. We don't recommend setting the workspace size to more than the available memory. I'll respond to your question regarding scan in a separate reply.
Posts: 5
Joined: Fri Jun 07, 2013 5:50 am
Location: Elsinore, Denmark
by mkrom » Wed Jun 12, 2013 12:43 pm
Bakul Shah wrote:[The scan operator] seems to have an O(n^2) behavior. But when + is used instead of {⍺+⍵}, scan (\) is O(n) as I would expect. Strange!
This is one of the questionable design decisions from the early days of APL. The definition of scan is a set of repeated reductions, each one including one more item. For associative functions like + (ignoring the fact that no functions are truly associative on limited-precision floating-point numbers), the interpreter cheats.

The dfns workspace contains a user-defined operator called ascan, to work around this. On my Windows laptop (all the Pi's are at home today), ascan does the "{⍺+⍵}ascan⍳5000" in 15ms vs 5 seconds for the primitive scan. Type ")copy dfns ascan" to bring the operator into your active workspace.
Posts: 5
Joined: Fri Jun 07, 2013 5:50 am
Location: Elsinore, Denmark
by Bakul Shah » Wed Jun 12, 2013 5:47 pm
APL's reduce is a "right fold" (in functional programming terms). That is, f/V == v0 f (v1 f (v2 ...)), right? So then the Nth terms of f\, which is just f/ on the first N vector entries, will be computed differently from the N+1th term. Most of my recent experience with k, which defines f/ to be a left fold. But I should've figured that out. Thanks!
Posts: 291
Joined: Sun Sep 25, 2011 1:25 am
by rfcpilot » Thu Jun 13, 2013 8:53 pm
If I may be permitted to add a word in support of APL programmers:-

Documentation within the program is VITAL.
Posts: 2
Joined: Mon May 06, 2013 5:06 pm
by jackokring » Wed Jun 19, 2013 6:12 pm
http://www.jsoftware.com/download/j801/ has a beta version of J 801. I think the Qt toolkit installer is being worked on, and JPI will be a supported platform moving forward with continued interest. It's like APL but with regular keying and no special keyboard. It does unicode though.
Pi=B256R0USB CL4SD8GB Raspbian Stock. https://sites.google.com/site/rubikcompression/strictly-long
User avatar
Posts: 754
Joined: Tue Jul 31, 2012 8:27 am
Location: London, UK
by VE7VIE » Wed Jun 26, 2013 12:33 am
I'd say: Documentation of the problem being solved is what is vital (with some algorithm hints, perhaps). As an APL consultant for 20 years I wasted many days trying to understand code that could have been rewritten in minutes, if what was being accomplished by it had only been described. It doesn't have to be with the code, which may well be thrown away.
Barry

rfcpilot wrote:If I may be permitted to add a word in support of APL programmers:-

Documentation within the program is VITAL.
Posts: 2
Joined: Wed Jun 26, 2013 12:10 am
by fornallaza » Wed Jul 24, 2013 5:16 pm
VE7VIE wrote:I'd say: Documentation of the problem being solved is what is vital (with some algorithm hints, perhaps). As an APL consultant for 20 years I wasted many days trying to understand code that could have been rewritten in minutes, if what was being accomplished by it had only been described. It doesn't have to be with the code, which may well be thrown away.
Barry

rfcpilot wrote:If I may be permitted to add a word in support of APL programmers:-

Documentation within the program is VITAL.


Barry, you are quite right in principle. But what do you exactly mean when you state "the code [...] may well be thrown away." Is it not important to relate documentation structure to code structure, hence to represent code "canonically" or otherwise?
Posts: 1
Joined: Wed Jul 24, 2013 4:53 pm
by apple2 » Thu Sep 26, 2013 11:41 am
The Dyalog APL for the R.Pi looks very nice. I've only finished setting up my R.Pi and when I saw that APL was available, I had to give it a go. When I first learned to program in APL it was on an IBM Mainframe 1130 or 370 (can't remember exactly), that was back in about 1977. The only other APL that I've had reasonable success with was APLSE running on a PC in MSDOS. Although that was OK, it is a bit limited with arrays and the text resolution is a limited to 80x25. Now that I've got Dyalog APL running on a nice big 24" screen, I can get much higher text resolutions that use a very clean TTF font.
My first program exercise was to convert a Calendar Printing Program from a version that I had working and printing in APLSE, which was based on a program listing I had dating back to 1977. I found out that Dyalog APL actually has a CAL function, but for the exercise I am still going to code the original listing into Dyalog. The program prints a Calendar with a picture and a large year banner above the actual calendar. the pictures are basically old school ASCII art saved as text files that are randomly selected by the program. My favourite is the Mona-Lisa image which has triple overlaid lines of text.
So far I have most of the main program and subroutines up and running, with output to the screen, but soon I need to get it to print to an external physical printer, either on a network or dot matrix printer directly connected to the printer port. This is where I am running into a problem. I've managed to get my network laser added to Raspbian on the R.Pi and this works fine, including the ability to print APL Program listings in the correct fonts, using the Leafpad app. But I don't know how to make Dyalog APL send output to the printer. I've been scanning through all the Dyalog documentation, but can't find anything on sending output to a printer. Can anyone explain how to do this. the equivalent commands in APLSE doesn't work on Dyalog APL. it uses []TCNL (ie []=QUAD), []TCLF and []TCFF and other similar commands. I don't think this works in Dyalog.
Posts: 1
Joined: Thu Sep 26, 2013 10:36 am
by rudimentarius » Wed Dec 04, 2013 8:40 pm
Hi, I only work on the console; I would be happy to learn a little of APL. Do you think it is possible to use APL on the console?
Posts: 8
Joined: Tue Aug 21, 2012 8:24 am