This is screen-shot of GNU-APL running ⎕PLOT tests on CentOS-7 Linux box. I'm using X11 library "xcb" which works well with latest GNU-APL ver. 1.8/SVN:1379M. The "xcb" library is good, it allows the APL to run and generate plots on both Linux boxes and the MacBook.

This is GNU-APL using the ⎕PLOT function to plot 2000 pseudo-random numbers from 1 to 1000. The function ⎕PLOT just works in CentOS-7, no problem. I have setup the nested array "Attr" (see its contents at the APL session screen, bottom-left), and altered the background canvas (grey) and the line-width size (down to 1 pixel), and so on. This is a very nice feature, and is something I did *not* have on my Windows APL that runs under the WINE "emulator" (That approach works well, but there is no built-in graphics.) But the GNU-APL ⎕PLOT function "Just Works" on Linux, since the GTK stuff is installed to make GNOME work. I am seriously impressed by this.

This is a Linux box (CentOS-7) running two GNU-APL 1.8 sessions to display two simple sine-wave plots, created on the fly, using the ⎕PLOT function. This runs directly from GNU-APL, and does not need to call GNUPlot. I like charts and graphics with dark-grey backgrounds, but the newest & latest GNU-APL 1.8 / SVN 1379 version only changes the backgound of the graphic "legend". What looks very interesting with the latest build of the GNU-APL code, is that the ⎕PLOT looks like it does 3-D surface image rendering, like GNUPLOT does. The single line of APL code that generates the plot, is shown below the right-side graphic,

This is a pretty cool hack. This box is an old 32-bit Fedora/Red-Hat box, with a semi-custom Linux kernel, but based on a Linux kernel: 2.6.27.25-78.2.56.fc9.i686 (as reported by "uname -a"). I've got the GNU-APL 1.8a (the SVN version 1379, with my fixes to the LIBXCB stuff, so ⎕PLOT works correctly. This involved some major work - first, I had to build a working gcc version 4.8.5, which is from 2015 - actually a pretty solid compiler - complete with a good FORTRAN (gFortran), and Java and other stuff. I also had previously built Python 2.7, and the box runs two versions of Tcl/Tk. To build gcc 4.8.5, I used the original gcc 4.3.0 (from April 28, 2008) which was on the machine. (Attempts to build GNU-APL with this older gcc compiler, failed with "long-integer" errors. So, I had to upgrade gcc to 4.8.5 to build GNU-APL 1.8 from source.)

But this is the coolest thing. This GNU-APL is a real, native Linux APL, and one uses "xmodmap" to setup the APL keyboard/APL characters. I had assumed that the APL would not run under a 32-bit processor, but that's wrong. If you have gcc 4.8.5, (or later, probably), the GNU-APL 1.8 will configure and compile & build successfully, if you have installed the newer libxcb stuff and the fftw3 code, for FFTs (if you want to do some signal-processing, or other waveform bashing.)

When you upgrade "libxcb", by building it from source, you run into problems trying to link stuff together, because the xcblib-xlib.so.1 library just got removed in the move from libxcb.so.1.0.0 to libxcb.so.1.1.0, and on this older platform, I kept getting undefined references to "_xcb_lock_io" and "_xcb_unlock_io", during the build. (Here is an old Gentoo note found on Google: https://forums.gentoo.org/viewtopic-p-7282170.html?#7282170 )

When I first built and installed LIBXCB (I used the LIBxcb.1.12 tarball), it completely destroyed my X-windows/GNOME GUI! Oh my.. The install for libxcb sets up a symlink in /usr/local/lib which points to new /usr/local/lib/libxcb.so.1.1.0 dynamic library. And in /usr/lib, the symlink libxcb.so.1 which points to /usr/lib/libxcb.so.1.0.0 gets ignored. I spent hours tracking this down and figuring out what was happening. You can run "ldd" (the tool to check dependencies in dynamic librarys) on old libxcb-xlib.so.0.0.0, and see where libxcb.so.1 is pointing to. Once I installed the newer libxcb, the libxcb.so.1 reported by "ldd" was pointing to /usr/local/lib/libxcb.so.1. The idea is that new stuff goes into /usr/local/lib, but the old system-critical stuff in /usr/lib is unaffected, so your system will remain functional. But when programs (like X) look for dynamic libs, they look in /usr/local/lib first, then /usr/lib (on RedHat/Fedora/CentOS). To recover function of my Xwindows/Gnome, I just removed the symlink to the newer xcblib.so.1.1.0 in /usr/local/lib, by removing /usr/local/lib/libxcb.so.1, and then X-windows/Gnome was restored.

This way, the new xcblib stuff can be used, but the old remains available for system operation. Run "ldd" against /usr/lib/libxcb-xlib.so.0.0.0, and you see now that libxcb.so.1 now points to /usr/lib/libxcb.so.1 (not the one in /usr/local/lib.

You have to do other stuff also, to build the APL. Typically (like the gcc build also), you set LD_LIBRARY_PATH to /usr/local/lib and PKG_CONFIG_PATH also to /usr/local/lib, so your new code can link against the newer installed versions of libs in /usr/local/lib.

For gcc upgrade, I needed to build: mpc, mpfr and gmp. For the GNU-APL, I had to build fftw3 and xcb (as mentioned).

Also, to get GNU-APL to build to completion, so it could be successfully installed, I had to hack the "Makefiles" in the /tools subdirectory of /home/gnuapl/apl-1.8a (where I put the current APL source).
Specifically, I was also gettting the "_xcb_lock_io" and "_xcb_unlock_io" undefined reference errors during the GNU-APL "make". I did this build of gcc 4.8.5 and GNU-APL on two different 32-bit boxes. On the first box, in the xcb build (of libxcb-1.12), I had to also build pthread-stubs-master, xcb-proto-1.12 and libXau-1.0.7. One the second box, the build of xcb lib used only pthread-stubs-master and xcb-proto-1.12. But on the second box, I had to tweak the "LIBS =" parm in the ../tools/Makefile to include: " /usr/lib/libxcb.so.1 /usr/local/lib/libxcb.so.1.0.0 " at the end of the string. So in apl-1.8a/tools/Makefile:

LIBS = -lc -ldl -lcairo -lfftw3 -lm -lncurses -lcurses -lnsl -lpthread -ltinfo -lxcb -lX11 -lX11-xcb

became:

LIBS = -lc -ldl -lcairo -lfftw3 -lm -lncurses -lcurses -lnsl -lpthread -ltinfo -lxcb -lX11 -lX11-xcb /usr/lib/libxcb.so.1 /usr/local/lib/libxcb.so.1.0.0

In /usr/local/lib, I have both libxcb.so.1.0.0 (the original one) and /libxcb.so.1.1.0 (the newer one) of the xcblib libraries. And I notice a symlink called "/usr/local/lib/libxcb.so" has been created in /usr/lib, which actually points to libxcb.so.1.1.0. So mostly, I am getting the new library during "make" runs. But a link to the older 1.0.0 library is included in the "LIBS=" line in the make file. This let the build work, without needing to build libXau-1.0.7. (It would appear.) The build runs libtool, which create .la files for xcb and other stuff in /usr/local/lib. These .la files are text files which give dynamic load-library location information. You can google "What are .la files?" and spend a while reading what ".la" files are, and how "libtool" creates and manages them.

I didn't really expect to get all this working. But it does now work, and Xwindows/Gnome GUI is working again. And on the second machine I setup, it is quite amazing. The machine is an old Pentium III Compaq-EN, with only 1.3 gig of memory, and the APL and the ⎕PLOT graphics and the ⎕FFT stuff all works. The image above shows the GNU--APL 1.8, with ⎕PLOT working successfully. This machine is a 32-bit Pentium 4, with 2 gig memory, and it runs along snappy quick, no problems. I'll try to write up all this a bit better, as I am just going thru scribbled notes, trying to capture stuff I did on the fly, and just wrote scrawls as I got things to work. This note is mess, but I wanted to get details down while it's all still fresh. I will try to write up something better, later. What this means, is that with a bit of effort, you an take an old 32-bit box, install a Linux on it, and build a very powerful APL machine, that looks like it works, complete with ⎕PLOT graphics and ⎕FFT, and also SQLITE3 functional access. Cool stuff, for major data-bashing and model-hacking. :)

GNU-APL running on Macbook-Pro. I built the APL interpreter from source, and then got the FFTW3 library for Fast Fourier Transforms, and I already had GNUplot on the Mac. This is GNUAPL 1.8, running the "GNUPLOT.apl" example, where it uses the Quad-FFT function to call the FFT library, and the GNUplot to display the results.

GNU-APL - How to Setup APL Keyboard & Compile the Code

This is the Dyalog APL keyboard, which Dyalog provides for the GNU-APL. (Click on image to enlarge it.)

GNU-APL - It Seems to Work Well! - For production-grade data-bashing, we use an old Manugisitcs APL - but an associate mentioned he was using GNU-APL, and it has the advantage of crazy-large workspaces (ie. measured in gigabytes) and also uses SQL-Lite as the back-end database.   This fellow is capturing all daily trading from a particular exchange, and this results in roughly 1 gigabyte of data each day - and so running an SQL query might generate a 100,000 row table, with a fair bit of data for each row.

So, I was intrigued by this, and found and downloaded the GNU-APL last night, and compiled it and got it running on one of the CentOS-7 boxes.  

The current details about GNU-APL should be here:

https://www.gnu.org//software/apl/

Damn thing seems to work pretty good.  I had to hack around with the keyboard stuff for a while, as the first configuration I tried - using Linux "xmodmap" to configure the ALT-whatever key to create the APL characters, caused the loss of all the ALT-function features needed to control the XTERM Linux sessions - and even switch contexts between X-Windows in GNOME (and this managed to blow up the Firefox session, and wipe out a bunch of webpage sessions, of course).

To use "Xmodmap", you can just run:

         xmodmap ./support-files/old-Keyboard/apl.xmodmap

But maybe don't use this.  The loss of "Alt-TAB" (to switch between Xterm window sessions in Gnome) is lethal to Firefox, and will also prevent ALT-F1, ALT-F2 ... etc. from switching between sessions outside of GNOME.  So this approach (which works fine for generating APL characters in Xterm) is no good.  (Note! On older Fedora boxes, I have to use this method.)

But what does work, is this trick (on the latest CentOS Linux boxes:)

        xkbcomp ./support-files/old-Keyboard/apl.xkb :0 -w 0

and this works great. (The ":0" is your X-session, "-w 0"  means suppress warnings.)  On my Fedora/CentOS-7 Linux box, it sets up ONLY the right-side ALT key on the keyboard, to be the ALT key for generating APL characters.  The left-side ALT key still works as it is supposed to, so that ALT-TAB can switch between running Windows in GNOME.  

Using the right-side ALT key, allows APL chars to be generated and displayed correctly.  For example,  ALT(right)-R creates the "rho" character, ALT(right)-i creates the "iota", and ALT(right)-[ will create the left-arrow for APL assignment operator, ALT(right)-] is the right-arrow, for APL branching, etc.  This is the same as the ALT-xx operation of the various GEMESYS APL apps on Android (using the Android "Hacker's Keyboard"), and yet it still allow the ALT(left-side) key to operate as is required by Xterm and GNOME and Linux.  (eg: ALT-CTRL-F7 lets you jump right out of GNOME/X-windows into regular command-line Linux sessions, and ALT-<Fsession#> lets you jump back into Xwindows/GNOME session.  ALT(leftside)-TAB is needed to just switch between Windows - and restore minimized Xwindows/GNOME sessions.)

The GNU-APL has several other methods of creating the APL keyboard, which I have not tried yet.  But the method described here is quite satisfactory, and lets all the APL characters be displayed correctly..

Also, to start APL, in a normal, standard APL interactive workspace session, you run "apl" with the option "--noColor", which makes the interactive APL session behave in a sane way, like any standard interactive APL.

Eg:  - To start GNU-APL after it has been installed:

                 [Your-System-Prompt-in-Xterm-Window]$ apl --noColor

and you will get a working APL with a big workspace (up to gigabytes, it looks like, if you need this much...).  On my CentOS-7 box, if you start without "--noColor" option, you get an awful video mess, and cannot even see the APL interpreter results.   Just enter ")off" to exit APL, an then enter "reset" and to fix your borked X-term session (it might be blank, no video chars visible!), and the virtual terminal will reset correctly.  But if you enter "--noColor", it works fine.  Note there are "two" dashes for this critical parameter, not one.

How to Install GNU-APL:

    [ I am running an old gcc (GCC) 4.8.5 20150623 (Red-Hat 4.8.5-28) with all the associated  development utilities need to build anything now on Linux... ]  So, to build GNU-APL:

      - download the APL-1.7 gunzipped tarball from the GNU-APL ftp site.  Note that this can be seriously slow  sometimes:

         Download apl-1.7.tar.gz from site:  https://ftp.nluug.nl/pub/gnu/apl/

         Create directory in /home     (ie.  become root, cd /home, mkdir gnuapl, cd gnuapl)

         cp /home//Downloads/apl-1.7.tar.gz .     (copy file to build directory)

         gunzip apl-1.7.tar.gz    (create .tar file, ie. removes the .gz compression)

         tar -xvf      (untar the package)

         cd apl-1.7    (connect to build directory where you will compile source)

         ./configure   (if running a modern Linux, this should just work, and setup build defaults)

         make           ( run the Makefile to do the compile of the c++ source)

           (Check the apl executable...    cd src,  ./apl  --noColor   (to run the GNU APL)

                (Try something like 234+3, press return, and confirm you see: 237 as the response)

                (If the exectuable runs ok, you may as well just install it and experiment with it...)

         make install    ( if the compile ran without errors, you can just install the apl executable)

For now, I am running the APL-1.7.   I will try the 1.8 version tonite on a different machine and see if it works.  My associate who has been working on this says that the 1.7 (circa 2017) is very stable, but he could not get APL 1.8 to run without getting segfaults.

Initial experiments with the GNU APL 1.7 look quite promising.  Very promising, actually.

Coda:  How to check the GNU APL signature file (or any GNU project Signature)

   1) ensure you have gpg on your machine.  If a modern Linux (ie. since 2008!) it should be there.

   2) Assume you put the files APL source and .sig files in /home//Downloads

       cd /home//Downloads

       Go to your broweser, and download the keyring signature file for GNU projects.  Just cllck this link:...

             https://ftp.gnu.org/gnu/gnu-keyring.gpg

      This gets the file gnu-keyring.gpg file into Downloads directory.  Run a gpg with --verify to check that the .sig file matches what was signed on the .tar.gz file:

        gpg --verify --keyring ./gnu-keyring.gpg  apl-1.7.tar.gz.sig  apl-1.7.tar.gz

     This command says "Look in gnu-keyring.gpg to confirm the .sig is a real sig file, and verify that the apl-1.7.tar.gz file was signed with this signature.  You should get a "Good Signature from..." response, in this case: "Jurgen Sauermann (Programmer) <juergen.sauermann@t-online.de>".  Note that you also get a WARNING saying there is no certainty that this key is actually a trusted key (you have to fiddle with GPG stuff more to get a "web-of-trust" thing setup, and that is another thing..)

   Also, you can run the MD5 hash against the apl-1.7.tar.gz file, and I get this value, when I run it against mine:

      gpg --print-md md5 apl-1.7.tar.gz

      (should respond with:)

       A0 64 56 F4 AA 9E 34 97   00 DA 51 C8 EF D1 41 50

   (BLah blah blah - MD5 is not the most secure message digest - blah blah blah blah.)

    and for MD5 hash check (message digest check) for "apl-1.8.tar,gz",

      gpg  --print-md md5 apl-1.8.tar.gz

      B1 8E 71 FF 2D 30 7C F2    26 80 67 DE ED 50 26 EC

   I like MD5 becuase it is simple and fast and is better than no security at all, guys.

And this GNU-APL seems to work good.  

Update: To get the APL Libraries in wslib3, wslib4 and wslib5 to be visible to the interpreter, I had to create a local "preferences" file in ~/.gnu-apl directory, and remove the references that are in the default build-preferences file (see build-directory "gnu-apl.d" for the standard default preferences file, and just copy it to your local .gnu-apl directory).  Replace the @GNU_APL_LIBS@ strings in each of the LIBREF-n statemetns with "." to point to your local directory, and then create local directory copies of each of the subdirs wslib3, wslib4, wslib5 that are in the GNU-AP build directory.

Just cd to build directory (in my case, I used:  /home/gnuapl), and then copy the directories for each of the APL libraries to your local user directory:

      cd  /home/gnuapl      (connect to your build directory...)

      cp ./wslib3  /home//  -v  -R       (make local copies of each of the APL Library directories, 3, 4 and 5. ) 

Then, when you start GNU-APL, and enter ")libs" you should see that your three APL Libraries show up a "present" instead of "missing",

 

GNU-APL - Latest SVN Version

Note:  It is a good idea to install the latest SVN version.  You need to install (or already have, like most Linux installations do), the SVN code version management tool.

If SVN is installed on your local machine, you can get all the code with this command below.  Just create a new directory (I used "mkdir /home/gnuapl" to create a directory under the "/home" top level Linux directory.)  Then, "cd /home/gnuapl", and with that as your default directory, just run this:

svn co http://svn.savannah.gnu.org/svn/apl/trunk

and that above command will create a directory "trunk" with the very latest GNU-APL code in it, and you can just "cd trunk" and try the "./configure".  If it runs ok, run "make", and if that works, you can just run: "make install", as described above.

If there are errors or problems you will have to resolve them.

Good luck!

 

GNU-APL Notes - on Linux and MacBook-Pro

(Click on Image to expand it!) This is actually the GEMESYS sAPL running on an Android tablet. APL is a terse and very powerful language, which is available on every computer. The GEMESYS apps are 100% free, with no adverts or in-app tricks or tracking.) We build our stuff and offer it at no charge because we can! :)

Decided I had to get the GNU-APL working with the latest SVN version.   First got it working right on the Linux boxes, and then on the MacBook.  The Linux boxes were easier, as the trick was to run the ./configure with a "--without-gtk3" option, which disabled the buggy Gtk-3 graphics stuff, and tells GNU-APL to use the "xcb" / X11 library routines for charting purposes.   Linux was easly, Apple Macbook was more difficult  (big surprise - not)...  

But after some extensive hacking around, I finally got the GNU-APL 1.8a to build - WITH THE ⎕PLOT Graphics CAPABILITY - on the MacBook.  This is a big deal, as this allows quality graphics to be generated in real-time, under program control, and with actionable data.

The technical details for the Macbook involve: 

  -  having the XQuartz (X11) utilities installed

  -  you need all the command-line build utilities and Xcode 7 or better gcc compatible c++ compiler and tools

  -  you will need to get the "xcb" library routines, which GNU-APL uses to talk to X11, and build these from source  (get xcb 1.12, run tar -xvf,  and then just run ./configure, make, make install to build and install the xcb libraries for X11.

  -  when building the GNU-APL, you need to use:  " ./configure  --without-gtk3"    (since the Gtk routines are not part of MacOSX), and then "make" and "make install" to install the GNU-APL with xcb graphics support for the ⎕PLOT system function.

  -  and for the GNU-APL ./configure, you also need to set the LDFLAGS to where-ever your X11 libraries are, in my case it was:

       export LDFLAGS="-L/usr/X11/lib"

  -   also have to make sure you xcb routines and xcb-proto.pc(the /usr/X11/lib/pkgconfig file) are the  same version as the X11 library routines  and xproto headers).  I had to download xcb_1.12 version as a tar.gz file, and [ ./configure, make, make install ] to build the xcb routines.

The xcb code is old, and works well.  If you have XQuartz installed (for MacOSx X11 support), the whole thing works pretty good.  The xcb stuff is how ⎕PLOT talks to X11 and gets it to fling up graphics windows containing the plots.  Note that the GNU-APL surface plots are configured using a 3-d matrix (a "cube" or "block" of data-values).   If the rho,rho of the data equals 3,  (ie. data is a 3-dimension block of numbers) then this tells ⎕PLOT that is should make a surface plot, and not a table full of lines, as the chart.

 

Example of GNU-APL to Produce Plot

I just discovered the ⎕PLOT function in GNU-APL.  It does not work on the MacBook, but it DOES work on the Linux boxes.  (Plus, it looks like I can render APL chars in this webpage editor!)...  Here is a simple graphic, 2000 random numbers, 1 to 1000:

      ∇RAN_PLOT[⎕]∇
    ∇
[0]   RAN_PLOT
[1]  ⍝ --- Plot 2000 Random Numbers.  Note, this fn uses global var: Attr
[2]  ⍝ --- Attr is a nested array of "attrib: value" (eg: "line_width-1: 1 pixel") passed to ⎕PLOT as left argument
[3]  ⍝ --- This function simply displays a PLOT of 2000 random numbers, in the range of 1 to 1000.
[4]   Attr ⎕PLOT ,(1000?1000),,(1000?1000)
    ∇


The left argument to ⎕PLOT is a nested array of "parameter:  value" strings, - basically just an encapsulated table.  You can display it with the "disclose" operator, on the "Attr" variable: (viz.)

      ⊃Attr
legend_name-1:  Random Numbers        
caption: A Plot of Many Random Numbers
line_width-1: 1 pixel                 
pa_border_L: 60 pixel                 
point_size-1: 3 pixel                 
canvas_color: #2C2C2C                 
pa_width: 1100                        
pa_height: 700                        
      
What this does, is pretty self-explanatory,

 


The GNU-APL can be used to access SQL-Lite Databases. An example is shown below.


Available function numbers for GNU-APL to Access SQL-Lite Database:
-------------------------------------------------------------------

type  ⎕SQL[1] file      - open a database file, return reference ID for it
      ⎕SQL[2] ref       - close database
query ⎕SQL[3,db] params - send SQL query
query ⎕SQL[4,db] params - send SQL update
      ⎕SQL[5] ref       - begin a transaction
      ⎕SQL[6] ref       - commit current transaction
      ⎕SQL[7] ref       - rollback current transaction
      ⎕SQL[8] ref       - list tables
ref   ⎕SQL[9] table     - list columns for table


  Example of Using SQL-Lite (Version 3) "sqlite3" with GNU-APL
  ============================================================

The weirdly curious lack of "How-To's" and "Examples" on modern documentation
is rather unfortunate.  Everyone who writes, assumes that everyone is already
a domain-level expert.   This is a profoundly incorrect assumption, of course.

Here is a simple example of creating an SQLITE database and putting some
records in it, and then reading these records from within a GNU-APL workspace.

Hope this is useful for non-experts who are curious and want/need to do some
real work using their Linux-boxes!

- Mark Langdon,
  Owner & Developer,
  GEMESYS Ltd.
  December 8th, 2020


======== Example Of Creating SQLite3 Database and Reading it in GNU-APL =====

             Create a Tiny Example SQLite3 Database
             ======================================

Here, we are at command-level, in an X-Term window in the user directory.
We will create a tiny two-column database table, and put two records in it.

First, we just start "sqlite3" and confirm we can successfully exit it.
This confirms it is installed by default on our CentOS-7 Linux box, which
runs the default GNOME Windowing environment, which is similar to Windows-10.


( ---- Let's start SQLite3 at Linux Command-Line Level... )

[mcl@l2-centos74 ~]$ sqlite3

SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .quit


( ---- Now, we will create a tiny database in a file called:  mclnote.db )


[mcl@l2-centos74 ~]$ sqlite3 mclnote.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"


( ---- The database has been created, and we can now use CREATE and INSERT verbs )
( ---- in SQL to create a datatable, which will be called "notes" and will have  )
( ---- a line of text, and an integer number, which we will call "date".         )


sqlite> create table notes(text,date INTEGER);


( ---- We put two rows in the table, using INSERT verb.  This is just standard SQL. )
( ---- Note that SQL commands are terminated with semi-colons...                    )


sqlite> insert into  notes values('This is the first test note.', 20201205);
sqlite> insert into notes values('This is the second test note.', 20201205);


( ---- Now, lets see if the data is actually in the table.  We use the SELECT    )
( ---- verb to query the table and display it's contents.                        )


sqlite> select * from notes;
This is the first test note.|20201205
This is the second test note.|20201205


( ---- Ok, lets quit SQLite3... )


sqlite> .quit;
Error: unknown command or invalid arguments:  "quit;". Enter ".help" for help

( ---- Didn't work, did it...   )

sqlite> .quit


( ---- Ok, that worked.  We have a file in the user directory called "mclnote.db". )
( ---- We can confirm it exists, using the Linux "ls" command that lists files...  )


[mcl@l2-centos74 ~]$ ls *.db -l
-rw-r--r--. 1 mcl mcl 2048 Dec  5 18:04 mclnote.db


( ---- This is our sample tiny database example, which we will read in GNU-APL. )


      Read an SQL database table created with SQLite3 from within GNU-APL
      ===================================================================

( ---- Start GNU-APL...  )

[mcl@l2-centos74 ~]$ apl -noColor
unknown option '-noColor'
usage: apl [options]
    options:
    -h, --help           print this help
    -d                   run in the background (i.e. as daemon)
    -f file              read APL input from file
    --id proc            use processor ID proc (default: first unused > 1000)
    --cfg                show ./configure options used and exit
    --noCIN              do not echo input (for scripting)
    --echoCIN            echo (final) input to COUT
    --rawCIN             do not emit escape sequences
    --[no]Color          start with ]XTERM ON [OFF])
    --noCONT             do not )LOAD CONTINUE or SETUP workspace on startup
    --emacs              run in (classical) emacs mode
    --emacs_arg arg      run in emacs mode with argument arg
    --gpl                show license (GPL) and exit
    -L wsname            )LOAD wsname (and not SETUP or CONTINUE) on startup
    --LX expr            execute APL expression expr first
    -p N                 use profile N in preferences files
    --par proc           use processor parent ID proc (default: no parent)
    --PW value           initial value of ⎕PW
    -q, --silent         do not print the welcome banner
    -s, --script         same as --silent --noCIN --noCONT --noColor
    --safe               safe mode (no shared vars, no native functions)
    --show_bin_dir       show binary directory and exit
    --show_doc_dir       show documentation directory and exit
    --show_etc_dir       show system configuration directory and exit
    --show_lib_dir       show library directory and exit
    --show_src_dir       show source directory and exit
    --show_all_dirs      show all directories above and exit
    --[no]SV             [do not] start APnnn (a shared variable server)
    -T testcases ...     run testcases
    --TM mode            test mode (for -T files):
                         0:   (default) exit after last testcase
                         1:   exit after last testcase if no error
                         2:   continue (don't exit) after last testcase
                         3:   stop testcases after first error (don't exit)
                         4:   exit after first error
    --TR                 randomize order of testfiles
    --TS                 append to (rather than override) summary.log
    -v, --version        show version information and exit
    -w milli             wait milli milliseconds at startup
    --                   end of options for apl


( ---- Ok, the attempt to start APL with the "--noColor" option didn't work, because  )
( ---- I entered "-noColor" with a single dash, not the required "--" (double dash).  )
( ---- If you try to start GNU-APL without "--noColor", on my CentOS-7 Linux box, I   )
( ---- get some scrambled video which requires an ")off" and then a "reset" to be     )
( ---- entered, to restore operation of the X-Term window. (This is some problem with )
( ---- the emacs editor front-end for APL, which does not work on my system.)         )
( ---- If I start APL with "--noColor", everything works fine.                        )


[mcl@l2-centos74 ~]$ apl --noColor
                                       
                    ______ _   __ __  __    ___     ____   __
                   / ____// | / // / / /   /   |   / __ \ / /
                  / / __ /  |/ // / / /   / /| |  / /_/ // /  
                 / /_/ // /|  // /_/ /   / ___ | / ____// /___
                 \____//_/ |_/ \____/   /_/  |_|/_/    /_____/
                                       
            Welcome to GNU APL version 1.7 / Unversioned directory
                                       
                Copyright (C) 2008-2016  Dr. Jürgen Sauermann
                       Banner by FIGlet: www.figlet.org
                                       
                This program comes with ABSOLUTELY NO WARRANTY;
                          for details run: apl --gpl.
                                       
     This program is free software, and you are welcome to redistribute it
         according to the GNU Public License (GPL) version 3 or later.
                                       
          
      
      )help

( ---- Enter ")help" causes all GNU-APL commands to be shown... )

APL Commands:
      )CHECK
      )CLEAR
      )CONTINUE
      )COPY [lib] wsname [object ...]
      )DROP [[lib] wsname]
      )ERASE symbol ...
      )DUMP-HTML [[lib] wsname]
      )DUMPV [[lib] wsname]
      )DUMP [[lib] wsname]
      )FNS [from-to]
      )HELP
      )HIST [CLEAR]
      )HOST command
      )IN filename [object ...]
      )LIBS [[lib] path]
      )LIB [lib|path]
      )LOAD [lib] wsname
      )MORE
      )NMS [from-to]
      )OFF
      )OPS [from-to]
      )OUT filename [object ...]
      )PCOPY [lib] wsname [object ...]
      )PIN filename [object ...]
      )QLOAD [lib] wsname
      )RESET
      )SAVE [[lib] wsname]
      )SIC
      )SINL
      )SIS
      )SI
      )SYMBOLS [count]
      )VALUES
      )VARS [from-to]
      )WSID [wsname]
      ]BOXING [OFF|2|3|4|7|8|9]
      ]COLOR [ON|OFF]
      ]NEXTFILE
      ]EXPECT error_count
      ]HELP
      ]KEYB
      ]LIB [lib|path]
      ]LOG [facility [ON|OFF]]
      ]OWNERS
      ]PSTAT [CLEAR|SAVE]
      ]SIS
      ]SI
      ]SVARS
      ]SYMBOL symbol
      ]USERCMD [ ]ucmd APL_fun [mode]
               | ]ucmd { ... }
               | REMOVE ]ucmd
               | REMOVE-ALL
               ]
      ]XTERM [ON|OFF]

System variables:
      ⎕AI     Account Information
      ⎕ARG    command line ARGuments of the interpreter
      ⎕AV     Atomic Vector
      ⎕CT     Comparison Tolerance
      ⎕EM     Event Message
      ⎕ET     Event Type
      ⎕FC     Format Control
      ⎕IO     Index Origin
      ⎕L      Left Argument
      ⎕LC     Line Counters
      ⎕LX     Latent Expression
      ⎕PP     Printing Precision
      ⎕PR     Prompt Replacement
      ⎕PS     Print Style
      ⎕PW     Print Width
      ⎕R      Right Argment
      ⎕RL     Random Link
      ⎕SVE    Shared Variable Event
      ⎕SYL    SYstem Limits
      ⎕TC     Terminal Control characters
      ⎕TS     Time Stamp
      ⎕TZ     Time Zone
      ⎕UL     User Load
      ⎕X      aXis Argument
      ⎕WA     Workspace Available
      λ       { ... } result
      ⍺       { ... } left value argument
      ⍵       { ... } right value argument
      χ       { ... } axis argument
      ⍶       { ... } left function argument
      ⍹       { ... } right function argument

System functions:
      ⎕AF     Atomic Function
      ⎕AT     Attributes
      ⎕CR     Character Representation
      ⎕DL     Delay
      ⎕DLX    D. Knuth's - Dancing Links
      ⎕EA     Execute Alternate
      ⎕EB     Execute Both
      ⎕EC     Execute Controlled
      ⎕ENV    ENvironment Variables
      ⎕ES     Event Simulate
      ⎕EX     EXpunge
      ⎕FIO    File I/O
      ⎕FX     FiX
      ⎕INP    INPut from script
      ⎕NA     Name Association
      ⎕NC     Name Class
      ⎕NL     Name List
      ⎕SI     State Indicator
      ⎕SQL    SQL functions
      ⎕SVC    Shared Variable Control
      ⎕SVO    Shared Variable Offer
      ⎕SVQ    Shared Variable Query
      ⎕SVR    Shared Variable Retraction
      ⎕SVS    Shared Variable State
      ⎕STOP   STOP vector
      ⎕TF     Transfer Form
      ⎕TRACE  TRACE vector
      ⎕UCS    Universal Character Set (aka. Unicode)
       

      Bad UTF8 sequence start at LineInput.cc:987
Bad UTF8 sequence start at LineInput.cc:987

( ---- If you enter an incorrect ALT-key sequence, you might get the  )
( ---- above error message.  Don't worry about it, just carry on...   )


      ⎕SQL 'sfsfs'

( --- Above, if you enter a bogus command to Quad-SQL, you get the SQL help...)

Available function numbers:
type  ⎕SQL[1] file      - open a database file, return reference ID for it
      ⎕SQL[2] ref       - close database
query ⎕SQL[3,db] params - send SQL query
query ⎕SQL[4,db] params - send SQL update
      ⎕SQL[5] ref       - begin a transaction
      ⎕SQL[6] ref       - commit current transaction
      ⎕SQL[7] ref       - rollback current transaction
      ⎕SQL[8] ref       - list tables
ref   ⎕SQL[9] table     - list columns for table


( ---- Ok, so now, I try to open the SQLite3 database I just created... )
( ---- All this below is wrong... :)  -------------------------------   )

      ⎕SQL[1] mclnotes.db
VALUE ERROR
      ⎕SQL[1]mclnotes.db
                      ^
      ⎕SQL[1] 'mclnotes.db'
DOMAIN ERROR+
      ⎕SQL[1]'mclnotes.db'
      ^     ^
       1 ⎕SQL[1] 'mclnotes.db'
VALUE ERROR+
      1 ⎕SQL[1]'mclnotes.db'
      ^
        
        ⎕SQL[1] './mclnotes.db'
DOMAIN ERROR+
      ⎕SQL[1]'./mclnotes.db'
      ^     ^
      
      ⎕SQL[1] 'mclnote.db'
DOMAIN ERROR+
      ⎕SQL[1]'mclnote.db'
      ^     ^
      ⎕SQL[1] './mclnote.db'
DOMAIN ERROR+
      ⎕SQL[1]'./mclnote.db'
      ^     ^
      'sqlite3' ⎕SQL[1] './mclnote.db'
VALUE ERROR+
      'sqlite3' ⎕SQL[1]'./mclnote.db'
      ^

( ---- end of my wrong stuff that did not work!  Don't be discouraged...          )
( ---- you have to tell Quad-SQL command the type of database you want to open... )
( ---- once you open the database correctly, it will return a "reference number"  )
( ---- which the documentation carefully indicates as "ref" :) ...                )  


      'sqlite' ⎕SQL[1] './mclnote.db'
0

( ---- Ok, Success!  The database in local user directory has been opened ...)
( ---- Your reference handle to the database is "0" or the number zero ...   )
( ---- This command below Quad-SQL[8] displays the tables in the database ...)
( ---- You use the "reference number" to tell the Quad-SQL command which     )
( ---- database to refer to ...                                              )

      ⎕SQL[8] 0
 notes

( ---- Now, we can select all the contents of the "notes" table ... )


      'select * from notes' ⎕SQL[3,0]
SYNTAX ERROR
      'select * from notes' ⎕SQL[3,0]
      ^                         ^
      
( ---- What went wrong?  We forgot to include some paramter number.     )
( ---- When we include a parameter number, the SELECT statement works.  )


      'select * from notes' ⎕SQL[3,0] 0
 This is the first test note.  20201205
 This is the second test note. 20201205
      
( ---- Experimentation, confirms that this parameter number can be anything...)

      'select * from notes' ⎕SQL[3] 0
RANK ERROR+
      'select * from notes' ⎕SQL[3]0
      ^                           ^
      'select * from notes' ⎕SQL[3,1] 0
DOMAIN ERROR+
      'select * from notes' ⎕SQL[3,1]0
      ^                             ^

( ---- The database reference number is the second element of the Quad-SQL[3] )
( ---- system command vector, which is very curious, but such is life..       )

      'select * from notes' ⎕SQL[3,0] 1
 This is the first test note.  20201205
 This is the second test note. 20201205

( ---- The parameter to the Quad-SQL[3,dbrefnum] command can be anything ...  )
( ---- Below, we make it '234', and the command works.                        )

      'select * from notes' ⎕SQL[3,0] 234
 This is the first test note.  20201205
 This is the second test note. 20201205


( ---- But, if we fail to include this parameter number, then the command fails... )

      'select * from notes' ⎕SQL[3,0]    
SYNTAX ERROR
      'select * from notes' ⎕SQL[3,0]
      ^                         ^

( ---- Here, we make it '4564435', and the SELECT statement works correctly...  )

      'select * from notes' ⎕SQL[3,0] 4564435
 This is the first test note.  20201205
 This is the second test note. 20201205

( ---- We can make the parameter here iota-zero, which is NULL.  Still works... )

      'select * from notes' ⎕SQL[3,0] ⍳0     
 This is the first test note.  20201205
 This is the second test note. 20201205
      

( ---- Ok, so now we close the SQL database, using Quad-SQL[2], dbrefnum=0 ...  )


      ⎕SQL[2] 0


( ---- Since we closed the SQL database, any attempt to SELECT from it fails... )


      'select * from notes' ⎕SQL[3,0] ⍳0
DOMAIN ERROR+
      'select * from notes' ⎕SQL[3,0]⍳0
      ^                              ^

( ---- Ok, so lets re-open the database....    )

      
      'sqlite' ⎕SQL[1] './mclnote.db'
0

( ---- The Quad-SQL[1] command opens the database "mclnote.db" in local directory...)
( ---- And below, we run the SELECT against "notes" again, to get all the data ...  )

      'select * from notes' ⎕SQL[3,0] ⍳0
 This is the first test note.  20201205
 This is the second test note. 20201205

( ---- Now, lets put the data from the SQL database, into an APL variable, so we   )
( ---- can chop it up and/or scan out data elements from within the raw data  ...  )


      data ← 'select * from notes' ⎕SQL[3,0] ⍳0

( ---- We created an APL workspace variable called "data", and we can check the    )
( ---- dimensions of that variable, using the APL "rho" operator ...               )

      ⍴data
2 2

( ---- APL says the variable "data" is a 2 by 2 matrix ...   )
( ---- This APL uses nested arrays, which works as follows: The first row and the    )
( ---- element of the "data" variable is the first data-element of the "notes" table.)

      data[1;1]
 This is the first test note.

( ---- So, data[1;1], is just the first text string   ...                        )
( ---- We can use the "rho" operator to query the dimensions of this element ... )


      ⍴data[1;1]

( ---- Oops, no we can't.  This "nested-array" stuff requires that we "disclose" first.)
( ---- checking the rho (dimensions) of first row, first column of "data" returns as a )
( ---- scalar, which has no dimensions.  Checking the dimensions of a single number,   )
( ---- just returns a NULL result.  )

      ⍴data[1;1]

( ---- To actually get at the string of text, you have to "disclose" the stuff that  )
( ---- is "nested" inside row 1, column 1 of APL variable "data" ...                 )
( ---- The disclose operator, "⊃" is a symbol from "set theory", and you can make it )
( ---- on the APL keyboard with ALT(right)-x.                                        )

      ⍴ ⊃data[1;1]
28

( ---- Now, the "rho" operator (which is ALT(right)-r), gives the dimensions of the  )
( ---- text string in the first row of the "notes" table.                            )
( ---  And now we can chop up and/or search this text string.

      ⍴ ⊃data[1;1]
28
       7↑ (⊃data[1;1])
This is

( ---- In the above example, we extracted the first seven characters from the
( ---- first row in the SQL datatable "notes", which is a variable called "data"
( ---- in our APL workspace.  Note the workspace is not named yet.  We can name
( ---- the workspace and save it... )

      )wsid
IS CLEAR WS
      
( ---- We use ")vars" to query workspace variables, and ")fns" to list names of )
( ---- workspace functions (programs), but there are none here (yet...)         )

      )vars
data
      
      )fns
      
      data
 This is the first test note.  20201205
 This is the second test note. 20201205
      
      )wsid SQLEXAMPLE
WAS CLEAR WS
      )wsid
IS SQLEXAMPLE
      )save

( ---- Trying to SAVE the APL workspace failed, probably some default permission )
( ---- on the "workspace" subdirectory is wrong. So, just save it explicitly to  )
( ---- the user-directory on the Linux-box...                                    )

Unable to )SAVE workspace 'SQLEXAMPLE'. Permission denied
      
      )wsid /home/mcl/SQLEXAMPLE
WAS SQLEXAMPLE
      
      )wsid
IS /home/mcl/SQLEXAMPLE
      )save
2020-12-08  05:57:05 (GMT-5) /home/mcl/SQLEXAMPLE

( ---- now, the ")save" command worked.  )
( ---- Let's close the SQL database...   )

( ---- We check status of the SQL database, with ⎕SQL[8] and db-reference number.   )
( ---- This ⎕SQL command will display the data tables in the database ...           )
 

       ⎕SQL[8] 0
 notes

( ---- The Quad-SQL[9] command lists the column names in the "notes" table ... )       

      0 ⎕SQL[9] 'notes'
 text         
 date INTEGER
      
( ---- And the ⎕SQL[2] command, with the database reference number as parameter, )
( ---- will close the SQLite database   ...                                      )

      ⎕SQL[2] 0

( ---- Exit the GNU-APL with ")off" APL command ... )

      )off

Goodbye.

( ---- Return to Linux command-line, and confirm the APL workspace file was created...)

[mcl@l2-centos74 ~]$ ls SQL* -v
SQLEXAMPLE  SQLEXAMPLE.bak


( ---- We can also confirm the database file is present and accounted for...  :)     )

[mcl@l2-centos74 ~]$ ls mclnote* -l
-rw-r--r--. 1 mcl mcl 2048 Dec  5 18:04 mclnote.db
[mcl@l2-centos74 ~]$
[mcl@l2-centos74 ~]$
 

--------- End of Example GNU-APL Session Showing Example Query of SQL database ------- 

(More Notes to follow here...)

 
I will try to provide more examples of using GNU-APL, in the next while.