System functions (Quad functions)
The built-in System functions extend the power of APLX by providing easy-to-use cross-platform tools for achieving many common and more complex tasks.
In general, the same system functions are supported by all versions of APLX, so that code written using them will run under Windows, Macintosh and Linux. However you should note that APL interpreters from other vendors may implement a different set of functions which is often much less rich.
There are too many system functions to cover in detail here, but here are just a few...
System functions for manipulating data
There are a number of system functions that manipulate data, including:
For reshaping vectors as matrices (and visa versa) a system function,
⎕BOX 'COGS WHEELS SPRINGS' COGS WHEELS SPRINGS
and for deleting spaces from character data, there's another system variable,
⎕DBR ' WIDE OPEN SPACES' WIDE OPEN SPACES
Another function is
MANIFESTO ← 'ALL ANIMALS ARE EQUAL' ⎕SS (MANIFESTO; 'ARE'; 'ARE NOT') ALL ANIMALS ARE NOT EQUAL.
There are further details and examples of these three system functions and others in the APLX Language Manual.
System functions for reading and writing files
APLX includes a large number of functions for reading and writing files.
Examples of native file functions
1. To read an existing text file into an APL variable:
'C:\Documents\MyFile.txt' ⎕NTIE 1 TEXT ← ⎕NREAD 1 4 ⎕NUNTIE 1
The whole of the specified file is read into the APL variable
2. To create a new text file containing the text 'Hello new file':
'C:\Documents\MyNewFile.txt' ⎕NCREATE 1 'Hello new file' ⎕NWRITE 1 4 ⎕NUNTIE 1
3. To write out a table of data as a web page:
SalesData ⎕EXPORT 'C:\Documents\SalesData.html' 'html'
4. To read a table of spreadsheet data in Comma-Separated Variable (CSV) format:
data ← ⎕IMPORT 'C:\Documents\SpreadsheetData.csv' 'csv'
Some more useful system functions
For full details of all system functions and many more examples, see the APLX Language Manual.
1. To display a chart of sales data:
SALES ← ?3 12⍴20 ⎕CHART SALES
Here we generate some random sales data and display it in chart form in a new window:
2. To create a new window containing an Edit field.
DEMO ← '⎕' ⎕NEW 'Dialog' ⋄ DEMO.title ← 'Edit Example' DEMO.myEdit.New 'Edit' ⋄ DEMO.myEdit.where ← 2 1 DEMO.myEdit.text ← 'Some sample text'
This will create the following window (the appearance will be different if you try this on a Macintosh or Linux version of APLX):
3. To issue a Windows command to list the contents of a folder:
⎕HOST 'CMD /C dir' Volume in drive C has no label. Volume Serial Number is 07D0-0B11 Directory of C:\aplx\ws 20/06/2001 19:13 [DIR] . 20/06/2001 19:13 [DIR] .. 05/09/2001 16:43 17,792 JIM.aws 05/09/2001 17:06 574 EXPLORE.atf 30/07/2001 19:49 17,828 QNA.aws 3 File(s) 39,313 bytes 2 Dir(s) 14,797,176,832 bytes free
5. Here we use SQL to connect to a database and read a table of data into the APL variable
1 ⎕SQL 'connect' 'aplxodbc' 'DSN=BigCorpDB;PWD=xx;UID=root;' 0 0 0 0 1 ⎕SQL 'do' 'use bigcorp' 0 0 0 0 fields ← 'FIRSTNAME,LASTNAME,SEX,EMAIL,EMPLOYEENUMBER,DEPARTMENT' (rc errmsg employeeData) ← 1 ⎕SQL 'do' 'select',fields,'from employeedata' ⍴employeeData 350 6 5 6↑employeeData Bert Brown M Bert.Brown@bigcorp.com 1 C Claude Ptolemy M Claude.Ptolemy@bigcorp.com 2 B Zak Smith M Zak.Smith@bigcorp.com 4 E Sian Jones F Sian.Jones@bigcorp.com 5 C Eric Smallhorse M Eric.Smallhorse@bigcorp.com 6 C
Copyright © 1996-2008 MicroAPL Ltd