1 / 94

Object Orientation in Dyalog APL

Object Orientation in Dyalog APL. Implementation details V1.01. 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.

keiji
Télécharger la présentation

Object Orientation in Dyalog APL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Object Orientationin Dyalog APL Implementation details V1.01

  2. 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.

  3. 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

  4. 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

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

  6. 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.

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

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

  9. 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

  10. 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.

  11. 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 (NewValue).

  12. 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.

  13. 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.

  14. 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.defProp[index] If a property is the default then using “squad indexing” applies to the whole property

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

  16. Implementation details Triggers t←⎕NEW trigger1 ('Dan' 'Baronet') Full name is Dan Baronet Full name is Dan Baronet t.FirstName←'Daniel' Full name is Daniel Baronet

  17. 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

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

  19. 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 s1←⎕new square s1.surface 20 400

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

  21. Non-Based classes ⍝ M1 calls its own M2: (⎕NEW B).M1 I am B ⍝ M1 calls its own M2: (⎕NEW A).M1 I am A

  22. Non-Based classes Class B Class A M1 M2 M1 M2 M2 ‘I am B’ M2 ‘I am A’ ⍝ M1 calls its own M2: (⎕NEW B).M1 I am B ⍝ M1 calls its own M2: (⎕NEW A).M1 I am A

  23. Based classes ⍝ M1 calls its own M2: (⎕NEW B).M1 I am A

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

  25. Overridden classes ⍝ M1 calls its own M2 because ⍝ it has not been overridden: (⎕NEW B).M1 I am A

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

  27. Overridden classes ⍝ M1 calls B’s M2 because ⍝ it has been overridden: (⎕NEW B).M1 I am B

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

  29. 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.

  30. Implementation details: ⎕NC/⎕NL ⎕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 ‘myClass’ 9 To find their sub-class they need to be enclosed: ⎕NC ⊂‘myClass’ 9.4

  31. Implementation details: ⎕NC/⎕NL ⎕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

  32. 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

  33. Implementation details: ⎕NC/⎕NL ⎕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 External Class n.7 - - External Interface

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

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

  36. Implementation details Types of Namespaces and their ⎕NC The first two already existed in V10 • Regular NS 9.1 • Forms 9.2 • Instances 9.2 (NOT 9.3!) • Classes 9.4 • Interfaces 9.5

  37. Implementation details: ⎕DF The default display form of a namespace is its path: ⎕←'t1.s1' ⎕NS '' #.t1.s1 We can change this using ⎕DF: t1.s1.⎕df '(S1: son of t1)' t1.s1 (S1: son of t1)

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

  39. Contents of namespaces t1.s1.v11←’var’ ⍝ If we change the t1.s1.⎕fx ‘f1’ ‘...’ ⍝ contents of s1: ,t1.s1.⎕nl 2 3 f1 v11 ,abc.⎕nl 2 3 ⍝ abc will “see” it f1 v11 ⎕NC ’abc’ ‘t1’ ‘t1.s1’ 9.1 9.1 9.1

  40. Contents of namespaces To get a distinct copy of t1.s1 we need to do abc←⎕NS ⎕OR 't1.s1' ,abc.⎕NL 2 3 ⍝ everything is copied f1 v11 abc ⍝ even its name (S1: son of t1) abc≡t1.s1 ⍝ but they’re different 0 abc.⎕df ‘I am ABC’ ⋄ abc I am ABC

  41. Contents of namespaces abc Outside world (e.g. WS) I am ABC abc.⎕NL 2 3 ∇f1 ... ∇ f1 v11 v11←’var’

  42. Contents of namespaces abc You can addto a namespace: tx←{,⍵} ‘abc’ ⎕ns ‘tx’ and <tx> appears without ‘v11’ or <f1> going away. I am ABC ∇f1 ... ∇ v11←’var’ ∇tx←{,⍵} ∇

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

  44. Display form of a Form The default display form of a Form is its path, just like a regular namespace: +'F1' ⎕WC 'form' #.F1 We can change this using ⎕DF: F1.⎕df '<F1 is in great form>' F1 <F1 is in great form>

  45. Display form of a form ⍝ we can add items to it: ‘F1.b1’ ⎕wc ‘button’ ‘e2’ F1.⎕wc ‘edit’ ⎕nc ‘F1’ ‘F1.b1’ ‘F1.e2’ 9.2 9.2 9.2 ⍝ we have 3 instances of built-in APL forms F1.e2 F1 ⍝ each with its own name #.F1.e2 <F1 is in great form>

  46. Contents of a form The form contains 2 objects: ⍴⎕←F1.⎕nl 2 3 9 b1 e2 2 2 ⎕nc ‘F1.b1’ 9 F1.⎕nc ‘Caption’ 0 <F1 is in great form> e2

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

  48. Contents of a form The form now contains 4 objects: ⍴⎕←F1.⎕nl 2 3 9 b1 e2 f1 v1 4 2 ⎕nc ‘F1.b1’ 9 <F1 is in great form> e2 ∇ f1 whatever ∇ v1←’some var’

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

  50. <F1 is in great form> e2 v1 ∇f1 ∇ Contents of a form []WX=0 The form contains 4 external objects: ⍴⎕←F1.⎕nl -2 3 4

More Related