What is a "top-level binding"? - typing

I came across the expression top-level binding used within the context of dynamically typed languages and variable assignment.
What is meant by top level and how does this differ from normal lexical binding or dynamic binding?
Adding surrounding text for more context:
A variable can be bound to a value of any type. You can rebind mynum to a string:
mynum = ’Brown’
This binding lasts until you assign some other value to mynum...It is called a top-level binding. We will encounter cases of binding variables to values where the bindings are temporary.

Wikipedia had the following to say about a top-level binding on the page for Common Lisp:
In Common Lisp, a special variable which has only a top-level binding
behaves just like a global variable in other programming languages. A
new value can be stored into it, and that value simply replaces what
is in the top-level binding.
A variable with top-level binding appears to be another name for a global variable.
The specific example you provided indicates it is in the outer-most/global scope of the program, as opposed to a smaller, temporary scope which goes away during execution. This variable would be available to any portion of the program assuming it had not been locally or temporarily overridden in the current lexical or dynamic context.

Related

XAML property values: default vs local vs ambient

I've been trying to interpret the XAML code in a project I've inherited and I want to figure out where some of the values are coming from in certain elements. When I look at an object's properties in the Properties panel, I can see squares next to each property. A white square indicates that the property value is the default, a black square indicates that the property value is "local" meaning it has been changed from the default and that change can be seen in the XAML tag, and a green square means "ambient."
There are styles applied to the objects so I can sort of intuit that the values in ambient properties must come from resource dictionaries. I'm still unsure where to look for the source of the values, which I want to do in order to change them. The documentation for ambient properties is hard for me to follow and doesn't answer all my questions, and I haven't found any documentation discussing the differences between default, local, and ambient.
If this is an appropriate place to ask, can someone explain and discuss the differences between default, local, and ambient?
Is there a word used to distinguish between these types of property values, i.e. is "default" a property value "type" or what?
And are there any property value types beyond those three?
My, what a charming profile you have. ;)
I just want to mention that you can get some information about the source of a dependency property's value using the static helper method DependencyPropertyHelper.GetValueSource(DependencyObject, DependencyProperty) in the System.Windows namespace.
"Default" essentially means that no source has been specified and so the value is taken from some built-in source. Note that some default values are dynamically generated and not constant. "Local" is when the value is explicitly set in that specific dependency object, overriding any values that it would otherwise inherit. "Ambient" is when the value is derived from some other source such as a style. I would refer to the distinction between these as different base value sources.
And yes, there are more than just those three. If you put the attribute TextBlock.FontFamily="Arial" in your Window tag for example, text blocks in that window will inherit that value from it. When you observe the property in the properties panel and roll over the box, it will say "Inherited." Note that the box is still green just like it is with "Ambient."
There is actually an enum that can help illuminate the various possible base value sources. It's called BaseValueSource.

AngularJS data binding types

I know this is an old and 100 times-answered question, but things are getting more complex with the latest releases, thus causing me a lot of confusion.
I'd like to know what is the difference between the four currently available ways to declare a data binding for an attribute in a directive.
Specifically:
# Text binding
= Two-way binding
& Method binding (although some call it one-way binding)
< One-way binding
I'm interested in particular in the difference between the last two, given that they seem to have overlapping functionalities and I really can't tell the difference and the advantages of one against the other.
# Text binding:
This is used if we want to provide any static text to each instance of our directive. For e.g., any title or specific style/property component that needs to be passed to custom directive that is used to create a dialog.
= Two-way binding:
This is our normal angular two way data binding. For e.g., any live data update in a dialog or any user input (checkbox, radio etc.) can be achieved using this.
& Method binding:
As the name suggests this is primarily used for calling methods defined in the parent controller from the directive. It can also be used to evaluate a expression and bind the result to the directives scope. Typical usage might be responding to user events like when the user closes the dialog.
< One-way binding:
This I guess was introduced for higher performance situations, where we need not any updates from the directives scope to reflect on the parents scope. Typical usage scenario may be when we need to pass title, style, dialog configuration (modal/non modal, etc.) via a variable defined in the parent scope. Since such data are mostly not changed in the scope of the custom directive (our case dialog), one way binding would have a higher performance than a double binding. This is because angular watch cycle needs to monitor only the parents scope variables and not the directives one-way binded variables.
Note: I am not a expert in AngularJS and the answers above are best to my knowledge. They might be wrong in the view of a experienced Angular guy. Please pardon and correct me if there are any mistakes.
Official docs: https://docs.angularjs.org/api/ng/service/$compile#-scope-
Here is some information on the new one-way binding for isolate scope.
From GitHub:1
feat($compile):
add one-way binding to the isolate scope definition
This change allows the developer to bind an isolate scope / controller property
to an expression, using a < binding, in such a way that if the value of the
expression changes, the scope/controller property is updated but not the
converse.
The binding is implemented as a single simple watch, which can also provide
performance benefits over two way bindings.
Closes #13928
Closes #13854
Closes #12835
Closes #13900

How can I overrule/change and then reset a Binding?

I have a Canvas whose Width & Height are databound, e.g. Width:
Width="{Binding DrawingSize.Width, NotifyOnTargetUpdated=True}".
When I set the Canvas's Width somewhere in code behind to another value, the Binding is lost.
Can somebody explain why that is or where MSDN explains it?
MSDN explains this in the Dependency Property Value Precedence:
Dynamic resources and bindings have the precedence of where they were
set, but the value is deferred. One consequence of this is that if you
set a dynamic resource or binding to a local value, any change to the
local value replaces the dynamic resource or binding entirely.
You can use SetCurrentValue to change the current value without overriding anything. However, even if there are valid usages for this method, I personally wouldn't recommend it. You're likely to run into other problems such as "who set this value, that's not the one I expected", or "the binding has changed too early, I lost my current value". Consider using the coercion mechanism, described in the same MSDN page, instead.

Dependency Properties

If I am setting one dependency property equal to another dependency property, will they automatically get updated if one chagnes, or do I still need to bind them. Also if two dp are part of the same object (same type too) and I set them equal to each does the same apply as above, or only this case works and the one above doesn't?
will they automatically get updated if one chagnes, or do I still need to bind them
No. Each is a separate property, and setting one to the other just sets the value. If you want them to be "bound together" then you should create a binding that binds them together.
This is true whether they're in the same class or different classes.

Garbage Collection when Attached dependencyobject is destroyed \ disconnected

When we use any attached property against any dependency object, I thunk it actually maps the property and the value with the dependency object.
E.g. <DockPanel><TextBlock x:Name="MyText" DockPanel.Dock="Top"/></DockPanel>
Here value "Top" is mapped with DockPanels DockProperty via the dependency object textblock "MyText"
But my question is when is this mapping disposed? The reason I am asking this is the DockPanel's DockProperty is static\shared. So it must be having such multiple mappings Pair (Of value, dependency object) maitained against it in some kind of internal dictionary. (just a guess)
So this must be garbage collected when the dependency object is destroyed.
So now my point is is there any way that I should know IF such attached property diposing is taking place (like some kind of dispairing or dispose event for the given attached property and dependency object)?
Also if such garbage collection doesnt take place then isnt this a memory leak?
Thx
Vinit Sankhe.
As I understand the new property system in the WPF, the DependecyObject itself stores the value.
In your example, this would be the textblock.
Don't get confused as you call a static member - it is supposed to be implemented like:
element.SetValue(DockPanel.TopProperty, value);
So there happens no static field storage.
I think it was created using WeakReference. So removing of empty references takes place periodically.

Resources