Questions tagged [scope]
Scope is an enclosing context where values and expressions are associated. Use this tag for questions about different types of scope as well for questions where scope may be unclear.
17,528
questions
0
votes
0
answers
31
views
Why does my function work with the key word "this" and not a variable i am referencing to directly [closed]
Hi all appreciate the time your taking to look at this - recently started programming so apologies for the terminology if incorrect.
I just want to set some context firstly, so I'm writing a function, ...
0
votes
2
answers
30
views
coroutineScope doesnt wait for child coroutines?
i try to learn coroutines in Kotlin and now i have a problem with some code i played with in the Kotlin Playground.
I have two suspend-functions. One with a delay of 3seconds. I will call both ...
0
votes
1
answer
24
views
Box2d body, preservation of b2BodyDef, b2Shape, and b2FixtureDef
To create and initialize a b2Body, we need to create a b2BodyDef, b2Shape, and a b2FixtureDef, and we pass these values as pointers to functions.
So I could have a createBody function like this:
...
-1
votes
0
answers
29
views
Understanding Environment Records and Execution Contexts in ECMAScript
I've been reading the ECMAScript specification and came across the concept of "Environment Records" and their role in executable code and execution contexts. The documentation outlines that ...
2
votes
0
answers
47
views
React Native const value changing
In my React-Native App; I have one const variable declared as below in one component named: constants.js
export const IS_VIA_DEEP_LINK = false
Now,
In my Splashscreen.js I am doing as below:
constants....
0
votes
1
answer
33
views
Python integer variable scope vs set scope [duplicate]
In the following code if I define current in the for loop as an integer then during the call in dfs function current += 1 will error out with "UnboundLocalError: local variable 'current' ...
0
votes
0
answers
48
views
rust borrowed value issue value borrowed value does not live long enough [duplicate]
can't solve this
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::ffi::OsString;
use std::collections::HashMap;
extern crate tokenize;
use tokenize::tokenize::words;
extern crate ...
0
votes
0
answers
11
views
how to access fields and files in form.parse of formidable library
I wrote a file upload handler like this to get a user avatar and also the user info like username and etc to signup a new user
const fs = require('fs');
const path = require('path');
const formidable ...
0
votes
1
answer
30
views
instance variable is changing in Managed/Backing bean in the Spring Boot application [duplicate]
I have primefaces tab with spring boot. Each tab has a individual datatable which shares common instance variable "name".
Example:
User1 selected name as "John" in tab1
User2 ...
-1
votes
1
answer
30
views
js calling a function with a nested unnamed function and getting a value from it [closed]
function myFunction(a,callback){}
myFunction(a, function(test){c = 'result';});
console.log('value c '+c);
Any ideas on how to get in the third line to get the value с?
I tried to use:
var c = ...
0
votes
1
answer
28
views
Dagger2 custom scopes: Are custom scopes not seen on @Inject constructor injections when using provider methods in a module?
The following is the code
Custom Annotation classes:
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class CtxMain
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ...
0
votes
0
answers
13
views
How to get class name from a methodCallExpr without invoking reolve()
Using javaparser library in Java, I have a Visitor class that extracts methodCallExpr. now I want to get the class name of the objects on which they are invoked. For instance:
a.sayHi();
when I call ...
0
votes
0
answers
6
views
Keycloak : Customize claim "scope" to "scp"
I would like to modify the token claim scope to scp in keycloak. I tried with add mappers but it did not work.
If you have an idea on that ?
For information, I tried on keycloak version 22.0.
Thanks ...
-1
votes
0
answers
20
views
Problems with scope of try block in python
def fetch_key_for_call_and_put(ticker, expiry_date, open_date_raw):
key_for_call_query = f"SELECT OptionRoot FROM a{open_date_raw} WHERE UnderlyingSymbol = '{ticker}' AND Expiration = '{...
0
votes
0
answers
20
views
JavaScript "color variable undefined"
I am running back an error of "color not defined" and possibly more. I run each block separately and they come back undefined. When I run the final piece basically executing the whole setup ...
0
votes
1
answer
47
views
How do I go about separating code away from the main form class?
I'm only fairly new to C# but have a bit of a project on the go and have run into a bit of trouble.
I'm trying to follow (my known) best practices and want to get on top of this early.
Below is a very ...
-1
votes
1
answer
35
views
Does arr.filter call callbackFn twice?
First time asker.
I came across this code from the page below:
function inBetween(a, b) {
return function(x) {
return x >= a && x <= b;
};
}
let arr = [1, 2, 3, 4, 5, 6, 7];
...
0
votes
1
answer
38
views
Is there any way to make a static variable in Python?
I'm not exactly a noob but I'm also not the best Python dev. Recently I've been trying to make a program that creates a variable in the global scope of main.py, a function in main calls file2.foo(), ...
0
votes
0
answers
21
views
Workaround for calling `open()` in `__del__()` for a function decorator
I am writing a function decorator to perform profiling of a function, it stores information about the function during execution and outputs the information into a log file. The implementation causing ...
0
votes
1
answer
30
views
How to determine the scope of a function passed as a parameter to a child widget?
I'm trying to understand how the function I pass as a parameter to the child widget is able to update the instance attributes of the parent widget.
For example, the below code works:
//...some code
...
-1
votes
2
answers
67
views
This example subverts my understanding of ownership and reference scope
// print:
// string-a
// string-aaabc
fn main() {
let mut a = String::from("string-");
let s = &mut a;
let ss = &mut a; // s goes out of scope here
ss....
0
votes
0
answers
60
views
BASH command on remote workstation is returning results from source machine, not the remote one
As a learning project, I'm writing a little BASH script that will list various elements of two workstations. It should compare the machine the script is executed on and one passed to the script.
In ...
0
votes
0
answers
14
views
A class method Passed as a parameter of method in the same class seems to loose global variable scope [duplicate]
class Myclass{
private _myvar = "foo"
function1(){
this.function2(this.function3)
}
function2(myfunction){
myfunction()
}
function3(){
...
0
votes
1
answer
45
views
Does Rust shadow variables that are not re-declared? [duplicate]
I am trying to learn Rust, and am trying to write a simple program that takes arguments from the command line, to get used to some basic concepts. The code I wrote to handle the arguments, fails, and ...
1
vote
1
answer
52
views
Scope of variable inside switch case
package main
import "fmt"
func main() {
x := 10
switch x {
case 0:
y := 'a'
fmt.Printf("%c\n", y)
case 1:
// y = 'b' // this can't compile,...
-2
votes
0
answers
42
views
Assigning values to global variables
I have a file x.f90, let's say. I have a bunch of subroutines sitting inside a module in x. The thing is, one of these subroutines (call it M) is bringing in values for variables from some other file. ...
0
votes
1
answer
39
views
Same Julia code, different results in different editors
This Julia code runs ok in JupyterLab but gives me a scope error in Vscode. Why is there a difference? Is there a setup parameter in Vscode that I need to look at?
x = 0
for i in 1:5
x += (1/i)^2
...
0
votes
0
answers
9
views
Summing calculated measure for flat dimension
I have created a calculated measure, that I need the sum of in the grand total line, og when no dimension is selected.
Until now, I have tried various methods, all of them ending in either wrong ...
-1
votes
1
answer
25
views
Extracting df from inside function
I'm trying to access the dataframe when calling the function import_first_excel_csv_file function. The code should run the gui, get the directory and import the xcel in the directory to a dataframe ...
-1
votes
1
answer
63
views
How do I privately implement an operator for an STL container?
Say we have something like this:
template<typename T>
class SparseMatrix {
// Where the first (K,V) is (row_idx, columns) and the second is (col_idx, numeric type)
using Entries = std::...
0
votes
0
answers
47
views
Why do these three JavaScript examples produce different outputs, considering function hoisting? [duplicate]
Question
I'm trying to understand why the following three JavaScript examples produce different outputs, even though they all seem to involve function hoisting. Shouldn't the outputs be the same based ...
0
votes
1
answer
30
views
Use and modify my variable in all startthreadjob powershell
I need help because I'm having trouble using my variables in powershell jobs.
Let me explain
I want to create a counter to retrieve the number of ping OK
foreach($computer in $computers)
{
Start-...
0
votes
0
answers
28
views
Correct definition of lifetime of a reference in Rust [duplicate]
I have a doubt about the definition of lifetime of a reference in Rust:
the two definitions I've found in most articles are the following two:
"The lifetime of a reference is the set of lines of ...
0
votes
2
answers
182
views
Renaming vs Adding Column to a DataFrame within a function in Python
I had have a function which:
Defines a list of dictionaries. One item in each dictionary is a dataframe.
It then adds a column to dataframe
then renames a column in same dataframe
And then returns ...
-3
votes
1
answer
143
views
How does C++ compiler distribute scope for a for-statement conceptually? [closed]
What's the scope structure of a for-statement is in C++?
I've seen in cppreference that in C the loop-statement establishes its own block scope, while in C++ it doesn't. (https://en.cppreference.com/w/...
0
votes
1
answer
35
views
Why i have to return integer but not list from a function?
i am writing a blackjack game. At the beginning i am writing pc moves then i will code user's moves, at the end by comparing the summaries of the computers cards and users cards who is going to win ...
0
votes
1
answer
29
views
Order of Function Definitions and Referenced Before Assignmnet Error
Suppose we have the following two snippets of code:
Snippet #1:
def bar():
print("Hello world")
baz()
def baz():
print("Hello user")
bar()
Snippet #2:
def bar():
...
1
vote
2
answers
39
views
How can I only allow a function to be run via a script and not the terminal wt.exe (PowerShell)
I have been trying to make a function for hours to only run if it's run by the script and not the terminal.
I have a Profile.ps1 in C:\Users\Alexander\Documents\PowerShell\Profile.ps1 that is run on ...
1
vote
2
answers
32
views
I want to import two classes from the same file one of them depend on the other
I have a file with two classes as follows:
# file1.py
class ApiConfig():
def __init__(self, ip: str = ""):
self.ip = ip
...
class Base_api():
method_name = None
params = None
...
0
votes
1
answer
55
views
How to use an async closure in Rust's retry
I have to retry an async function- handle_message & I'm using the retry crate for it (version "1.2.1"). But the second argument is a closure.
use retry::{retry, delay::Fixed};
retry(...
0
votes
1
answer
52
views
Discord.js dynamically add options to slash command with .addChoices()
I have a slash command that requires 3 choices from the user: team1, team2, and how many games. I'm adding those as parameters for the command like this:
data: new SlashCommandBuilder()
....
0
votes
2
answers
66
views
What's the correct way to declare event handler in class of JavaScript? [duplicate]
As I checked on MDN, method of a class looks like this:
class Foo {
method1 (){
// content of method1
}
}
However I found it's not good for event handlers
<!doctype html>
<html ...
1
vote
3
answers
77
views
Scope of a structure in C language
Could someone explain in simple terms what is meant by this?
The scope of a structure begins at its appearance in a type specifier, and persists to the end of the translation unit (for declarations ...
0
votes
1
answer
19
views
What is an efficient way of returning values in viewmodel scopes / function scopes in kotlin
I have a QuestDetailScreen in which I call getDailyQById(id), which passes to a viewmodel -> repo -> dao -> database. I use LiveData in the viewmodel for the DailyQuest vals. To not have the ...
2
votes
2
answers
86
views
Difficulty separating header/source of a class within a namespace while using operator overload
My separation of a class between a header/source seems to work until I try to work with the declaration of the class within a namespace. I believe it has to do with the scope of the operator within ...
0
votes
1
answer
31
views
typescript exports causing "error TS2451: Cannot redeclare block-scoped variable"
After a long gap, I am updating an old typescript project to the modern versions of node et al. After fixing a bunch of linter error, I am getting a strange error:
TSError: ⨯ Unable to compile ...
1
vote
3
answers
88
views
Totally weird PHP variable scope behaviour (also weird IDE behaviour) – can anyone make sense of this?
I'm asking this question b/c a certain PHP (and IDE) behaviour confuses me, and I was wondering if anyone can make sense of it. If you are proficient in variable scope questions, then this question is ...
3
votes
2
answers
88
views
Understanding cppreference example on lock
While reading on c++ std::lock, I ran into the following example from the cppreference:
void assign_lunch_partner(Employee &e1, Employee &e2)
{
static std::mutex io_mutex;
{
...
2
votes
1
answer
53
views
How to insert some functions inside other function to track score for a game?
I am new to javascript and I'm trying to do the rock-paper-scrissors game from the odin project: https://www.theodinproject.com/lessons/foundations-rock-paper-scissors. The functions that get an input ...
3
votes
1
answer
41
views
Why does reassigning to the function name inside the function body change its behavior?
I came across this function when reverse engineering some JavaScript:
function fun1() {
const arr = ["a", "b", "c", "d", "e"];
fun1 = function ...