TIP 478: Add Expected Class Level Behaviors to oo::class

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Author:         Gerald Lester <Gerald.Lester@gmail.com>
State:          Draft
Type:           Project
Vote:           Pending
Created:        18-Oct-2017
Post-History:   
Keywords:       Tcl
Tcl-Version:    8.6.7

Abstract

TclOO provides a native OO system for Tcl. This TIP is to enhance it to meet some of the common expectations of people coming in from other languages.

Rationale

Most other OO systems provide for class variables which are accessible and shared by all members of a class and class methods which only have access to class variable and not to instance/object variables. They also provide a way to initialize the class variables. This TIP seeks to add them into TclOO.

Proposal

The proposal is to add some or all of the functionality of oo::util, in particular the classvariable and classmethod. Additionally, it is proposed to add an initialise class definition command to all the initialization of class variables.

Reference Implementation

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

  proc ::oo::define::initialise {body} {
      if {[package vsatisfies [package require Tcl] 8.7]} {
          set cls [uplevel 1 self]
      } else {
          set cls [lindex [info level -1] 1]
      }
      tailcall apply [list {} $body [info object namespace $cls]]
  }

Copyright

This document has been placed in the public domain.

History