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:


CategoryAplx CategoryDotNet

APLXExamplesDotNet (last edited 2010-03-31 13:19:39 by SimonMarsden)