Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕CALL Call external static method
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

⎕CALL Call external static method


The dyadic system function ⎕CALL allows you to call a 'static' method (or access a static property) in an external environment such as .Net or Java. A 'static' method is a member of a class which can be called without needing to create an instance of the class.

The left argument is a character vector which specifies the external environment in which you want to make the call, in the same format as for ⎕NEW. The right argument is either a character vector containing the name of the method (if there are no arguments or this is a property), or a nested vector where the first element is the name of the method and subsequent elements are the arguments to the method. The explicit result is whatever the external environment returns as the result of the call; it may be an ordinary array of data, or a reference to an object in the external environment.

For example, the .Net System.DateTime class contains a static property Now which returns the current date and time as an instance of the DateTime class:

      '.net' ⎕CALL 'System.DateTime.Now'
[.net:DateTime]
      TS←'.net' ⎕CALL 'System.DateTime.Now'
      TS.ToString
10/10/2007 12:06:42

It also contains a static method IsLeapYear which takes an integer argument representing a year, and returns a Boolean value indicating whether the year is a leap year:

      '.net' ⎕CALL 'System.DateTime.IsLeapYear' 1994
0
      '.net' ⎕CALL 'System.DateTime.IsLeapYear' 1996
1

Similarly, in Java, to create a TimeZone object we need to call a static method in the TimeZone class:

      tz←java ⎕CALL 'java.util.TimeZone.getTimeZone' 'America/Los_Angeles'
     
      ⍝ Does this time zone use daylight savings time?       
      tz.useDaylightTime
1
      
      ⍝ What is the time zone called with and without daylight savings time?    
      tz.getDisplayName 1 (tz.LONG)
Pacific Daylight Time
      tz.getDisplayName 0 (tz.LONG)
Pacific Standard Time
 

Using a class reference to call static methods

Another way of calling a static method of an external class is to get a reference to the class itself (usually by calling ⎕GETCLASS), and use that to access the method using dot notation. For example, in the above Java example we could have called the getTimeZone method as follows:

      tzclass←'java' ⎕GETCLASS 'java.util.TimeZone'
      tz←tzclass.getTimeZone 'America/Los_Angeles'

Topic: APLX Help : Help on APL language : System Functions & Variables : ⎕CALL Call external static method
[ Previous | Next | Contents | Index | APL Home ]