lexical-scope

Why do I sometimes hear the term "lexical variable?"

I've seen the term "lexical variable" a few times, mostly in the context of closures. Paul Graham uses the term in his books on Lisp referring to variables defined using the let expression. I understand that lexical scoping is another name for static scoping. Is lexical variable just a variable that is visible in a program unit's refer...

Dynamic and Lexical variables in Common Lisp

I am reading the book 'Practical Common Lisp' by Peter Seibel. In Chapter 6, "Variables" sections "Lexical Variables and Closures" and "Dynamic, a.k.a. Special, Variables". http://www.gigamonkeys.com/book/variables.html My problem is that the examples in both sections show how (let ...) can shadow global variables and doesn't really te...

Why are lexical scopes prefered by the compilers?

How does lexical scope help the compilers? Does it help in compilation or optimization? ...

What is lexical scope?

I want brief intro to lexical scope ...

How is Lexical Scoping implemented?

A couple of years ago I started writing an interpreter for a little Domain Specific Language which included programmer-defined functions. At first I implemented variable scope using a simple stack of symbol-tables. But now I want to move to proper lexical scoping (with the option of closures). Can anyone explain or point me at a good e...

C: Cannot declare pointer inside if statement

Hi, 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 because my compiler complains when I first use the pointer later in the code. error...

How do you use "<<-" (scoping assignment) in R ?

Hi all, I just finished reading about scoping in the R intro, and am very curious about the <<- assignment. The manual showed one (very interesting) example for "<<-", which I feel I understood. What I am still missing is the context of when this can be useful. So what I would love to read from you are examples (or links to examples) ...

Lexically importing useful functions in a big script

Sometimes I need a useful utility function, like List::Util::max in the middle of a large program that does lots of stuff. So if I do use List::Util 'max'; At the top of my program, I'm stuck with that symbol, polluting my whole namespace, even though I only need it in one subroutine. So I've been thinking of trying a different patte...

Does my $_; do anything if $_ is implied

I think the answer is yes but I just want to make sure. so if I have sub something { my $_; my @array = ...; while ( @array ) { say; } } is the my $_; actually effective at lexicalizing the parameter passed to the say? In this particular case I'm using the DZP::UnusedVarsTests and it's complaining that I haven...

Why are variables declared with "our" visible across files?

From the "our" perldoc: our has the same scoping rules as my, but does not necessarily create a variable. This means that variables declared with our should not be visible across files, because file is the largest lexical scope. But this is not true. Why? ...