Check-in [e6ade010a0]

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

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

Overview
Comment:Added an example
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e6ade010a009643ae6d686d19161c8d1e1ba0cc0de682f7e75a088a657073d77
User & Date: dkf 2018-05-19 10:48:07
Context
2018-05-19
10:49
Untabify for consistent indentation check-in: 96cdaa7bf6 user: dkf tags: trunk, minor change
10:48
Added an example check-in: e6ade010a0 user: dkf tags: trunk
08:37
Updated TIP 500 in light of implementation experience. check-in: 7ff5dde719 user: dkf tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tip/500.md.

   272    272   
   273    273   A supporting introspector is also added, **info object creationid**, which
   274    274   returns the creation ID of any existing object. It also applies to classes.
   275    275   Again, note that creation IDs are _always_ system-allocated and are _never_
   276    276   guaranteed to be unique between interpreters, either in multiple processes or
   277    277   in the same thread or process; they are only ever locally unique.
   278    278   
          279  +# Example
          280  +
          281  +    oo::class create LabelEqual {
          282  +		constructor {label} {
          283  +			set [my varname label] $label
          284  +		}
          285  +        private {
          286  +		    variable label
          287  +			method getLabel {} {
          288  +			    return $label
          289  +			}
          290  +		}
          291  +		method equals {other} {
          292  +			expr {$label eq [$other getLabel]}
          293  +		}
          294  +	}
          295  +
          296  +	oo::class create Evaluated {
          297  +		superclass LabelEqual
          298  +		# Poorly chosen variable name! Happens too easily in real life
          299  +		variable label
          300  +		constructor {expression} {
          301  +			next $expression
          302  +			set label [expr $expression]
          303  +		}
          304  +	    method value {} {
          305  +			return $label
          306  +		}
          307  +	}
          308  +
          309  +	set expr1 [Evaluated new {1 + 2 + 3}]
          310  +	set expr2 [Evaluated new {3 + 2 + 1}]
          311  +	puts "one is two? [$expr1 equals $expr2]"
          312  +	# Prints: one is two? 0
          313  +	puts "one=[$expr1 value] two=[$expr2 value]"
          314  +	# Prints: one=6 two=6
          315  +	puts [info vars [info object namespace $expr1]::*]
          316  +	# Prints something like: {::oo::Obj13::11 : label} ::oo::Obj13::label
          317  +	catch {$expr2 getLabel} msg
          318  +	puts $msg
          319  +	# Prints: unknown method "getLabel": must be destroy, equals or value
          320  +
   279    321   # Implementation
   280    322   
   281    323   See the [`tip-500` branch](https://core.tcl.tk/tcl/timeline?r=tip-500).
   282    324   
   283    325   # Copyright
   284    326   
   285    327   This document has been placed in the public domain.