Dynamic scoping (was: Proposal: Squeak-E = Squeak x Kernel-E)

David Simmons david.simmons at smallscript.com
Mon Jan 27 23:56:33 UTC 2003


Have you considered something like:

a) thread (st-process) local pool (shared) variable

	X

b) MyContextCollection
   withContextDo: valuable
	  X := Array with: self with: X.
       ^valuable ensure: "finally:" [
		X := X at: 2.
        ].
        
This assumes a mechanism for supporting per/process (thread-local) shared
variables.

In SmallScript this could be written as:

Class name: MyContextCollection
    shared-fields: X "obviously choosing a better name here"
{
    Method [
    withContextDo: valuable
	  X := {self, X}.
        "optionally, various exception guards could go here
         to handle resolution via exceptions, etc"
       ^valuable finally: [X := X[2]].
    ]
    Method [
    resolve: expr
        |tuple| := X.
        [tuple] whileNotNil: [
            tuple[1].internalQuery(expr) !? [:r| ^r].
            tuple := tuple[2].
        ].
	 ^nil. "indicate failure"
    ]
}

-- Dave S.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SmallScript for the AOS & .NET Platforms
David.Simmons at SmallScript.com
http://www.smallscript.org

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org [mailto:squeak-dev-
> bounces at lists.squeakfoundation.org] On Behalf Of Stephen Pair
> Sent: Monday, January 27, 2003 1:03 PM
> To: 'The general-purpose Squeak developers list'
> Subject: RE: Dynamic scoping (was: Proposal: Squeak-E = Squeak x Kernel-E)
> 
> What is not clear about those semantics?  Since the transcript output
> occurs before setting the value, the correct output is:
> 
> 0
> 0
> 
> Originally, I wanted the ability set a value for all subsequent
> operations that occur in a process...however, to accomplish that *and*
> use the stack for maintaining scope enclosures would be quite convoluted
> (if at all possible).  And, it's also not clear to me at this point
> whether or not I really need that ability.
> 
> - Stephen
> 
> > -----Original Message-----
> > From: squeak-dev-bounces at lists.squeakfoundation.org
> > [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On
> > Behalf Of Avi Bryant
> > Sent: Monday, January 27, 2003 3:29 PM
> > To: The general-purpose Squeak developers list
> > Subject: RE: Dynamic scoping (was: Proposal: Squeak-E =
> > Squeak x Kernel-E)
> >
> >
> >
> > On Mon, 27 Jan 2003, Stephen Pair wrote:
> >
> > > Actually, I rather like the #dynamicValue pattern.  Why not
> > this then:
> > >
> > > ----
> > > DynamicContext clamp: [
> > > 	#foo dynamicValue: 42.
> > > 	self assert: #foo dynamicValue = 42
> > > ].
> > >
> > > self assert: #foo dynamicValue isNil
> > > ----
> > >
> > > With the above, if you need to set several values, you
> > don't need to
> > > enclose your code in several blocks.
> >
> > True, but I find the semantics less clear. Say I capture a
> > continuation just before the call to #dynamicValue:, and then
> > come back to it:
> >
> > |k|
> >
> > #foo dynamicValue: 0.
> > DynamicContext clamp: [
> >   k := Continuation current.
> >   Transcript cr; show: #foo dynamicValue.
> >   #foo dynamicValue: 42.
> > ]
> >
> > k ifNotNil: [k value].
> >
> > Does this show
> >
> > 0
> > 0
> >
> > or
> >
> > 0
> > 42
> >
> > on the Transcript?
> >
> > If you want to be able to set multiple bindings at once, I
> > would suggest
> >
> > DynamicContext bindAll: {#foo -> 42} during: [...]
> >
> >
> >
> >
> >
> 




More information about the Squeak-dev mailing list