DynamicBindings

Description

You may create a hierarchy of DynamicBindings and directly manipulate the keys and values of those instances (just as you would any dictionary). There is a root DynamicBindings that you may use to create new children if you like (but you can also create entirely separate hierarchies). You can access this root with "DynamicBindings root". To force a process to use one of your sets of DynamicBindings, you write code as follows (note, I only use 'PATH' to highlight the similarity with normal OS environment variables): myBindings := DynamicBindings root newChild.myBindings at: #PATH put: '/bin:/usr/bin'.myBindings bindDuring:[Bindings at: #PATH. "- '/bin:/usr/bin'"Bindings at: #PATH put: ('/usr/local/bin:', (Bindings at: #PATH)).Bindings at: #PATH]. "- '/usr/local/bin:/bin:/usr/bin'" For convenience, two methods have been added to Object that enable more direct access to bindings. The following exampel is equivalent to the first: myBindings := DynamicBindings root newChild.myBindings at: #PATH put: '/bin:/usr/bin'.myBindings bindDuring:[#PATH binding. "- '/bin:/usr/bin'"#PATH binding: ('/usr/local/bin:', (#PATH binding)).#PATH binding]. "- '/usr/local/bin:/bin:/usr/bin'" The first line creates a new set of bindings that is a child of the root bindings. Any variables set in the root bindings are also visible in this new child environment. The second line sets the dynamic variable "PATH". The third line uses the evaluates the argument block in the context of our new set of bindings. The fourth line gets the value for the variable "PATH" (which we just set). The fifth line in the above example modifies the environment variable "PATH", but only for the duration that the enclosing block is active. Here is another example: #PATH binding: '/bin'.Bindings clamp:[#PATH binding: '/usr/bin'.#PATH binding]. "- '/usr/bin'"#PATH binding. "- '/bin'" This example shows the use of the #clamp: method to isolate a our dynamic bindings only for the dur

Details

Source
SqueakMap
Dialect
squeak (65% confidence)

Categories

UI / Graphics Education / Howto System / OS
← Back to results