[squeak-dev] Delimited dynamic bindings

Frank Shearar frank.shearar at gmail.com
Fri Jul 27 21:15:09 UTC 2012


I think I've mentioned once or twice the fact that dynamic variables
and partial continuations do not play nicely with each other. [1] I
haven't, however, formally announced any _implementation_ of same. So
without further ado, go take a look at
http://ss3.gemstone.com/ss/Control.html which now ships with
partial-continuation-friendly delimited dynamic variables!

    "Delimited dynamic variables are easy to instantiate:"
    d := DelimitedDynamicVariable default: 0.

    "They don't pollute your namespace unless you explicitly want to:"
    MyDynamicVariable := d. "<-- often not necessary, but forced on
one by DynamicVariable"

    "You can reset their root/initial value:"
    d dset: 1.

    "You can query their current value:"
    d dref. "=> 1"

    "You can alter their state within a block:"
    d dlet: 2 in: [
        d dref. "=> "2"
    ]
    d dref. "=> 1"

    "You can set multiple variables at a time:"
    p := DelimitedDynamicVariable default: 0.
    d, p dset: #(10 20).
    {d dref. p dref.} "=> #(10 20)"

   "And, of course, for just one block:"
    d, p dlet: #(3 4) in: [
        {d dref. p dref.} "=> #(3 4)"
    ]

Why use delimited dynamic variables? You probably already are:

    [self someStuff] on: AnExceptionClass do: [:ex | ex resume: 1]

So... why use DelimitedDynamicVariables? You don't have to waste a
class name on them. For a variable that's not used outside of a class,
that means the use thereof is invisible, as it should be.

frank

[1] http://www.lshift.net/blog/2012/06/27/resumable-exceptions-can-macro-express-delimited-dynamic-variables


More information about the Squeak-dev mailing list