9,053 questions
-2
votes
2
answers
104
views
How to use Perl `eval` to build a closure that executes the command in a string
In a CGI script that processes arrays of strings the user can supply for each field whether to match a string there or not.
If all user-specified criteria are fulfilled, the specific array should be ...
1
vote
1
answer
104
views
How to call an async closure multiple times [duplicate]
I am trying to get the following simple apply function to compile (simlified for example):
struct Context(i32);
pub async fn apply<F, Fut>(ctx: &mut Context, f: F)
where
F: Fn(&mut ...
1
vote
1
answer
89
views
Why doesn’t new Function have access to local variables in JavaScript? [duplicate]
I was experimenting with closures in JavaScript and ran into something confusing.
function outer() {
let x = 10;
return new Function("return x;");
}
const fn = outer();
console.log(fn());
I ...
1
vote
2
answers
81
views
How to store C callback with arguments for later?
I have a Rust stub library that implements a FFI of an API written in C, so the some of the types are fixed.
I have a function similar to this:
pub type StoreFileCb = ::std::option::Option<
...
2
votes
0
answers
105
views
Does closure variable capture introduce thread safety risks due to field implementation?
Follow-up to: Detailed Explanation of Variable Capture in Closures
Given that captured variables are implemented as fields in compiler-generated classes (as explained in the referenced answer), does ...
0
votes
0
answers
53
views
Why does setTimeout inside a loop print the same value? [duplicate]
I'm trying to understand how setTimeout works inside a loop in JavaScript. I expected it to print numbers from 1 to 5, each printed after one second, but instead, it prints the number 6 five times.
...
5
votes
1
answer
79
views
Why does this code that moves a closure into another closure and returns both even compile?
I have the following code:
fn test() -> (impl FnMut(&mut u8), impl FnMut(&mut u8)) {
let a = |v: &mut u8| {*v = 0};
let b = move |v: &mut u8| { a(v); println!("{}&...
0
votes
1
answer
185
views
Why is a lambda expression not just the syntactic sugar of a functor?
Consider the following code:
int main() {
int n = 0;
return [n] { return n; }(); // ok
}
According to https://cppinsights.io, the code above will be translated into the following code:
int ...
-2
votes
1
answer
72
views
Will new object assignment to same GLOBAL variable cause memory leaks?
I'm trying to set GLOBAL variable available across all modules of Node.js app.
module.exports = app => {
app.get('/config', async (req, res) => {
.....
const { data } = await axios....
0
votes
0
answers
35
views
Why does "let" behave differently from "var" inside a for loop with "setTimeout"? [duplicate]
I’m trying to understand the difference in behavior between let and var inside a for loop, especially when used with setTimeout.
Here’s a simple example:
for (var i = 0; i < 3; i++) {
setTimeout((...
0
votes
0
answers
36
views
Why does V8 deoptimize certain closures with inline caching despite seemingly monomorphic access patterns?
I'm debugging a performance regression in a hot code path and found that V8 is deoptimizing a function that uses closures in a monomorphic way. Here’s a simplified version of the pattern
function ...
2
votes
1
answer
96
views
powershell -Action Scriptblock doesn't care about closure
My problem is fairly simple:
I'm trying to execute a file on a timer elapsed event.
I use a closure to preserve the value of my variable.
But I think I struggle to understand what is the lifetime of ...
1
vote
1
answer
65
views
Lua stack and vararg functions
I'm curently exploring Lua (5.4.7) vm implementation, it's relatively simple but i can't figure our how return works in case of vararg functions.
functions with fixed amount of params are quite simple,...
1
vote
1
answer
56
views
dptree::filter_async problem with move semantic
I'm writing a bot on Rust via teloxide + tokio. I have this run method (called from main)
pub async fn run() {
dotenv::dotenv().ok();
pretty_env_logger::init();
log::info!("Starting ...
0
votes
0
answers
56
views
Statically compile Groovy DelegatingScript with delegated object containing method with closure
I have following classes
final class GroovyValidator {
@Override
public List<String> validate(String script) {
final CompilerConfiguration config = new CompilerConfiguration();
...