Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-07-12
19:24 • Closed ticket [1011429fff]: Procedure-bound persistent vars plus 8 other cha... artifact: da3ff04353 user: dkf
2004-08-18
23:48 • Ticket [1011429fff]: 4 changes artifact: 1f35ffc44a user: hobbs
20:24 • Ticket [1011429fff]: 4 changes artifact: 6de74c252d user: dkf
13:23 • New ticket [1011429fff]. artifact: 04ce046a2f user: dkf

Procedure-bound persistent vars

Closed / Out of Date1011429fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 10 years ago
Descriptionplain2004-08-18 13:23:19
It'd be great if we could have variables associated
with a procedure (specifically with a Proc structure
instance) since that would make it much easier to do
things like accumulator functions, unique id
generators, etc.

Further ideas on syntax:
  proc cmdName {formalArgs} {persistentVars} body
The syntax of persistentVars would be a list like
formalArgs.  If a default is present for a pv, set the
pv to that value when the procedure is created. 
Otherwise the pv is initially non-existant.  No special
handling of 'args', of course.  All pvs to be
automatically present in the local var env when
executing the body, just like formals.  PVs are not
(necessarily) modified when the procedure exits.  PVs
are deleted when the proc is deleted.

Probably also need [info] subcommand for introspection
on PVs.  :^)
dkfplain2004-08-18 20:24:58
Logged In: YES 
user_id=79902

Note: This FRQ submitted so I don't forget it.  It follows
on from a discussion on the chat (16 Aug 2004)
hobbsplain2004-08-18 23:48:29
Logged In: YES 
user_id=72656

This could easily be done with a 'static' command
implemented in Tcl (likely already been done).  Use of [info
level] [upvar] and [uplevel] has all the magic you need.
dkfwiki2016-07-12 19:24:27

Coroutines give us the capability to do the effects from this.

Log in (anonymous is fine) to add a comment.