Differences between revisions 5 and 6
Revision 5 as of 2014-02-02 19:38:49
Size: 3188
Editor: anonymous
Comment: create a new page by copying and modifying an existing one
Revision 6 as of 2014-02-02 20:11:31
Size: 4893
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was copied from HelloWorldTcpIp
= Hello World via TCP/IP =
## page was copied from HelloWorld
= Transferring code between APL suppliers in APL2000 =
Line 4: Line 4:
With just seven lines of code you can send and receive the Hello World message in the same session, between workspaces on the same machine, between machines on the same network or any machine connected to the internet. ~-<<SeeSaw(section="table-of-contents", show="true", seesaw="false", toshow="<<(Show>> table-of-contents)", tohide="<<(Hide>> table-of-contents)", speed="Slow")>>-~
<<TableOfContents>>
Line 6: Line 7:
These examples are written in APL+WIN to work on the local machine therefore they both refer to the ip address of the local host 127.0.0.1. They can be run as functions or simply typed in the same order as they appear below and executed sequentially in an active session. == Overview ==
This page shows how to transfer code in workspaces or component files and read them back. This can be used to take backups or go back to previous versions of the interpreter.
Line 8: Line 10:
To run between machines on a network or over the internet simply replace the ip address with that of the server machine in both functions and choose any port number outside that used by common services. It can also be used to import/export code from/to other interpreters.
Line 10: Line 12:
These functions are the essential bare bones and require more flesh putting on them to create robust communications systems but they serve to demonstrate the possibilities. == Methods ==
Line 12: Line 14:
Run as functions in the same session this is what you should see: There are at least 2 ways to export/import code in APL2000:

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 APL2000. It can often be translated to use the equivalent APL2000 functions.

2. Using fixed record length ATF files

This format produces a representation of each function and variable in the workspace. 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.

You need a special workspace to read in and write out the code. The workspace should be available here: [[attachment:xfrpc11.w3]].

''ATF'' files

This format was introduced by IBM many years ago and has been supported by many other vendors, APL2000 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.


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 user 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:
Line 14: Line 49:
      TcpServer
      TcpClient
Hello World
}}}
{{{
∇ TcpServer;socket;rc
                                                                                           
⍝Create a socket
socket←¯1↑⎕ni 'Socket'
                                                                                           
⍝Bind the socket on port 3000 and the ip address of the server machine
rc←socket ⎕ni 'Bind' 3000 '127.0.0.1'
                                                                                           
⍝Put the socket in listening mode
rc←socket ⎕ni 'Listen'
                                                                                           
⍝Create event handler to accept connection from client and return Hello World
rc←socket ⎕ni 'onAcceptNotify' 'rc←3⊃⎕ni "Accept" ◊ 0 0⍴rc ⎕ni "Send" "Hello World" "char"'
      title←'Big Application'
      ⎕fx ⊃'r←avg v' 'r←(sum v)÷⍴,v'
avg
      ⎕fx ⊃'z←sum x' 'z←+/x'
sum
      mat←.01×?2 5⍴10000
      record←'Joe Blough' 19550209 (.22 .45 1.2 1.56)
Line 33: Line 57:
      ∇l←list
[1] l←l,⎕nc l←⎕nl 2 3 4 5
[2] ∇
      list
avg 3
list 3
mat 2
record 2
sum 3
title 2

      )WSID myws
Line 36: Line 71:
=== 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
Line 37: Line 75:
      )COPY \apl\xfrpc
      ∆xfrto '\tmp\mycode'
* XFR version 3.11
10 objects transferred
}}}
To write specific items put them before the file name (here 'title' and 'mat'):
{{{
     'title mat' ∆xfrto '\tmp\my2objs'
* XFR version 3.11
2 objects transferred
}}}
To read the workspace back:
{{{
      )LOAD \apl\xfrpc
saved...
      ∆xfrfrom '\tmp\mycode.xsw /replace' ⍝ note the XSW extension, necessary when importing APL2000 code
* XFR version 3.11
APX3.11 20100217 34458; WS=myws
10 objects defined
      list
avg 3
list 3
mat 2
record 2
sum 3
title 2
}}}
To read only some groups
{{{
      )load \apl\xfrpc
SAVED ...
      ∆xfrfrom '\tmp\mycode.xpw /obj=c' ⍝ bring in only character variables (c)
* XFR version 3.11
APX3.09 20100217 40418; WS=myws
* "⎕lx:C" not redefined
3 objects defined
      ⎕nl 2
mat
record
title
}}}
⎕LX was not redefined because we did not add the /replace switch.
Line 38: Line 118:
∇ TcpClient;socket;hostaddress;service;rc
                                                                       
⍝Create a socket
socket←¯1↑⎕ni 'Socket'
                                                                       
⍝Create event handler to read incomming messages
rc←socket ⎕ni 'onReadNotify' '3⊃⎕ni "Recv" "char"'
                                                                       
⍝Connect the socket on port 3000 to the ip address of the server machine
rc←socket ⎕ni 'Connect' 3000 '127.0.0.1'
                      
Component files can be transferred too.
{{{
      '\tmp\ft1' ⎕fcreate 10
      title ⎕fappend 10
1
      record ⎕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.11
3 cpts transferred with Access Matrix
      ∆xfrfrom '\tmp\exf1.xpf /file=\tmp\new1'
* XFR version 3.11
4 objects defined
      '\tmp\new1' ⎕fstie 11
      ⎕fsize 11
1 4 3584 0 0
      ⎕fread 11 1
Big Application
      mat≡⎕fread 11 3
1
      ⎕frdac 11
0 ¯1 0
Line 51: Line 146:
Author: GrahamSteer
For details see [[http://www.milinta.com/xfrpc.htm]].


=== Using the ATF format ===

To write the workspace to file do the following
{{{
      ]OUT \tmp\mycode
}}}
You cannot write specific items, only the entire workspace.

To read the workspace back:
{{{
      ]IN \tmp\mycode
      ⍴⎕nl 2 3
6 6
}}}
Line 54: Line 166:
CategoryHelloWorld - CategoryApl2000 CategoryAplx CategoryAplx

Transferring code between APL suppliers in APL2000

(Hide table-of-contents)

Overview

This page shows how to transfer code in workspaces or component files 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 APL2000:

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 APL2000. It can often be translated to use the equivalent APL2000 functions.

2. Using fixed record length ATF files

This format produces a representation of each function and variable in the workspace. 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.

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

ATF files

This format was introduced by IBM many years ago and has been supported by many other vendors, APL2000 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.

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 user 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
      mat←.01×?2 5⍴10000
      record←'Joe Blough' 19550209 (.22 .45 1.2 1.56)

      ∇l←list
[1]   l←l,⎕nc l←⎕nl 2 3 4 5
[2]   ∇
      list
avg    3
list   3
mat    2
record 2
sum    3
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.11
10 objects transferred

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

     'title mat'  ∆xfrto '\tmp\my2objs'
* XFR version  3.11
2 objects transferred

To read the workspace back:

      )LOAD \apl\xfrpc
saved...
      ∆xfrfrom '\tmp\mycode.xsw  /replace'  ⍝ note the XSW extension, necessary when importing APL2000 code
* XFR version 3.11
APX3.11 20100217 34458; WS=myws
10 objects defined
      list
avg    3
list   3
mat    2
record 2
sum    3
title  2

To read only some groups

      )load \apl\xfrpc
SAVED  ...
      ∆xfrfrom '\tmp\mycode.xpw  /obj=c'  ⍝ bring in only character variables (c) 
* XFR version  3.11
APX3.09 20100217 40418; WS=myws
* "⎕lx:C" not redefined
3 objects defined
      ⎕nl 2 
mat
record
title

⎕LX was not redefined because we did not add the /replace switch.

Component files can be transferred too.

      '\tmp\ft1' ⎕fcreate 10
      title ⎕fappend 10
1
      record  ⎕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.11
3 cpts transferred with Access Matrix
      ∆xfrfrom '\tmp\exf1.xpf   /file=\tmp\new1'
* XFR version  3.11
4 objects defined
      '\tmp\new1' ⎕fstie 11
      ⎕fsize 11
1 4 3584 0 0
      ⎕fread 11 1
Big Application
      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

      ]OUT \tmp\mycode

You cannot write specific items, only the entire workspace.

To read the workspace back:

      ]IN    \tmp\mycode
      ⍴⎕nl 2 3 
6 6


CategoryAplx CategoryAplx

Transfer code (last edited 2017-02-16 19:38:28 by KaiJaeger)