ŒIC Insert into Class


The dyadic system function ŒIC allows you to insert existing functions and/or variables into a class. It is particularly useful for converting older APL systems into object-oriented form.

Example:


      'Point' ŒIC ŒBOX 'X Y MOVE'

The left argument is a character vector containing the name of a new or existing class. If you specify a new class, it will be created. If you want the new class to inherit from an existing class, you can follow the class name by a colon and the name of the parent class.

The right argument is a matrix of the names of the global functions, operators and variables which you want to insert into the class, padded to the right with blanks if necessary. If there is only one name, the right argument can be a character vector. If the right argument is an empty vector, the class will be created but no members will be inserted into it. The named items will be transferred into the class as follows:

Of course, you can alter the attributes of the members of the class later on by using the class editor, for example if you want to make one of the properties read-only.

Note that the existing global definition of the inserted functions, operators and variables will be deleted, i.e. the operation moves rather than copies the items into the class. If the name corresponds to an existing member of the class, the existing member will be overwritten.

The explicit result of ŒIC is a boolean vector with one element per name, with a value of 1 if the corresponding member was successfully inserted into the class, and 0 if it was not. (It will fail if the name is invalid, or is the name of something other than an operator, function or variable, or if a variable contains class or object references).

In this example, we start with a workspace with a few variables and functions:

      Subject„''
      Sender„'Charles Barker'
      Text„''
      ’Message B
[1]   Text„B
[2]   ’
      ’R„Length
[1]   R„½Text
[2]   ’
      )FNS
Length  Message
      )VARS
Sender  Subject Text

Now we insert all the existing functions and variables into a new class called Message. Note that the existing function Message becomes the Constructor of the new class:

      'Message' ŒIC ŒNL 2 3
1 1 1 1 1
      )FNS
      )VARS
      )CLASSES
Message
      ŒCR 'Message'
Message {
Text„''
Subject„''
Sender„'Charles Barker'

’Message B
Text„B
’

’R„Length
R„½Text
’
}
      Message.ŒNL 2    © Public properties
Sender
Subject
Text
      Message.ŒNL 3    © Public methods
Length
      Message.ŒNL 10   © Constructor
Message

Finally, we create another class EMail which inherits from Message, and adds an extra uninitialized property Recipient:

      'EMail:Message' ŒIC 'Recipient'
1
      ŒCLASS EMail
{EMail} {Message}
      )CLASSES
EMail   Message

Topic: APLX Help : Help on APL language : System Functions & Variables : ŒIC Insert into Class
[ Previous | Next | Contents | Index ]