Transfering code in APLX

(Hide table-of-contents)

Overview

This page shows how to transfer code in workspaces or component files, including overlays, and read them back. This can be used to take backups or go back to previous versions of the interpreter.

It can also be used to import/export code from/to other interpreters.

Methods

There are at least 2 ways to export/import code in APLX:

1. Using variable record length EXTENDED files

This format produces a representation of just about everything in the workspace. Translation of code from other APLs is limited but possible. For example, code imported from another APL might use Quad functions unavailable in APLX. It can often be translated to use the equivalent APLX functions.

2. Using fixed record length ATF files

This format produces a representation of each function and variable in the workspace. It does not include overlays. It cannot perform translation of code when importing code from other APLs.

Technique

EXTENDED files

This format was introduced to deal with the 5 major APLs of the time (1990s): Sharp APL, APL*PLUS, APLX, APL2 and Dyalog APL. It lays the representation of each variable or function in the ws, system variables included, onto variable length records. It can deal with overlays but because the code was created before the advent of classes those cannot be written out or read back in.

You need a special workspace to read in and write out the code. The workspace should be available here: xfrpc.aws.

ATF files

This format was introduced by IBM many years ago and has been supported by many other vendors, APLX included. It basically lays the representation of each object in the ws, system variables included, onto a number of 80 chars wide records in a file with extension ATF. It turns overlays into a numeric vector of length 0.

Note that the ATF file should be regarded as a binary file, not text. For example, the line-ending convention must be <CR><LF> (something which is apt to get changed when e-mailing ATF files between Windows and Macintosh systems, unless care is taken)

The system commands )IN and )OUT are used to import and export code in ATF format. No other software needs to be used.

Examples

Let's assume we have a workspace containing the following:

      title←'Big Application'
      ⎕fx ⊃'r←avg v' 'r←(sum v)÷⍴,v'
avg
      ⎕fx ⊃'z←sum x' 'z←+/x'
sum
      3 ⎕ov ov←0 ⎕ov 2 3⍴'avgsum'
avg
sum
     ⍝ erase those functions so they exist only in the overlay (="package")
      )ERASE sum avg

      mat←.01×?2 5⍴10000
      record←'Joe Blough' 19550209 (.22 .45 1.2 1.56)

      ∇z←(f power n)  x
[1]   z←x
[2]   :While n>0  ⋄  z←f z  ⋄  :End

      ∇l←list
[1]   l←l,⎕nc l←⎕nl 2 3 4 5
[2]   ∇
      list
list   3
mat    2
ov     2
power  4
record 2
title  2

      )WSID myws

Using the EXTENDED format

To write the workspace to file, including ⎕IO, ⎕CT, ⎕PW and ⎕LX (assume the workspace used to do the transfer is in \apl\xfrpc) do

      )COPY  \apl\xfrpc
      ∆xfrto '\tmp\mycode'
* XFR version  3.09
10 objects transferred

To write specific items put them before the file name (here 'title' and <power>):

     'title power'  ∆xfrto '\tmp\my2objs'
* XFR version  3.09
2 objects transferred

To read the workspace back:

      )LOAD \apl\xfrpc
      ∆xfrfrom '\tmp\mycode.xpw  /replace'  ⍝ note the XPW extension, necessary when importing APLX code
* XFR version 3.09
APX3.09 20100217 34458; WS=myws
10 objects defined
      list
∆xfrfrom 3
list     3
mat      2
ov       2
power    4
record   2
title    2
      ⍝ there is still a trace of the ws we must get rid of:
      )FNS
∆xfrfrom     list
      )ERASE  ∆xfrfrom

      ⍝ overlays are rebuilt
      3 ⎕ov ov
sum
avg

To read only some groups

      )load 0 xfrpc
SAVED  2010-02-17 4.03.53
      ∆xfrfrom '\tmp\mycode.xpw  /obj=cp'  ⍝ bring in only character variables (c) and overlays (p for Packages)
* XFR version  3.09
APX3.09 20100217 40418; WS=myws
* "⎕lx:C" not redefined
2 objects defined
      )ERASE ∆xfrfrom
      ⎕nl 2 3 4 5
ov
title

Component files can be transferred too.

      '\tmp\ft1' ⎕fcreate 10
      title ⎕fappend 10
1
      ov  ⎕fappend 10
2
      mat ⎕fappend 10
3
      (1 3⍴0 ¯1) ⎕fstac 10
      ⎕fsize 10
1 4 3584 0 0
      ∆xfrto '\tmp\exf1   /file=10'
* XFR version  3.09
3 cpts transferred with Access Matrix
      ∆xfrfrom '\tmp\exf1.xpf   /file=\tmp\new1'
* XFR version  3.09
4 objects defined
      '\tmp\new1' ⎕fstie 11
      ⎕fsize 11
1 4 3584 0 0
      ⎕fread 11 1
Big Application
      3 ⎕ov ⎕fread 11 2
sum
avg
      mat≡⎕fread 11 3
1
      ⎕frdac 11
0 ¯1 0

For details see http://www.milinta.com/xfrpc.htm.

Using the ATF format

To write the workspace to file do the following, or use the equivalent "Export..." option from the File menu.

      )OUT \tmp\mycode

To write specific items include them after the file name (here 'title' and <power>):

      )OUT \tmp\my2objs   title  power

To read the workspace back:

      )IN    \tmp\mycode
      ⍴⎕nl 2 3 4 5
6 6
      3 ⎕ov ov       ⍝ overlays are not rebuilt
DOMAIN ERROR
      3 ⎕ov ov
      ^

To read only some items

      )IN   \tmp\mycode  power  list
      ⍴⎕nl 2 3 4 5
2 5


CategoryAplx

APLXtransfer (last edited 2010-02-17 22:07:56 by DanBaronet)