591 questions
3
votes
4
answers
140
views
Why does this Razor code compile even though I reuse the same loop variable name in nested foreach
I am writing a Blazor component and noticed something unexpected. In my Razor code, I use a foreach to loop over a list, and inside the Click event handler of a RadzenButton I declare another foreach ...
2
votes
1
answer
175
views
What is the difference between alias `our` and the original global variable?
This is one question encountered while reading the answer of this QA (as ikegami's comment says, how subroutine foo works is complicated. IMHO that may be due to using one outside variable):
sub foo { ...
-1
votes
1
answer
43
views
Static scoping with nested functions
consider the nested functions:
def a():
def b():
def c():
def d():
def t():
I know:
t can call a and vv
a can also call b and d
b can call d, a and c
d can call b and a
c can call b
...
-1
votes
1
answer
65
views
Dynamic scoping evaluation
I'm currently taking a course about programming languages and trying to solve the following question, given the code in SML syntax, assume SML using dynamic scoping, what would be the value of the ...
0
votes
0
answers
50
views
Why is this closure running prematurely? [duplicate]
A while ago I found this answer by Shepmaster about how to implement cleanup code at the end of a Rust test. I added my own "generalised" idea from his, here.
It's been running fine as ...
0
votes
1
answer
74
views
instance of parent Class not accessible from subclass? "does not exist in current context"
So I'm fairly new to all this. I've got the beginnings of a simple Octree implementation for a Unity project. This consists of an Octree parent class, an instance of it, and a OctreeNode subclass
I'm ...
3
votes
1
answer
661
views
I can't understand the Rust "scope" definition (Rust Programming Language, 2nd Ed. Klabnik & Nichols)
I'm having a hard time with how Rust defines "scope". Or perhaps it's with the definition of "scope" in the No Starch Press book (I actually bought the book).
On the top of pg. 62:...
0
votes
1
answer
49
views
Understanding ls() scoping and environments
I'm having trouble understanding why this piece of R code works the way it does. Here is a simple function:
weird_ls <- function() {
some_env <- new.env()
assign("a", value = 1, ...
0
votes
2
answers
81
views
Perl, simplest way to override a class that's called by another class? (In MIME::Parser)
I'm using MIME::Parser to parse a bunch of emails. I want a different subdirectory for every mail message, with consistent file naming within each subdirectory. So far so good, but there's a couple ...
0
votes
0
answers
119
views
Why is a variable not borrowed for static if it is dropped at the end of the main function in Rust?
I am trying to pass a closure which captures a local variable:
fn main() {
/* snip */
let COINT = some_function_call();
/* snip */
hermes.with_task(
u32::MAX,
1,
1,
Box::...
2
votes
2
answers
76
views
When parameter name equals function name: who wins?
(I have this uneasy feeling that I've asked this before, but now I can't find it. Feel free to close and redirect this question if so...)
In C, assume I have a function named thing() and some other ...
2
votes
1
answer
84
views
Can a type inside a lambda parameter list refer to an uncaptured outer variable?
I'm trying to use std::size instead of macros like _countof or ARRAYSIZE, but I'm running into scoping problems.
Is the following code legal?
#include <iterator>
int main()
{
int arr1[4];
...
0
votes
0
answers
163
views
Conflicting global variable names in external javascript
There are a lot of questions and answers about conflicting variables names on Stackoverflow, but they all seem to be about scoping in your own code.
<script src="https://external_one/...
0
votes
1
answer
125
views
`super` vs `this` when calling methods on a JavaScript class
I'm trying to determine the best way to allow a user to pass a class's method into a promise chain. Currently the code looks like this, and I get the error I expect.
class Parent {
async say(...
0
votes
1
answer
309
views
How to get the environment object from the environment string?
Let's say I create a function:
x = function() { print(environmentName(environment())); envir=environment(); print(envir); print(environmentName(envir)); print(environmentName(environment())); print(...
0
votes
1
answer
92
views
Giving int data type to variable y in Program2 changes the output of that program. What will be the reason for it? Memory allocation in stack segment
(output printed is written in comment)
Just by giving int data type of the variable y which is within the paranthesis the output is different in program 2.
How Memory allocation in stack segment will ...
0
votes
1
answer
46
views
Rails Mailer: Pass `attachments` to other methods
I'm working on a standard Rails app that uses a mailer to send email.
Each mailer class has an attachments attribute [src on GitHub] that aliases an instance variable.
I'm trying to pass that ...
0
votes
0
answers
302
views
TypeScript - Why are global exported variables undefined in some contexts when they were set in another context?
I'm trying to have a shared store of global variables in a Vue.js application. Since only some properties are relevant to the state of the actual application, only those are wrapped in a Vue ...
2
votes
1
answer
131
views
Data objects not found in embedded vegan:cca. Scoping issue?
I try to embed cca (and also capscale) from package vegan (version 2.5-7, R 4.1.2) in another function to test an analysis pipeline with some data transformation and then varying model formulas. The ...
1
vote
1
answer
57
views
R scoping question: Object exists but I can't do anything with it
I'd like to feed a value from one function into another that I'm calling on inside the first, and I can't seem to get the scoping right. Crucially, the two functions are defined separately. Here's an ...
0
votes
0
answers
763
views
Dynamic Scope in C
I just have a problem with C dynamic scoping in the following code. I am aware that C only uses static (lexical) scoping, but the problem asks to pretend that we are using dynamic scoping.
#include &...
0
votes
4
answers
1k
views
Access variable in try block
I want to remove the throws FileNotFoundException from the method head and put it into it.
public static String[] read(String file) throws FileNotFoundException {
But then I can't access in (the ...
0
votes
3
answers
196
views
How to update a variable to use in another scope
I have a variable let second = 20 that i make 1 lower until it hits 0. When it hits 0 i want to stop running a part of my code but the variable second is always 20 when i use it because i make it ...
0
votes
0
answers
19
views
Are function declarations function scoped? [duplicate]
I have read that in sloppy mode function declarations are function scoped just like var with value of actual functions. But I want to know why can't I access the inside() function code below:
...
2
votes
1
answer
215
views
JavaScript Scoping Can't Access setInterval
Hey guys can someone just quickly help me out here.
I have an interval for a slideshow in one function and I want to clear it from another function without using global scopes as I know it is bad ...