Check-in [e6ade010a0]

Login

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

Overview
Comment:Added an example
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e6ade010a009643ae6d686d19161c8d1e1ba0cc0de682f7e75a088a657073d77
User & Date: dkf 2018-05-19 10:48:07.531
Context
2018-05-19
10:49
Untabify for consistent indentation check-in: 96cdaa7bf6 user: dkf tags: minor change, trunk
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
Unified Diff Ignore Whitespace Patch
Changes to tip/500.md.
272
273
274
275
276
277
278










































279
280
281
282
283
284
285

A supporting introspector is also added, **info object creationid**, which
returns the creation ID of any existing object. It also applies to classes.
Again, note that creation IDs are _always_ system-allocated and are _never_
guaranteed to be unique between interpreters, either in multiple processes or
in the same thread or process; they are only ever locally unique.











































# Implementation

See the [`tip-500` branch](https://core.tcl.tk/tcl/timeline?r=tip-500).

# Copyright

This document has been placed in the public domain.







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







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

A supporting introspector is also added, **info object creationid**, which
returns the creation ID of any existing object. It also applies to classes.
Again, note that creation IDs are _always_ system-allocated and are _never_
guaranteed to be unique between interpreters, either in multiple processes or
in the same thread or process; they are only ever locally unique.

# Example

    oo::class create LabelEqual {
		constructor {label} {
			set [my varname label] $label
		}
        private {
		    variable label
			method getLabel {} {
			    return $label
			}
		}
		method equals {other} {
			expr {$label eq [$other getLabel]}
		}
	}

	oo::class create Evaluated {
		superclass LabelEqual
		# Poorly chosen variable name! Happens too easily in real life
		variable label
		constructor {expression} {
			next $expression
			set label [expr $expression]
		}
	    method value {} {
			return $label
		}
	}

	set expr1 [Evaluated new {1 + 2 + 3}]
	set expr2 [Evaluated new {3 + 2 + 1}]
	puts "one is two? [$expr1 equals $expr2]"
	# Prints: one is two? 0
	puts "one=[$expr1 value] two=[$expr2 value]"
	# Prints: one=6 two=6
	puts [info vars [info object namespace $expr1]::*]
	# Prints something like: {::oo::Obj13::11 : label} ::oo::Obj13::label
	catch {$expr2 getLabel} msg
	puts $msg
	# Prints: unknown method "getLabel": must be destroy, equals or value

# Implementation

See the [`tip-500` branch](https://core.tcl.tk/tcl/timeline?r=tip-500).

# Copyright

This document has been placed in the public domain.