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

www.microapl.co.uk

⎕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:

  • If the name corresponds to an existing function or operator, it will become a public method of the class.
  • If the name is the name of a function and is the same as the name of the class being created (i.e. the left argument), it will become the Constructor for the class.
  • If the name corresponds to an existing variable, it will become a public, read-write instance property of the class, with the default value of the property being the current value of the variable. However, the variable must not contain a class or object reference.
  • If the name is currently undefined, it will become an uninitialized, public, read-write instance property of the class.

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 | APL Home ]