Questions tagged [name-binding]

33 questions
31
votes
6 answers

What happens when JavaScript variable name and function name is the same?

I have the following code, where I declare a function and after it, a variable with the same name as the function: function a(x) { return x * 2; } var a; alert(a); I expected this to alert undefined, but if I run it, the alert will display the…
joesid
  • 671
  • 1
  • 10
  • 21
21
votes
1 answer

At which point occurs template Instantiation binding?

This code is from "C++ programming language" by Bjarne Stroustrup (C.13.8.3 Point of Instantiation Binding) template void f(T value) { g(value); } void g(int v); void h() { extern g(double); f(2); } And he mentions: Here,…
user1289
  • 1,251
  • 2
  • 13
  • 25
13
votes
2 answers

Python nested scopes with dynamic features

Need help with understanding the following sentence from PEP 227 and the Python Language Reference If a variable is referenced in an enclosed scope, it is an error to delete the name. The compiler will raise a SyntaxError for 'del name'. Lack…
trupanka
  • 693
  • 8
  • 20
7
votes
1 answer

What happens when I create a list such as c=[1] in python, in terms of name object bindings?

After reading http://www.effbot.org/zone/python-objects.htm I am left with this question: In python, if a=1 creates an integer-object and binds it to the name a, b=[] creates an empty list-object and binds it to name b, what happens when I call e.g.…
djvg
  • 11,722
  • 5
  • 72
  • 103
7
votes
1 answer

How do Let expressions work in AST?

Consider: data Expr a = V a | Lit Integer | Let (Expr a) (Expr (Maybe a)) deriving (Eq,Show) The Let constructor enables me to bind an expression (first arg) in order to reference it in the second (V Nothing refers to it). If I do…
phaazon
  • 1,972
  • 15
  • 21
6
votes
2 answers

Proper tagged AST

I’ve been trying to build tagged AST for a while now. Let’s introduce the issue: data E a = V a | LitInt Int | LitBool Bool | FooIntBool (E a) (E a) -- er… deriving (Eq,Show) The issue with that piece of code, to me, resides in…
phaazon
  • 1,972
  • 15
  • 21
5
votes
3 answers

Iterating in Python lists - does it copy or use iterator?

I have a list like this a = [ [ 1,2,3 ], [ 4,5,6] ] If I write for x in a: do something with x Is the first list from a copied into x? Or does python do that with an iterator without doing any extra copying?
smilitude
  • 265
  • 4
  • 9
4
votes
1 answer

point of instantiation and name binding

I am confused about the point of instantiation with the following example: #include void f(int){std::cout<<"int"< void g(T t) { f(t);//4 } void f(double){std::cout<<"double"<
Shane Nian
  • 63
  • 1
  • 4
4
votes
2 answers

How exactly binding is done in closures?

function f() { return s; } // works fine though no `s` is defined yet ! var s=1; f(); // 1 delete s; var s=2; f(); // 2 (function() { var s=3; f(); // 2 and not 3 which means lexical scoping is at play (?) })(); first off, you can close over a…
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
3
votes
3 answers

JAX RS, my filter is not working

Im work on : Best practice for REST token-based authentication with JAX-RS and Jersey But my filter not triggered, my call pass directly to the endpoint... My secure interface: @Qualifier @Retention(RUNTIME) @Target({METHOD, FIELD,…
Matias Blanco
  • 71
  • 3
  • 8
3
votes
1 answer

Jersey @PreMatching and name binding in 1 provider

I need to implement a Jersey filter (ContainerRequestFilter) that needs to be called during pre-matching phase but only apply to some resources. The pre-matching part can be done by annotating the class with the @PreMatching annotation and the…
ufasoli
  • 1,038
  • 2
  • 19
  • 41
2
votes
1 answer

Is it possible to bind a name inside a python function after the function has been compiled?

I know this pattern is would be very bad, I'm asking the question out of curiosity not because I'm planning on doing this in production code. Suppose I define a function: def function(x, y): return x + y + z And the variable z doesn't exist in…
Ignacio
  • 377
  • 3
  • 12
2
votes
2 answers

Does capture by reference turn into capture by value when the reference goes out of context in Javascript?

The following Javascript program: function f() { function g() { console.log(x); } let x = 0; g(); // prints 0 x = 1; g(); // prints 1 return g; } let g = f(); g(); // prints 1 outputs: 0 1 1 So it seems that g first captures x by…
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67
2
votes
0 answers

Name binding in function statements

The following Python program: d = {} for x in range(3): d[x] = lambda: x print(d[0](), d[1](), d[2]()) outputs: 2 2 2 x is bound by reference in the lambda expression. After the for statement, x is bound to 2, which explains the output. I…
Géry Ogam
  • 6,336
  • 4
  • 38
  • 67
2
votes
1 answer

Using dictionaries to multiply columns like by reference Pandas

I have a data frame like this and I would like to multiply the rows by its references value in another data frame using pandas. After that I would like to add all products from those rows and store it in a column called Pro_Sum. I know Python…
Zesima29
  • 184
  • 12
1
2 3