Скачать презентацию Object Orientation in Dyalog APL Implementation details V Скачать презентацию Object Orientation in Dyalog APL Implementation details V

b6306b8ac861f6bbe421243eb07104c3.ppt

  • Количество слайдов: 94

Object Orientation in Dyalog APL Implementation details V 1. 01 Object Orientation in Dyalog APL Implementation details V 1. 01

Implementation details Dyalog implemented Object Orientation (OO) in APL. New territory was uncovered when Implementation details Dyalog implemented Object Orientation (OO) in APL. New territory was uncovered when venturing into OO. In keeping with the dynamic nature of APL a lot of questions were raised. And many were answered.

Implementation details Classes' system functions/commands All Interfaces, Classes & some Namespaces (ICN) come in Implementation details Classes' system functions/commands All Interfaces, Classes & some Namespaces (ICN) come in scripted form. • ⎕SRC: Just like ⎕NR returns the representation of a function in nested form, ⎕SRC returns the representation of an ICN in nested form. • ⎕FIX: Just like ⎕FX creates a function, ⎕FIX creates an ICN. • )ED ∘Interf /○Cl/ ⍟Ns

Implementation details Classes' system functions/commands • • • monadic ⎕CLASS returns the tree of Implementation details Classes' system functions/commands • • • monadic ⎕CLASS returns the tree of references dyadic ⎕CLASS casts an instance into another ns )CLASSES lists classes in the namespace : Implements identifies what it implements ⎕DF change the display form of a NS )INTERFACES lists all interfaces in the current namespace

Implementation details Classes: A class can implement one or more interfaces. An interface describes Implementation details Classes: A class can implement one or more interfaces. An interface describes what it should do. The class describes how it should be done.

Implementation details This maneuvering interface describes what has to be done with a machine: Implementation details This maneuvering interface describes what has to be done with a machine: )ed ∘maneuvering It does NOT specify how it should be done.

Implementation details This car class implements maneuvering: VW←⎕ new Car VW. Gas. Pedal 60 Implementation details This car class implements maneuvering: VW←⎕ new Car VW. Gas. Pedal 60 Going up to 60 (maneuvering ⎕ class VW). Steer 140 Heading NW (maneuvering ⎕ class VW). Accellerate 120 Going up to 120 VW. Gas. Pedal 100 Going down to 100 VW. Break. Pedal 1 Breaking. . .

Implementation details This plane class implements maneuvering: C 172←⎕ new Plane C 172. Stick Implementation details This plane class implements maneuvering: C 172←⎕ new Plane C 172. Stick 23 Heading 20 C 172. Handle 200 Going up to 200 C 172. Stick 23 11 Climbing, Heading 20 (maneuvering ⎕ class C 172). Steer 210 Heading 210 (maneuvering ⎕ class C 172). Slow. Down 20 Flaps 20 degrees

Implementation details Members' system functions/commands Members are Fields (variables), Methods (functions), properties and other Implementation details Members' system functions/commands Members are Fields (variables), Methods (functions), properties and other classes. • ⎕ INSTANCES lists the instances of a class • ⎕ NEW creates an instance • Special Property cases • Triggers

Implementation details Properties In C# they are implemented as a pair of functions. In Implementation details Properties In C# they are implemented as a pair of functions. In APL the 'name←' case is handled naturally. It is called the SIMPLE case and is the default. A second case where indexing is made using any object (as opposed to numbers) is also handled easily. This is the KEYED case. The array nature of APL introduced a notion of NUMBERED property. This is the third case.

Implementation details Properties: SIMPLE case When a property is set, its SET function is Implementation details Properties: SIMPLE case When a property is set, its SET function is called. When retrieved, its GET function is called. The argument is a namespace containing the name of the property (Name) and its value (New. Value).

Implementation details Properties: KEYED case ‘pa’ also contains the indices of the property (Indexers). Implementation details Properties: KEYED case ‘pa’ also contains the indices of the property (Indexers). The property MUST be used with [brackets] and their contents cannot be elided. Their shape must conform to APL rules for assignment and result.

Implementation details Properties: NUMBERED case The set/get function call is made, ONCE per index. Implementation details Properties: NUMBERED case The set/get function call is made, ONCE per index. ‘pa’ also contains the index to deal with (Indexers). It may be used with indices. The SHAPE function is used to check and generate indices. Their shape must conform to APL rules for assignment and result.

Implementation details Default Properties There can be only one. If a default property exist, Implementation details Default Properties There can be only one. If a default property exist, [indexing] can be done directly on the instance. Doing instance[index] is the same as instance. def. Prop[index] If a property is the default then using “squad indexing” applies to the whole property

Implementation details Multiple Properties If several properties are similar the definition statement may include Implementation details Multiple Properties If several properties are similar the definition statement may include several names separated by commas, like this: : Property P 1, P 2, P 3 The Get/Set functions’ argument will contain the name in ‘Name’ (as in arg. Name)

Implementation details Triggers t←⎕NEW trigger 1 ('Dan' 'Baronet') Full name is Dan Baronet t. Implementation details Triggers t←⎕NEW trigger 1 ('Dan' 'Baronet') Full name is Dan Baronet t. First. Name←'Daniel' Full name is Daniel Baronet

Implementation details Inheritance: new system functions/commands • • • : Base used to call Implementation details Inheritance: new system functions/commands • • • : Base used to call base class constructor ⎕BASE used to call base class functions override/able Destructors are called when the instance is destroyed ⎕NC/⎕NL have been extended ⎕THIS is the same as (⎕NS''). ## : implements, : access can be GUI based (ex: : Class F: ‘form’) : include

Implementation details: : Base pet←⎕ NEW Collie ‘Rex’ pet. ⎕ nl -2 Name Nlegs Implementation details: : Base pet←⎕ NEW Collie ‘Rex’ pet. ⎕ nl -2 Name Nlegs Sounds Type pet. (Name Type) Rex canis familiaris

Implementation details: ⎕Base ⎕ Base is used to call base function like : base Implementation details: ⎕Base ⎕ Base is used to call base function like : base is used to call the constructor with an argument. This is used when the base function is shadowed by a class member. As in s 1←⎕ new square s 1. surface 20 400

Implementation details Override and overridable These concepts allow a base class code to be Implementation details Override and overridable These concepts allow a base class code to be overridden. The following slides will explain this in more details.

Non-Based classes ⍝ M 1 calls its own M 2: (⎕ NEW A). M Non-Based classes ⍝ M 1 calls its own M 2: (⎕ NEW A). M 1 I am A ⍝ M 1 calls its own M 2: (⎕ NEW B). M 1 I am B

Non-Based classes Class A M 1 M 2 Class B M 2 ‘I am Non-Based classes Class A M 1 M 2 Class B M 2 ‘I am A’ ⍝ M 1 calls its own M 2: (⎕ NEW A). M 1 I am A M 2 ‘I am B’ ⍝ M 1 calls its own M 2: (⎕ NEW B). M 1 I am B

Based classes ⍝ M 1 calls its own M 2: (⎕ NEW B). M Based classes ⍝ M 1 calls its own M 2: (⎕ NEW B). M 1 I am A

Based classes Class A There is no M 1 in B so A’s (on Based classes Class A There is no M 1 in B so A’s (on which B is based) M 1 is used M 1 M 2 Class B: A M 2 ‘I am A’ M 2 ‘I am B’ ⍝ M 1 calls its own M 2: (⎕ NEW B). M 1 I am A

Overridden classes ⍝ M 1 calls its own M 2 because ⍝ it has Overridden classes ⍝ M 1 calls its own M 2 because ⍝ it has not been overridden: (⎕ NEW B). M 1 I am A

Overridden classes Class A There is no M 1 in B so A’s (on Overridden classes Class A There is no M 1 in B so A’s (on which B is based) M 1 is used M 1 M 2 Class B: A M 2 ‘I am A’ M 2 ‘I am B’ ⍝ M 1 calls its own M 2: (⎕ NEW B). M 1 I am A

Overridden classes ⍝ M 1 calls B’s M 2 because ⍝ it has been Overridden classes ⍝ M 1 calls B’s M 2 because ⍝ it has been overridden: (⎕ NEW B). M 1 I am B

Overridden classes Class A There is no M 1 in B so A’s (on Overridden classes Class A There is no M 1 in B so A’s (on which B is based) M 1 is used M 1 M 2 Class B: A M 2 ‘I am A’ M 2 ‘I am B’ ⍝ M 1 calls B’s M 2: (⎕ NEW B). M 1 I am B

Implementation details Destructors They are used to clean-up after an instance is destroyed: kk←⎕new Implementation details Destructors They are used to clean-up after an instance is destroyed: kk←⎕new life ‘Kong' King Kong is born )erase kk Kong is dead, long live the king.

Implementation details: ⎕NC/⎕NL extensions Those 2 system functions have been extended to deal with Implementation details: ⎕NC/⎕NL extensions Those 2 system functions have been extended to deal with the new objects. Since classes and instances are a type of namespace their basic classification is 9: ⎕NC ‘my. Class’ 9 To find their sub-class they need to be enclosed: ⎕NC ⊂ ‘my. Class’ 9. 4

Implementation details: ⎕NC/⎕NL extensions ⎕NL has also been extended to report all objects of Implementation details: ⎕NC/⎕NL extensions ⎕NL has also been extended to report all objects of a given sub-class: ⍴⍴⎕NL 9. 4 2 Furthermore, if one of the argument to ⎕NL is negative the result is returned in vector format: ⍴⍴⎕NL -9. 4 1

Implementation details: ⎕NC/⎕NL ⎕ NC/⎕ NL extensions ⎕ NL and ⎕ NC are symmetric Implementation details: ⎕NC/⎕NL ⎕ NC/⎕ NL extensions ⎕ NL and ⎕ NC are symmetric such that n∊⎕ NC ⎕ NL n and vn∊⎕ NL ⎕ NC¨vn ⍝ vn is a list of names

Implementation details: ⎕NC/⎕NL extensions ⎕NL and ⎕NC also apply to variables and functions. The Implementation details: ⎕NC/⎕NL extensions ⎕NL and ⎕NC also apply to variables and functions. The complete list is: 2 3/4 9 n. 1 Variable Traditional fn/op NS created by ⎕NS n. 2 Field D-fns or –op Instance (could be form) n. 3 Property Derived/Primitive n. 4 Class n. 5 Interface n. 6 External/shared External Class n. 7 External Interface

Implementation details: System commands To see vars or fields: fns or methods: classes: interfaces: Implementation details: System commands To see vars or fields: fns or methods: classes: interfaces: events: properties: use )vars )fns/methods )classes )interfaces )events )props

Implementation details: ⎕NC/⎕NL extensions ⎕NL also includes instance members when used with a negative Implementation details: ⎕NC/⎕NL extensions ⎕NL also includes instance members when used with a negative argument instance. ⎕NL -2. 2 ⍝ report all fields

Implementation details Types of Namespaces and their ⎕NC The first two already existed in Implementation details Types of Namespaces and their ⎕NC The first two already existed in V 10 • Regular NS 9. 1 • Forms 9. 2 • Instances 9. 2 (NOT 9. 3!) • Classes 9. 4 • Interfaces 9. 5

Implementation details: ⎕DF The default display form of a namespace is its path: ⎕←'t Implementation details: ⎕DF The default display form of a namespace is its path: ⎕←'t 1. s 1' ⎕NS '' #. t 1. s 1 We can change this using ⎕DF: t 1. s 1. ⎕df '(S 1: son of t 1)' t 1. s 1 (S 1: son of t 1)

Display form of namespaces abc←t 1. s 1 ⍝ even if assigned a new Display form of namespaces abc←t 1. s 1 ⍝ even if assigned a new name: abc ⍝ what does this look like? (S 1: son of t 1) abc≡t 1. s 1 ⍝ it “remembers” its reference 1 ⍬ ≡⍴abc ⍝ it is still just a ref 1 ⍴⍕ abc ⍝ its display has a length 15

Contents of namespaces t 1. s 1. v 11←’var’ ⍝ If we change the Contents of namespaces t 1. s 1. v 11←’var’ ⍝ If we change the t 1. s 1. ⎕ fx ‘f 1’ ‘. . . ’ ⍝ contents of s 1: , t 1. s 1. ⎕ nl 2 3 f 1 v 11 , abc. ⎕ nl 2 3 ⍝ abc will “see” it f 1 v 11 ⎕ NC ’abc’ ‘t 1. s 1’ 9. 1

Contents of namespaces To get a distinct copy of t 1. s 1 we Contents of namespaces To get a distinct copy of t 1. s 1 we need to do abc←⎕ NS ⎕ OR 't 1. s 1' , abc. ⎕ NL 2 3 ⍝ everything is copied f 1 v 11 abc ⍝ even its name (S 1: son of t 1) abc≡t 1. s 1 ⍝ but they’re different 0 abc. ⎕ df ‘I am ABC’ ⋄ abc I am ABC

Contents of namespaces Outside world (e. g. WS) abc I am ABC abc. ⎕ Contents of namespaces Outside world (e. g. WS) abc I am ABC abc. ⎕ NL 2 3 f 1 v 11 ∇ f 1. . . ∇ v 11←’var’

Contents of namespaces abc You can add to a namespace: I am ABC ∇ Contents of namespaces abc You can add to a namespace: I am ABC ∇ f 1. . . ∇ tx←{, ⍵ } ‘abc’ ⎕ ns ‘tx’ and appears without ‘v 11’ or going away. v 11←’var’ ∇ tx←{, ⍵ } ∇

Contents of namespaces abc But if you use ← instead: #. [Namespace] tx←{, ⍵ Contents of namespaces abc But if you use ← instead: #. [Namespace] tx←{, ⍵ } abc←⎕ ns 'tx' appears in ‘abc’ alone and the display form is reset ∇ tx←{, ⍵ } ∇

Display form of a Form The default display form of a Form is its Display form of a Form The default display form of a Form is its path, just like a regular namespace: +'F 1' ⎕WC 'form' #. F 1 We can change this using ⎕DF: F 1. ⎕df '' F 1

Display form of a form ⍝ we can add items to it: ‘F 1. Display form of a form ⍝ we can add items to it: ‘F 1. b 1’ ⎕wc ‘button’ ‘e 2’ F 1. ⎕wc ‘edit’ ⎕nc ‘F 1’ ‘F 1. b 1’ ‘F 1. e 2’ 9. 2 ⍝ we have 3 instances of built-in APL forms F 1. e 2 F 1 ⍝ each with its own name #. F 1. e 2

Contents of a form The form contains 2 objects: ⍴⎕←F 1. ⎕nl 2 3 Contents of a form The form contains 2 objects: ⍴⎕←F 1. ⎕nl 2 3 9 b 1 e 2 22 ⎕nc ‘F 1. b 1’ 9 F 1. ⎕nc ‘Caption’ 0 e 2

Contents of a form A form is pretty much like a namespace. It can Contents of a form A form is pretty much like a namespace. It can contain variables and functions. F 1. v 1←’some var’ F 1. ⎕fx ‘f 1’ ‘whatever’ F 1. ⎕nl 2 3 ⍝ these are POSITIVE numbers f 1 v 1 Those are the items WE have added.

Contents of a form The form now contains 4 objects: ⍴⎕←F 1. ⎕nl 2 Contents of a form The form now contains 4 objects: ⍴⎕←F 1. ⎕nl 2 3 9 b 1 e 2 f 1 ∇ f 1 v 1 whatever 42 ∇ ⎕nc ‘F 1. b 1’ v 1←’some var’ 9

Contents of a form BUT a form also has properties and methods: F 1. Contents of a form BUT a form also has properties and methods: F 1. ⎕wx← 1 ⍝ to be able to see them ⍴⎕←F 1. ⎕nl -2 3 ⍝ include internal items Accelerator. . . Caption. . . YRange 69 F 1. ⎕nc ⊂ ’Caption’ ⍝ Caption is external ¯ 2. 6 The new 65 items are the only visible members inside the form. They do NOT appear in ⎕nl +2 3

Contents of a form The form contains 4 external objects: ⍴⎕←F 1. ⎕nl -2 Contents of a form The form contains 4 external objects: ⍴⎕←F 1. ⎕nl -2 3 4 []WX=0 v 1 ∇ f 1 ∇ e 2

Contents of a form The form contains 69 total objects: ⍴⎕←F 1. ⎕nl -2 Contents of a form The form contains 69 total objects: ⍴⎕←F 1. ⎕nl -2 3 Accelerator. . . Caption. . . YRange 69 []WX=1 Accelerator Caption Picture ∇ f 1 Help. Button ∇ VScroll Border BCol Hint Wait v 1 YRange Picture Posn Prop. List Range Redraw Accept. Files Active e 2 Size Step Xrange Cursor. Obj Data Detach Posn Method. List Min. Button Moveable

Contents of a form The form has 2 types of functions and variables: 1. Contents of a form The form has 2 types of functions and variables: 1. Those internal and specific to its type 2. Those external, those we add The 1 st ones can be listed with a NEGATIVE ⎕NL argument ONLY The 2 nd ones can be listed with a POSITIVE ⎕NL argument. ⎕NL- includes both types of elements.

Contents of namespaces All namespaces have a common structure • They inherit system variables Contents of namespaces All namespaces have a common structure • They inherit system variables • The system variables exist both internally AND externally

Contents of a form If we redefine the form all external objects disappear: +‘F Contents of a form If we redefine the form all external objects disappear: +‘F 1’⎕wc’form’ #. F 1 ⍴F 1. ⎕nl 2 3 00 ⍴F 1. ⎕nl-2 3 65

Contents of a class Outside world (e. g. WS) Classes are a different kind Contents of a class Outside world (e. g. WS) Classes are a different kind of namespace but they behave identically. ⍝ NO external object ⍴Shr. Ins. ⎕ NL 2 3 00 Shr. Ins

Contents of a class Outside world (e. g. WS) Shr. Ins. ⎕ NL -2 Contents of a class Outside world (e. g. WS) Shr. Ins. ⎕ NL -2 3 FS 1 MS 1 The private members cannot be seen or accessed from outside. Shr. Ins Master Share/instance ∇ MS 1 ∇ ∇ MS 0 ∇ FS 1 (no value) FS 0 (no value)

Contents of a class Outside world (e. g. WS) You can add items “outside” Contents of a class Outside world (e. g. WS) You can add items “outside” a class: tx←{, ⍵ } ‘Shr. Ins’ ⎕ ns ‘tx’ Shr. Ins. v 11← 32 and they appear without anything else going away. Shr. Ins Master Share/instance ∇ MS 1 ∇ FS 1 (no value) v 11← 32 ∇ tx←{, ⍵ } ∇

Contents of a class Outside world (e. g. WS) Shr. Ins. ⎕ NC 2 Contents of a class Outside world (e. g. WS) Shr. Ins. ⎕ NC 2 3 tx v 11 Shr. Ins. ⎕ nc-2 3 tx v 11 FS 1 MS 1 Shr. Ins Master Share/instance ∇ MS 1 ∇ FS 1 (no value) v 11← 32 ∇ tx←{, ⍵ } ∇

Contents of an instance SI 1 Outside world (e. g. WS) SI 1←⎕ new Contents of an instance SI 1 Outside world (e. g. WS) SI 1←⎕ new Shr. Ins ⍴SI 1. ⎕ NL 3 2 00 SI 1. ⎕ NL -3 2 FI 1 FS 1 MI 1 MS 1 The shared members are visible through the instance. #. [Shr. Ins] ∇ MI 1 ∇ ∇ MS 1 ∇ FI 1 (no value) FS 1 (no value) Instance members Class members

Contents of an interface Outside world (e. g. WS) )ed ∘ maneuvering ⍴maneuvering. ⎕ Contents of an interface Outside world (e. g. WS) )ed ∘ maneuvering ⍴maneuvering. ⎕ NC -2 3 0 maneuvering. v 11← 12 maneuvering. ⎕ NC -2 3 v 11

Contents of an interface Outside world (e. g. WS) The methods in the interface Contents of an interface Outside world (e. g. WS) The methods in the interface can only be seen when exposed through the dyadic ⎕ CLASS system function: VW←⎕ new Car (VW ⎕ class maneuvering). ⎕ nl 3 Accellerate Slow. Down Steer

Contents of all namespaces This concept of internal/external names is important. Assuming we have Contents of all namespaces This concept of internal/external names is important. Assuming we have all types of namespaces as follows: ns←⎕ ns 'v 1' 'f 1' fo←⎕ new ⊂ 'form' in 1←⎕ new cl 1 all←ns, fo, cl 1, int 1 then doing ⍴¨all. ⎕ nl⊂ -2 3 ⍝ will show 2 65 1 2 0

Contents of all namespaces This concept of internal/external names is important. Adding 1 external Contents of all namespaces This concept of internal/external names is important. Adding 1 external item to each namespace: ⍴¨all. ⎕ nl⊂ -2 3 2 65 1 2 0 all. X←⍳ 5 ⍴¨all. ⎕ nl⊂ -2 3 3 66 2 3 1 ⍝ will show

: Include This statement is used when wanting to include CODE (not data) into : Include This statement is used when wanting to include CODE (not data) into a class. This may be because the code to include is common.

Implementation details summary • Many new system commands & fns • Interfaces show it Implementation details summary • Many new system commands & fns • Interfaces show it is done • Numbered Properties are implemented in a special manner in APL • Triggers offer lightweight properties • ⎕NL/⎕NC have been extended • The notion of external names is important • Inclusion of common code is possible

End of implementation details QUESTIONS ? End of implementation details QUESTIONS ?

Complex Class This class is used to create complex numbers. It can perform most Complex Class This class is used to create complex numbers. It can perform most simple math operations on them. This class has • 2 public instance fields • 1 public shared field • 2 private fields • 5 instance functions • . . .

Complex Class This class also has • 5 shared functions These perform the basic Complex Class This class also has • 5 shared functions These perform the basic operations: + - × ÷ *

Complex Class This class also has • 2 constructors and • 2 private functions Complex Class This class also has • 2 constructors and • 2 private functions one of which is a trigger for when one of the fields is modified

Keyed component file The idea is to have a file whose components are accessed Keyed component file The idea is to have a file whose components are accessed by key instead of a number. Sort of file. Read ‘key’

Keyed component file Since it is made from a component file it might be Keyed component file Since it is made from a component file it might be better to define a component file class. Like this → This class ties a file, creating it if necessary, and unties it (and destroys it if it was temporary) upon deleting the instance

. Net and other goodies In addition to the classes which you can write . Net and other goodies In addition to the classes which you can write in APL, version 11. 0 allows you to work with: • Dyalog GUI classes, including OLE Servers and OLE Controls (Active. X components) • Microsoft. Net classes

. Net and other goodies In version 11. 0, these classes can be used . Net and other goodies In version 11. 0, these classes can be used in exactly the same way as instances of classes which have been implemented in APL. You create instances of them with ⎕NEW, and you can manipulate the public properties, methods and events which they expose (but unlike APL classes, you cannot see or modify the implementation).

Forms and more via ⎕NEW • It is possible to create forms using ⎕new: Forms and more via ⎕NEW • It is possible to create forms using ⎕new: f 1←⎕NEW 'form‘ ((‘caption’ ‘My. Form’)('size' (12 16)) Note that the class name for built-in GUI objects is provided as a string rather than as a reference to a name in the workspace. • You can create OLE controls with ⎕new too: xl←⎕NEW 'Ole. Client‘ ( ⊂ 'Class. Name‘ 'Excel. Application')

⎕WX This system function e. Xposes Window’s interface: 0= do NOT expose anything +1= ⎕WX This system function e. Xposes Window’s interface: 0= do NOT expose anything +1= expose names and report in ⎕NL with negative argument, use V 10 syntax where properties are treated as functions (e. g. Sheet. (Item 3). . . ) +2= use new V 11 syntax (e. g. Sheet[3]. . . )

⎕WX xl←⎕NEW 'Ole. Client‘ ( ⊂ 'Class. Name‘ 'Excel. Application') ⎕wx allows to use ⎕WX xl←⎕NEW 'Ole. Client‘ ( ⊂ 'Class. Name‘ 'Excel. Application') ⎕wx allows to use V 10 syntax or the new V 11 syntax: xl. ⎕wx← 1 ⍝ use V 10 form xl. Active. Workbook. Sheets. (Item 1). Name xl. ⎕wx← 3 ⍝ use V 11 form xl. Active. Workbook. Sheets[⊂ ’Sheet 2']. Index

. Net and other goodies Example: standardize dialog boxes f 1←⎕NEW Dialog ('Hello World' . Net and other goodies Example: standardize dialog boxes f 1←⎕NEW Dialog ('Hello World' (50 250) ⍬) Note how the class is based on ‘Form’ (a string) and not Form (a name) You can do fm←⎕NEW ‘form’. . .

. Net and other goodies. Net utilities There is a lot of utilities out . Net and other goodies. Net utilities There is a lot of utilities out there that can be used in APL. For example, the Date/Time utilities found in the. Net Date. Time class. They are found in the System namespace. To be able to use the Date. Time class you must indicate to APL that it resides in the System namespace with ⎕USING: ⎕USING←’System’ now←⎕new Date. Time ⎕ts now ⍝ let’s see its display form: 2007/10/01 21: 47: 08 ⎕nc ‘now’ 9

. Net and other goodies. Net for others To allow other languages to use . Net and other goodies. Net for others To allow other languages to use your code you should organize your classes in namespaces: NS 1 Class. A Class. B WS NS 2 Class. X Class. Y Class. C

. Net and other goodies. Net for others To allow other languages to use . Net and other goodies. Net for others To allow other languages to use your code you • declare how it works using the : Signature statement • export it through the File/Export/. Net DLL menu item

: Signature statement This statement is used for the outside world where type is : Signature statement This statement is used for the outside world where type is important. It is made up of : Signature [rt←] fnname [at 1 [name 1] [, ng 2 [, . . . ] ] ] rt← is the return type. If present it MUST be followed by ← fnname is the name of the function as seen from outside. It does not have to match the function name. This MUST be there. at 1 is the 1 st argument type, if present name 1 is the name of the 1 st argument as seen from outside. If elided the DLL documentation will skip it and only show the type , ng 2 is the same at/name group for the 2 nd argument. If present, the comma MUST be there as it delimits groups , . . . same for the other arguments

. Net and other goodies. Net for others Here’s how a C# program would . Net and other goodies. Net for others Here’s how a C# program would use this program: using System; using APLClasses; // the namespace in which our class public class Main. Class { // is found public static void Main() { Primitives apl = new Primitives(); // the APL class int[] rslt = apl. Gen. Indices(10); // THE call for (int i=0; i

. Net and other goodies. Net for others Here’s how another APL program would . Net and other goodies. Net for others Here’s how another APL program would use this program: ⎕using←'APLclasses, c: . . . apl. dll' pr←⎕NEW Primitives pr. Gen. Indices 10 1 2 3 4 5 6 7 8 9 10

. Net and other goodies Web services can be written using APLScript, the scripting . Net and other goodies Web services can be written using APLScript, the scripting version of Dyalog APL, where logic is separated from page layout • in ASMX files and ASPX files or • in workspaces “behind”

. Net and other goodies Example of Web services written in APLScript . Net and other goodies Example of Web services written in APLScript

. Net and other goodies Example of Web services written in APLScript . Net and other goodies Example of Web services written in APLScript

. Net and other goodies With ASPX files: . Net and other goodies With ASPX files:

: Using vs ⎕USING : Using X is akin to ⎕USING, ←'X' It appends : Using vs ⎕USING : Using X is akin to ⎕USING, ←'X' It appends X to ⎕USING except when no argument is supplied where it means “← 0⍴⊂⍬” In a script/class it is necessary to determine the base class/interfaces

Namespaces in script form Namespaces can have a source )ed ⍟ name will edit Namespaces in script form Namespaces can have a source )ed ⍟ name will edit a new name using the same source format as classes and interfaces. The source can then be retrieved using ⎕ SRC and fixed using ⎕ FIX.

Overloading • Primitives cannot be overloaded by APL classes but some. Net classes are. Overloading • Primitives cannot be overloaded by APL classes but some. Net classes are. • Ex: Date. Time objects can be compared using =, >, etc. sorted using ‘grade up’ or added to Time. Spans using +. ⎕using←'System' d 1←⎕new Date. Time ⎕ts ⍝ assume it is 2007/10/10 19: 12: 01 d 2←⎕new Date. Time (2007 10 16) t 1←⎕new Time. Span (7 2 0 0) ⍝ 7 days, 2 hours +d 3←d 1 -t 1 2007/10/03 17: 12: 01 d 1

Conclusion There are many advantages to using OO languages over procedural languages: • ease Conclusion There are many advantages to using OO languages over procedural languages: • ease of modification • reduced maintenance costs • easier to model • can speed up development time • etc.

This doesn't mean you have to rewrite everything! But you are now competitive with This doesn't mean you have to rewrite everything! But you are now competitive with the other guys. If someone tells you "you can't do OO or. Net" you can now say “Yes we can!"