416 questions
0
votes
0
answers
18
views
Why isn't my simple conversion program working when i call a function within a function? [duplicate]
def rods_to_meters(rods):
meters = rods * 5.0292#converts rods to meters and stores in appropriate variable.
return(meters)
def rods_to_feet(rods):
feet = (rods * 5.0292) / 0.3048#...
0
votes
1
answer
107
views
Positional arguments in nested functions
This question relates to this video: https://www.youtube.com/watch?v=jXugs4B3lwU
The piece I'm missing is somewhat simpler than the concept the video is covering overall. In the example code below:
...
0
votes
0
answers
50
views
Headless mode while using Selenium webdriver won't perform function
This is a nested function inside a function that I defined. But somehow the webdriver in Headless mode just won't perform the xport.click function. This function WORKS on a regular window but won't in ...
2
votes
2
answers
856
views
Whether to use nested function for better readability in composables or not?
When using Jetpack Compose, there are some scenarios where there is a piece of code that does a specific job but since it is calling lambda parameters of the composable, it is not possible to fully ...
0
votes
0
answers
21
views
A question related to function enclosure and call-by-name of Python language [duplicate]
Consider the following code snippet:
def part1():
flist = []
for i in range(10):
def hello():
print(f"Hello {i = }.")
flist.append(hello)
for f ...
0
votes
0
answers
26
views
Why is my nested function not called from my anonymous function? [duplicate]
I tried accomplishing a small task in PHP 7.4 (a language I never use) and decided to use a nested utility function isReverseScored, to be called inside an "arrow function", like so:
// ...
1
vote
1
answer
86
views
Python generator yielding from nested non-generator function
This is a dumb example based on a more complex thing that I want to do:
from typing import Generator
def f() -> Generator[list[int], None, None]:
result = list()
result.append(1)
if len(...
0
votes
2
answers
73
views
Importing custom created module
So i have created Custom_module.py module that i want to import or rather to import specific function in .py file that i am currently working on.
for example like this:
# Custom_module.py
def test1():...
1
vote
1
answer
226
views
Variables' scope of nested function in MATLAB
I am a little confused about the variables' scope in a nested function in MATLAB.
As nested function help docs explains: vaiable remains local to the nested function.
function main
nestedfun1
...
-1
votes
1
answer
42
views
N-back-for-matlab returned errors [closed]
I downloaded nback from https://www.mathworks.com/matlabcentral/fileexchange/67976-n-back-for-matlab
I am trying to set up this task in R2023b matlab, but there are numerous errors on the script for ...
1
vote
2
answers
73
views
Acces to import of the nested function JS
I need some help to get how some function export works inside JS.
Let's say I have this code
function goodbuy() {
console.log('bye');
}
function myModule() {
function hello() {
console....
1
vote
2
answers
270
views
convert gcc forward-declared nested function to clang blocks
I know this is impossible because I've spent hours on it and also read these below but I am determined to approximate a clang block forward definition even if it takes linker tricks or inline assembly:...
0
votes
1
answer
121
views
Using nested helper functions while building a class
I want to build a class which is merely a wrapper for some data. This is the basic idea:
class Fruits:
fruits = [ 'apple', 'orange', 'cherry' ]
My fruits aren’t strings, though, but classes ...
0
votes
1
answer
164
views
Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any' -- when running a nested function
Problem: running get_pi_ij() gives the error:
Error in as.vector(x, mode) : cannot coerce type 'closure' to vector of type 'any'
Called from: as.vector(data)
The first thing this function does is to ...
-1
votes
2
answers
72
views
Why won't calling a nested function result in returning original function's value? [closed]
Somehow I can't manage to use a previously defined function inside another one. Is that possible?
def generate_password(length):
import random
password = str()
alpha_num = [i for i in '...
3
votes
1
answer
280
views
Could a callee directly access a stack variable in the caller without pointers in theory?
C is pass-by-value which means that all the parameters are copied to the stack frame every time you call a function. C also does not support inner functions that could access/modify local variables in ...
0
votes
1
answer
33
views
Program output with nested function and function parameter
Given the following code
def alpha(num, proc):
def beta(): print(num)
if num == 1:
alpha(2, beta)
else:
proc()
def gamma():
pass
alpha(1, gamma)
I expected the ...
-1
votes
2
answers
63
views
Return value from nested function 'not defined'
I have a nested function that is returning two values. When I try to call those values I get an error saying its not defined.
async def wallet(self, interaction:discord.Interaction, button:...
0
votes
1
answer
102
views
Python tkinter removing nested functions
So I was developing a GUI with tkinter and I have realised that I have so many nested functions in my code that I think it is not a good practice. However, I think my code will not work without using ...
1
vote
1
answer
623
views
How can the most inner function access the non-local variable in the most outer function in Python?
inner() can access the non-local variable x in middle() with nonlocal x:
def outer():
x = 0
def middle():
x = 5 # <- Here
def inner():
nonlocal x # Here
...
1
vote
2
answers
242
views
R nested functions
I have to calculate the number of missing values per observation in a data set. As there are several variables across multiple time periods, I thought it best to try a function to keep my syntax clean....
0
votes
0
answers
43
views
Can I write Nested function in c#? [duplicate]
I wanted to ask, if it is possible to write the below function below, If so how can I do it ?
def builder(x):
def perform_addition(y):
return x+y
return perform_addition
result = builder(6)
...
0
votes
1
answer
821
views
TypeError: function() missing 1 required positional argument: 'y'
I want the greet function to say "Hi Sam, Hi Cody" using the format function but I am getting this error:
greet(names())
TypeError: greet() missing 1 required positional argument: 'y'
def ...
0
votes
3
answers
1k
views
Query to a list of dictionaries (python)
I have a list of dictionaries:
friends = [
{'name': 'Sam', 'gender': 'male', 'sport': 'Basketball'},
{'name': 'Emily', 'gender': 'female', 'sport': 'volleyball'},
]
I need to create functions query, ...
-2
votes
2
answers
926
views
Why do I get error "missing 1 required positional argument"?
Why I continue getting the error :
missing 1 required positional argument: 'category_id'
when the argument is already passed within query function in Backend class? I also don't understand the error ...
-1
votes
2
answers
119
views
When I decorate a function why the original function becomes none type
def outer_fun(func):
print('outer function ran')
def inner_function():
print('inner function ran')
return func()
return inner_function()
def fun():
print("Hi&...
0
votes
1
answer
183
views
Variable declared and assigned at global scope is undefined when called by a nested return function
When a function is created inside a function, the following code is returning a string with the name variable coming back as undefined. Since this is functionally scoped inside the global scope, I ...
1
vote
2
answers
129
views
Unable to call sub-function when it is used with self but works fine without self
I have a function, start_round() that initializes the round and creates temporary round variables. Then I have a nested function, rd_animate() that does the animation. Now when I make this rd_animate()...
0
votes
1
answer
743
views
In R, how to write a nested function that uses the arguments from the outer function?
f1<-function(x,y){
f2<-function(a,b){
print("f2")
return(a+b)}
f2(x,y)
print("f1")
return(x-y)}
f1(8,5)
I was trying above code to figure ...
0
votes
1
answer
301
views
Python Slice operation causing UnboundLocalError: local variable referenced before assignment
If I use curr = curr[:-1] to remove the last element, it gives the error:
UnboundLocalError: local variable 'curr' referenced before assignment on line 13 which is if (len(curr) >= len(word)):
...
3
votes
1
answer
160
views
Returning value in a nested function when using memoization
I am trying to implement a count variable in the function below using dynamic programming specifically memoization. The method calculates the value in a Fibonacci sequence at a given index. I cannot ...
0
votes
0
answers
111
views
Nested function code is unreachable - python tkinter
The function firespit can't access any of the code inside of it saying it is unreachable. All the variable inside firespit are also unbound even though I have defined them previously. What i am trying ...
15
votes
1
answer
2k
views
With c# why are 'in' parameters not usable in local functions?
For example,
public int DoSomething(in SomeType something){
int local(){
return something.anInt;
}
return local();
}
Why does the compiler issue an error that the something variable cannot ...
1
vote
2
answers
373
views
nested functions calling with multiple args in python
This was the program for our test and I couldn't understand what is going on. This problem is called nested function problem.
def foo(a):
def bar(b):
def foobar(c):
return a + ...
0
votes
1
answer
665
views
VS Code C extension doesn't support GCC nested functions
I edit my C code with VS Code (1.17.0) with C/C++ Extension (1.12.0) that provides error checking. I compile my code with GCC compiler that supports nested functions. So if I write this
int foo(int x)
...
-1
votes
3
answers
168
views
Does Python not support closures unlike Lua? [duplicate]
I was learning about closures in Lua and came accross this code that works in Lua:
function newcounter()
local i = 0
function dummy()
i = i + 1
return i
return dummy
x = ...
-1
votes
1
answer
61
views
Calling a nested function with a string (window[]) in JS [duplicate]
How to call a nested function with only a string? eg:
function oot(wha) {
function inn(wha)
{
First.innerHTML+="Inner ["+wha+"]";
}
oot....
1
vote
2
answers
92
views
In nested function second function is not working
I created a useState hook to store the ID fetching from the first function., and the initial value of the hook is an empty string(''). But the problem is when I save the file two times the hook stores ...
0
votes
1
answer
44
views
In nested functions only the first function works
I've never used the nested functions before, and this seemingly simple task is giving me trouble. When I run this code only the first function work, and the second is completely unresponsive.
const ...
2
votes
3
answers
4k
views
Return function from nested function in Python
def method(x, y, z):
def nested_method(a, b, c):
if a + b + c < 7:
for i in range(0, 7):
if i == a + b +c
return i
nested_method(3, 4, 0)
...
-1
votes
4
answers
137
views
Using a function as function parameter
I tried to write a nested function to calculate the area. However, the program showed the name circle is not defined.
Could anyone please help providing a suggestion about this nested function ...
-1
votes
1
answer
255
views
Nested anonymous function wont run (javascript)
I am trying to make a callback function that has an anonymous function nested inside. My code looks something like this:
function submitGuess(guess) {
if (guess.length === 5) {
...
63
votes
1
answer
4k
views
Why does std::fs::write(...) use an inner function?
I'm new to Rust and have been looking through the source code a bit, and found this:
#[stable(feature = "fs_read_write_bytes", since = "1.26.0")]
pub fn write<P: AsRef<Path&...
-1
votes
2
answers
133
views
How can I gets inner function value in python?
I want to know what is the right syntax to gets the value of the outer_function (like the 1st printing below => the expected result) in python3:
def outer_function():
def inner_function():
...
0
votes
2
answers
888
views
memoization function in javascript
So I came across a momoize function when I was trying to understand how memoization really works, the solution has really had me thinking, the code below
const memoize = (fn) => {
const cache ...
0
votes
0
answers
145
views
Execution Time for Python Code Greatly Increased When Functions are Nested
I have a function as below:
def shuffle_n_split(combined_arr, n):
start_time = time.time() # adding for testing execution time
random.shuffle(combined_arr)
print("--- %s seconds ---&...
0
votes
1
answer
127
views
Python nested currying
I was trying to solve a codewars problem here, and I got a bit stuck. I believe I should be using nested currying in Python.
Let us just take the case of add. Let us constrain the problem even more, ...
0
votes
1
answer
774
views
Kotlin "variable expected" error when doing assignment to Array element
I'm writing the following nested function where dfsVisit uses the arrays "numCaminos" and "colores" declared in the outer function
However the kotlin compiler is giving me a "...
0
votes
5
answers
259
views
NodeJS - Call Nested Function from inside another nested Function
i have two nested functions, i want to call the second one inside the first one but i nodejs doesn't seem to recognize it.
function Main(){
this.NestedA = function(){
console.log('Hello from A')
...
0
votes
1
answer
528
views
Setting a value within a nested function
Been given this golang code, feel free critique is hard as my golang is rusty. Basic refresh token flow, however we are wrapping the functions in a TX function to allow rollback should something go ...