Discussion:
[Unicon-group] Trapped variable processing and extending this facility to other user defined variables
Bruce & Breeanna Rennie
2017-01-22 21:44:46 UTC
Permalink
Greetings to all,

Thanks to Clinton and Don Ward, we now have the new Unicon/Icon
Implementation Book available within the sourceforge download.

As I have been away from internet access, I have been reading the
current book as a evening activity. The section on trapped variables has
given rise to a question as follows.

Is there a use for or a need for this ability to associate a function
that can run when a value is assigned to a specific variable?

For example, in Unicon, one is allowed to define a default type and
value for procedure parameters. Is this a valid situation in which any
such variables could be created as trapped variable using a new system
defined function to make this a user define d trapped variable?

Are there other situations where such a facility could be useful?

regards

Bruce Rennie
Jeffery, Clint (jefferyc@uidaho.edu)
2017-01-23 04:44:31 UTC
Permalink
In graduate school, perhaps 1989 or so, one of our bigger homeworks was to implement a variable trap mechanism for assignments and for dereferences. I believe the variable trap notion originated in one of the SNOBOL dialects, or in SL5. From the 1989 class, there were about a dozen independent implementations performed... on Icon version 7 or so. I do not know whether any of them could ever be found. One thing that I remember is: it is harder when you have to trap assignments to variables like L[i][j] or T[s] or r.x and not just simple variables.


I know that I have wanted it pretty badly, though: variable traps are needed in the udb debugger, to make a more efficient watch facility. Logically, it is needed as part of the execution monitoring facilities.


So I propose a tweak to Bruce's question: *aside from debugging*, what uses can you think of, for catching all assignments to a particular variable?

Cheers,

Clint


________________________________
From: Bruce & Breeanna Rennie <***@dcsi.net.au>
Sent: Sunday, January 22, 2017 1:44:46 PM
To: Unicon group
Subject: [Unicon-group] Trapped variable processing and extending this facility to other user defined variables

Greetings to all,

Thanks to Clinton and Don Ward, we now have the new Unicon/Icon
Implementation Book available within the sourceforge download.

As I have been away from internet access, I have been reading the
current book as a evening activity. The section on trapped variables has
given rise to a question as follows.

Is there a use for or a need for this ability to associate a function
that can run when a value is assigned to a specific variable?

For example, in Unicon, one is allowed to define a default type and
value for procedure parameters. Is this a valid situation in which any
such variables could be created as trapped variable using a new system
defined function to make this a user define d trapped variable?

Are there other situations where such a facility could be useful?

regards

Bruce Rennie
David S. Cargo
2017-01-23 16:31:28 UTC
Permalink
Post by Jeffery, Clint (***@uidaho.edu)
So I propose a tweak to Bruce's question: *aside from debugging*, what uses can you think of, for catching all assignments to a particular variable?
This reminded me of something I remember from Smalltalk and Java.
This facility can be used for a "change listener" and to implement
the observer pattern.

https://en.wikipedia.org/wiki/Observer_pattern

This can be fundamental to implementing a model-view-controller
GUI.

Something similar is in Tcl with the trace facility for variables.

It allows some event-driven programming capabilities.

Even if it's restricted to scalar global variables it can be useful,
although it's more useful if scalar object variables or array
object variables are allowed.

It makes wiring up a persistence framework to a GUI presentation
much simpler.

escargo

Loading...