Questions tagged [lexical-scope]

Lexical scoping (sometimes known as static scoping ) is a convention used with many programming languages that sets the scope (range of functionality) of a variable so that it may only be called (referenced) from within the block of code in which it is defined. The scope is determined when the code is compiled. A variable declared in this fashion is sometimes called a private variable.

271 questions
1
vote
2 answers

Ionic 2 Angular 2 - can't access NavController from method

I am trying to navigate to another page after user is authenticated with angularfire. Everything works except navigating to another page. Here is my code: constructor(public navCtrl: NavController, public menu: MenuController, public afAuth:…
Christer
  • 2,746
  • 3
  • 31
  • 50
1
vote
1 answer

JavaScript Map shadowing

Writing a parser in JavaScript, for any language, one obviously uses Map to store mappings of names to variables. Most languages allow in some way or another variable in an inner scope to shadow one in an outer scope. The ideal data structure to…
rwallace
  • 31,405
  • 40
  • 123
  • 242
1
vote
1 answer

setTimeout Callback Explination

I don't understand how to explain the below code and why it does not work as intended: for (var i = 0; i < 16; i++) { setTimeout(function () { console.log(i); }, 1) } // Prints "16" 16 times One solution to this would be simply…
James Marino
  • 668
  • 1
  • 9
  • 25
1
vote
1 answer

r5rs eval not finding reference within its lexical scope

If eval with (interaction-environment) should have access to everything that's defined within the lexical scope of when it's called, then why am I getting this error when I try to run the below code? Welcome to DrRacket, version 6.3 [3m]. Language:…
1
vote
0 answers

JavaScript: a way to display the current lexical environment

Are there any browser plug-ins, interpreter objects or special host facilities to list all the variables / identifiers from the current lexical environment?
ezpresso
  • 7,896
  • 13
  • 62
  • 94
1
vote
3 answers

Understanding callbacks and related lexical scoping

I am trying to understand callbacks via setTimeout function. I have two sets of code : for (var i = 1; i <= 10; i++) { (function(callback,i){ setTimeout(function(){ callback(i) }, 0); …
Gyanesh Gouraw
  • 1,991
  • 4
  • 23
  • 31
1
vote
1 answer

When does lexical scoping binding take place - in runtime or compile time?

C language take scope binding during compile time (variable reference get fixed address - doesn't change at all), that is example of static scoping. Elisp language take scope binding during run time (variable point to top of own personal reference…
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
1
vote
2 answers

Nodejs asyn.apply and Javascript Apply

Can someone please explain me why the below code prints "arg1 0" while I expect it to print "arg1 hi". Is it due to the lexical scope? runIt(); function localScoped(arg1, callback) { console.log('arg1', arg1); callback(); } function runIt()…
rohit12sh
  • 827
  • 2
  • 11
  • 24
1
vote
1 answer

Is it bad practice to lexically scope Python import statements?

In Python it appears that imports are truly lexically scoped. Is this true? For example if you do this: def some_function: import sys print sys.argv[0] You will get an error: Traceback (most recent call last): File "example.py", line 4, in…
tjwrona1992
  • 8,614
  • 8
  • 35
  • 98
1
vote
1 answer

Emacs lisp: Pass lexical scope as to a function?

Python 3 has the function locals() ans globals() that allow passing the named values of the current scope at least for read-only purposes to a function. In emacs lisp I want to write a function for string interpolation. It would need access to the…
kdb
  • 4,098
  • 26
  • 49
1
vote
1 answer

Parallellize Independent Function Calls that Each Modify Function's Parent Environment

I'd like to find a way to parallelize repeated independent function calls in which each call modifies the function's parent environment. Each execution of the function is independent, however, for various reasons I am unable to consider any other…
1
vote
2 answers

Trouble with bookmark-set in bookmark+ (emacs 24.5)

Emacs raises "funcall: Symbol's value as variable is void: choices" on bookmark-set. After disabling bookmark+, bookmark-set started to work correctly. Does anyone have an idea how to solve this?
1
vote
1 answer

scope of nested R function

I have an example where I am not sure I understand scoping in R, nor I think it's doing the Right Thing. The example is modified from "An R and S-PLUS Companion to Applied Regression" by J. Fox > make.power = function(p) function(x) x^p > powers =…
piccolbo
  • 1,305
  • 7
  • 17
1
vote
2 answers

Change the value of a lexically scoped variable in a HHVM/Hack lambda expression?

Is it possible to change the value of a lexically scoped variable in a Hack lambda expression? function allTrue(Map $map): bool { $valid = 1; $map->map($a ==> $valid &= $a); return $valid === 1; } $map = Map{'foo' => true,…
robbmj
  • 16,085
  • 8
  • 38
  • 63
1
vote
8 answers

C: Cannot declare pointer inside if statement

I have a pointer which points to a function. I would like to: if (mode == 0) { const unsigned char *packet = read_serial_packet(src, &len); } else { const unsigned char *packet = read_network_packet(fd, &len); } But I cannot do it…
echedey lorenzo
  • 377
  • 1
  • 5
  • 19