Using .NET from APLX
APLX includes support for object-oriented programming (OOP), combining the OOP features familiar from other languages with APL's ability to handle arrays.
As well as writing your own APL classes and using them to create objects, you can also use APLX to create objects from classes written in other OOP languages like C#, Visual Basic .NET, Java and Ruby. This allows you to use the many powerful object libraries written in other languages from APLX.
A simple example of using .NET classes from APL
Classes written in .NET or Java are known in APLX as external classes. Creating an object using an external class is very straightforward - you just specify the language name as the left argument of the ⎕NEW system function. For example:
⍝ Create a new DateTime object using .NET
NETDATE←'.net' ⎕NEW 'System.DateTime' 2008 12 25 9 32 3
⍝ Internally APLX just stores it as an object reference in NETDATE
NETDATE
[.net:DateTime]
⍝ We can call various .NET methods from APLX
NETDATE.ToString
25/12/2008 09:32:03
NETDATE.get_Month
12
⍝ Adding 12 months produces a new DateTime Object...
NETDATE.AddMonths 12
[.net:DateTime]
(NETDATE.AddMonths 12).ToString
25/12/2009 09:32:03
⍝ Since APL is an array language, we can do this sort of thing:
⍝ (Here we add each of 1,2,3,4,5,6 to the NETDATE object, which creates 6 new
⍝ objects. We then reshape to a 6x1 matrix for a neater display. The final
⍝ call to ToString acts on each object in the matrix)
(6 1⍴NETDATE.AddMonths ¨⍳6).ToString
25/01/2009 09:32:03
25/02/2009 09:32:03
25/03/2009 09:32:03
25/04/2009 09:32:03
25/05/2009 09:32:03
25/06/2009 09:32:03
Further Examples
Here are some more interesting examples of using .NET classes from APLX:
Create a simple GUI window in .NET
Another GUI example demonstrating the use of buttons and text boxes
List the fonts installed on your system
Using Windows Presentation Foundation (WPF) from APLX to create rich user interfaces
Sending e-mail. How to send e-mails using SMTP servers which may require authentication
Using FTP to send and receive files. FTP examples using Microsoft's System.Net.WebRequest class
Computing a Message Digest Hash (MD5) used in cryptography
Calling your own C# class libraries. How to create and call a C# class library.
Compiling C# code from APLX. Sometimes useful for creating glue code.
Using the LINDO API optimization library from APLX.
APL Wiki