Check-in [dcb0aecc9d]

Login
FlightAware bounty program for improvements to Tcl and certain Tcl packages.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Tightened up the spec in a few places and added a few key examples.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:dcb0aecc9dd6a680c3d9cd4cfda5551213306103ecca825a7b456d96050d5a07
User & Date: dkf 2018-07-17 07:27:51
Context
2018-07-30
15:36
Add some spacing to index.json, so fossil no longer considers it to be a binary file. check-in: cb0afa427f user: jan.nijtmans tags: trunk
2018-07-17
07:27
Tightened up the spec in a few places and added a few key examples. check-in: dcb0aecc9d user: dkf tags: trunk
2018-07-08
10:32
Added a key to the TIP index page check-in: 7c3fcd9800 user: dkf tags: trunk
Changes

Changes to tip/478.md.

44
45
46
47
48
49
50
51






52












53
54
55


56
57
58
59
60
61
62
..
72
73
74
75
76
77
78
79

80
81
82
83
84







85
86
87
88
is mixed into to be created, hiding the instantiation methods (`create`,
`new`, etc.) of that class. The class can still be inherited from and those
subclasses can be instantiated.

## New Definitions

The `classmethod` class definition creates a method that can be used when
invoked against its defining class or any of its subclasses.



















The `initialise` class definition evaluates a script in a context where it can
access the class's namespace, allowing for easier initialisation of a class
than simply overriding its constructor.



## New Helper Commands

The `callback`/`mymethod` command, available within methods, takes the name of
a method and zero-or-more arguments and returns a script fragment that will
allow that method easy to invoke from a callback (e.g., a variable `trace`,
`chan event` callback, or Tk event binding). The command will be available
................................................................................
if an argument is a two-element list, the first element is the name of the
method and the second is the name of the command (which will be resolved
relative to the current namespace if it is not an absolute command name).

# Reference Implementation

Reference implementations are mentioned in the proposal section. Additionally, this is a reference implementation for `initialise`:
<pre>

  proc ::oo::define::initialise {body} {
      set clsns [info object namespace [uplevel 1 self]]
      tailcall apply [list {} $body $clsns]
  }
</pre>








# Copyright

This document has been placed in the public domain.







|
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>


|
>
>







 







<
>
|
|
|
|
<
>
>
>
>
>
>
>




44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
92
93
94
95
96
97
98

99
100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
is mixed into to be created, hiding the instantiation methods (`create`,
`new`, etc.) of that class. The class can still be inherited from and those
subclasses can be instantiated.

## New Definitions

The `classmethod` class definition creates a method that can be used when
invoked against its defining class or any of its subclasses. When a class
method is invoked on the class _or any of its subclasses_, the current object
(i.e., the object reported by `self`) will be the class on which it is invoked
(i.e., the subclass if it is invoked against a subclass). When a class method
is invoked on an object that is an instance of the class _or any of its
subclasses_, the current object will be the current class of the object on
which the method was invoked. Thus:

    oo::class create Super {
        classmethod x {} {puts "self is [self]"}
    }
    oo::class create Sub {superclass Super}
    set instSuper [Super new]
    set instSub [Sub new]

    Super x;        # prints 'self is ::Super'
    Sub x;          # prints 'self is ::Sub'
    $instSuper x;   # prints 'self is ::Super'
    $instSub x;     # prints 'self is ::Sub'

The `initialise` class definition evaluates a script in a context where it can
access the class's namespace, allowing for easier initialisation of a class
than simply overriding its constructor. It has the alternate name,
`initialize`. In particular, this makes it much easier to create procedures
and variables in that namespace.

## New Helper Commands

The `callback`/`mymethod` command, available within methods, takes the name of
a method and zero-or-more arguments and returns a script fragment that will
allow that method easy to invoke from a callback (e.g., a variable `trace`,
`chan event` callback, or Tk event binding). The command will be available
................................................................................
if an argument is a two-element list, the first element is the name of the
method and the second is the name of the command (which will be resolved
relative to the current namespace if it is not an absolute command name).

# Reference Implementation

Reference implementations are mentioned in the proposal section. Additionally, this is a reference implementation for `initialise`:


    proc ::oo::define::initialise {body} {
        set clsns [info object namespace [uplevel 1 self]]
        tailcall apply [list {} $body $clsns]
    }


This is a reference implementation for `oo::abstract`:

    oo::class create oo::abstract {
        superclass oo::class
        unexport create createWithNamespace new
    }

# Copyright

This document has been placed in the public domain.