APLX Help : Help on APL language : System Functions & Variables : ⎕CR Canonical Representation
|
|||||||||
![]() |
|
||||||||
Converts a user-defined function, operator, method, or class into a character matrix or vector. The name of the item to be converted to text form is the right argument of
The matrix or vector shows the lines of the function, operator, method or class, with line numbers omitted. It has the characteristics of any object composed of characters. You can, for example, use indexing to alter its elements, or use the MATRIX←⎕CR 'DT' (for a matrix result) VECTOR←1 ⎕CR 'DT' (for a simple delimited vector result) VECTOR←2 ⎕CR 'DT' (for a nested vector result) See also Canonical representation of a class⎕CR can also be used to convert an entire class to text form. In this case, the right argument should be a class name. The format of the result is as follows:
For example: ⎕CR 'Point' Point; IncSerial;serial { Z←0 Y←0 X←0 {serial←0} {CATEGORY←←'Geometric'} ∇IncSerial ⍝ Increment serial number serial←serial+1 ∇ ∇R←Mag ⍝ Return magnitude (distance from origin) R←+/(X,Y,Z)*2 R←R*0.5 ∇ ∇Point B ⍝ Constructor for Class B. Optionally set up X Y Z :If 0≠⍴B (X Y Z)←B :EndIf IncSerial ∇ ∇R←GetSerial R←serial ∇ } In the above example, the class Point has three instance properties (X Y and Z), all initialized to 0. It has two class-wide properties serial and CATEGORY. CATEGORY is a read-only property, so is initialized with a double assignment arrow. The serial property is private (i.e. not accessible from outside the class), so it is localized in the class header. The class has three ordinary methods (of which one, IncSerial is private), and a constructor (identifiable by the fact that it has the same name as the class). If a second class MovingPoint inherits from Point, and adds a new property VELOCITY, then you might have: ⎕CR 'MovingPoint' MovingPoint : Point { VELOCITY←0 } This shows the use of the colon character in the header, to indicate that MovingPoint inherits from Point. Canonical representation of a single method from a class
⎕CR 'Point.Mag' R←Mag ⍝ Return magnitude (distance from origin) R←+/(X,Y,Z)*2 R←R*0.5 |
|||||||||
APLX Help : Help on APL language : System Functions & Variables : ⎕CR Canonical Representation
|
Copyright © 1996-2010 MicroAPL Ltd