2,149 questions
0
votes
1
answer
66
views
Is there a way to make an anonymous that takes the left argument and the right argument?
For example, this function:
f:{x+y}
Is not what I want because to call the function, f[2;3] is required instead of 2 f 3. Is there a way to make the function such that 2 f 3 work?
I am using ngn/k, ...
0
votes
0
answers
84
views
How to include two named functions sequentially in one anonymous function
How do you include two named functions, which are not nested, in one anonymous function?
For example, say I have a file mainFunction.m which contains
function varargout = mainFunction(in1)
% in1 is ...
-2
votes
1
answer
98
views
Is it legal to declare a lambda after the last return in a C# function? [duplicate]
I was looking through the code of AutoMapper ASP.NET Core dependency injection, and in the AddAutoMapperClasses, I saw that they declared a lambda expression after the last return:
private static ...
4
votes
1
answer
83
views
Is there a way to make an anonymous function without output? [duplicate]
Is there a way to make an anonymous function without output?
I have variable for function_handle whose starting, default value is to do nothing. So I am doing func=@()[];. But I am also curious if ...
4
votes
1
answer
77
views
How to evaluate a MATLAB anonymous function that takes an arbitrary number of variables n, given a n-dimensional vector?
I'm relatively new to MATLAB so perhaps there's something I'm missing.
The task is the following: we must program a certain algorithm for optimizing a continuous function f: Rn ---> R. The thing is,...
0
votes
1
answer
125
views
How are closures implemented in Rust?
In many languages closures are implemented using a structure in combination with a standard associated function (with a fixed name) which provides a method of making the object "callable".
...
0
votes
0
answers
44
views
Anonymous function in array causes fatal error [duplicate]
I have the following class
<?php
namespace Core;
class Router
{
public $routes = [
[
'url' => '/register',
'controller' => BASE_PATH . 'controllers/registration/register....
0
votes
1
answer
66
views
Typing of anonymous function in nested dicts
I have a nested dict like this
function_dict_1 = Dict(
:f => Dict(
:func1 => x -> x^2
)
)
I want to call a strongly typed function, which receives this dict as an argument.
...
1
vote
1
answer
56
views
How to get anonymous function parameters information?
// normal function
fun something(a: String, b: String): String {
return "$a $b"
}
println(::something.parameters) <- not empty
but
// anonymous function
var something = fun(a: ...
1
vote
2
answers
99
views
Why does narrowing become forgotten inside a function expression?
I wish to define a function in a different way depending on whether a field in the provided value is null. I expect that the provided value's type will be appropriately narrowed inside the function ...
0
votes
2
answers
99
views
In PHP, how to recurse through a Closure when the variable name holding the anonymous function is a variable-variable
I have a list of about 100 articles, and within each article is a list of clauses. The clauses are a list of varying levels deep.
$clauses = array(
[
'Fields' => ['Clause' => 'clause 1', '...
0
votes
1
answer
55
views
Execute anonymous block from procedure
I have a table which consist of anonymous block in the column rule,
which needs to be executed from procedure.
Here is the sample data which looks like the real scenario.
Table emp:
create table emp (...
2
votes
3
answers
132
views
Trying to use an anonymous object in Perl
I have this script
use strict;
use warnings;
use Data::Dumper;
package Foo;
sub new {
bless { 'a' => 1,
'b' => sub { return "foo" }
}, $_[0]
};
my $foo = Foo-...
-1
votes
2
answers
108
views
Where are anonymous callback functions to setTimeout stored?
I have a simple program that looks like this:
console.log("Start of the program execution!");
setTimeout(() => {
console.log("I ran after a second!");
}, 1000);
console....
0
votes
1
answer
39
views
imap-ing over multiple glmers in R: Anonymous functions
I have this function:
mweFitModelsGLMER <- function(longData,
strModelName = "ID Rand Model",
strFormula = "phMeta_Toxicity ~ ...
1
vote
2
answers
111
views
Can I check if ReflectionType is instance of another type?
I want to check if a callable's return type is an instance of another type. For example, let's say I a have:
A class Pigeon which extends Animal.
A function addSupplier() which takes a callable ...
0
votes
1
answer
48
views
Capture the for-loop iteration value to create anonymous function for dynamically generated downloadHandler
I'm developing an R Shiny App building a list of graph and I want each data to be downloadable by a click on a button below each graph.
My problem is that the anonymous function created to handle the ...
0
votes
0
answers
33
views
In some cases, "this" in the function passed as an argument to the higher order function is Window or undefined. Please tell me the difference [duplicate]
class Foo {
m(f) {
f();
}
}
let foo = new Foo();
foo.m(function () {
console.log(this);
// Window
});
class Foo {
m(f) {
f();
}
}
class Boo {
m2() {
let foo = new ...
0
votes
0
answers
41
views
Assigning a TProc inside a non-generic inline method leads to compiler error. Why?
When trying to assign procedure begin end to a TProc in the code below,
I get a compiler error:
E2441 Inline function declared in interface section must not use local symbol '.TMyClass.DoesNotCompile$...
0
votes
1
answer
54
views
What is the difference between `function () {}` and `() => {}` in JavaScript? [duplicate]
I am trying to add a method to the Person constructor function but keep getting an output of "Hello undefined"
function Person(name, age) {
this.name = name;
this.age = ...
2
votes
2
answers
158
views
PHP chaining callback functions
I've encountered this code, but I can't understand its logic. Could someone explain why the output is the way it is?
<?php
$functions = [
function($next) {
echo 'A' ....
2
votes
3
answers
206
views
Is it necessary to use lambda symbol in Common Lisp?
I've been reading Paul Graham's ANSI Common Lisp recently, where he mentions
In Common Lisp, you can express functions as lists, but they are represented internally as distinct function objects. So ...
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:
// ...
4
votes
0
answers
209
views
Why can't C# infer the type of anonymous delegates/functions in some cases?
I'm using C# 12.
When assigning a function to an implicitly-typed (var) variable, C# can infer the type successfully, such as in this example:
// Scenario A
var func = () => "Hello World";...
1
vote
1
answer
126
views
Attach an anonymous function to an "onclick" attribute of a link
On various pages of a website I generate via JavaScript different click handlers attached to links in the innerHTML of an specific page element. I do it with a uitilty function like this:
function ...
5
votes
1
answer
313
views
What is the difference between an anonymous function and a function handle in MATLAB?
I hear these two terms, anonymous function and function handle being used to refer to something like f = @(x) x.^2 in MATLAB. But then I've also heard that these terms mean different things. How do ...
1
vote
0
answers
45
views
Simplifying a function handle using another function handle with partially given variable in Matlab
With the following code in Matlab"
f = @(a,x) a*x+3;
g = @(x) f(4,x)
I get g as a function handle of the function handle f.
g = @(x)f(4,x)
However, I want to get g as a function handle without ...
0
votes
1
answer
178
views
Return data from async anonymous function that is an argument to a non-anonymous function
I'm attempting to return the contents argument of an async anonymous function. The contents argument is populated within the anonymous functions block but on return it is undefined.
I've attempted ...
2
votes
2
answers
119
views
Elegant solution to the "Lambdas" vs "Generics" problem?
I am looking for a prettier solution here. The problem is to combine Generics and Lambda Expressions.
According to the Java Language Specification this it not possible the way I want.
So my question ...
3
votes
1
answer
202
views
How to read name of anonymous lambdas in Visual Studio call stack?
It's always been challenging to me to track anonymous lambdas in the call stack, so I wrote some sandbox code in order to deal with the issue:
int main() {
[] {
std::cout << "Hello ...
3
votes
1
answer
86
views
How are closures actually sent for evaluation in lambda expression calls
I'm trying to understand how closures are actually sent for lambda expressions calls:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int *A = (int *) malloc((...
4
votes
1
answer
196
views
In Julia, what is the type of an anonymous function when an outer scope is involved?
I can create an anonymous function within a list comprehension in Julia. I expect that this would create a type of Vector{Function}. Instead, the type is something like Vector{var"#2#4"}.
...
0
votes
1
answer
490
views
How to override anonymous function in JavaScript with Tampermonkey?
I have a function I want to override in an anonymous function with Tampermonkey.
(()=>{
/* other stuff */
function Zm(e) {
let {visible: t, onCancel: n} = e;
const ...
1
vote
0
answers
65
views
PHP: Write anonymous function to file for later use
Let's assume, we have an array with anonymous functions as values. It has following contents:
$fpool = [
'f1' => function($a){
if($a > 0){
return [$a*$a, $a+$a];
}...
0
votes
1
answer
249
views
function gives "2nd argument: not valid character data" error
I am new to elixir and I am trying to make a recursive anonymous function, but for some reason my anynymous function that works on it's own as expected throws me "2nd argument: not valid ...
0
votes
0
answers
34
views
I can't set the "onclick" attribute of an element in JS
I'm working in vanilla JS. Here is my function as of now
function displayQueue() {
queueDiv.innerHTML = "";
for (var i = 0; i < queue.length; i++) {
let newDiv = document....
0
votes
0
answers
78
views
MATLAB optimization function variable assignment in anonymous function
I have an optimization problem in MATLAB and I'd like to be able to write an anonymous function to pass to the optimization function.
The function I am minimizing is a function of x, but I am required ...
0
votes
1
answer
70
views
Is anonymous function expression?
Is an anonymous function expression? if it is, why can not we use it wherever JavaScript expects an expression?
Example :
const result = String(function () {
return 2;
});
what variable returns :
...
0
votes
0
answers
74
views
How to execute/override a JavaScript function declared in anonymous function
How can I execute a function that is defined in an anonymous function ?
For example, I've this method "openProfile" declared in anonymous function. I would like to override it / call it
...
0
votes
1
answer
80
views
delegate and cancellationtoken troubleshooting
I can't understand why I'm getting System.NullReferenceException: Object reference not set to an instance of an object. exception.
I would like to pass the delegate ConnectAsyncDelegate to Commit ...
0
votes
1
answer
105
views
Is it safe to use the reference result of a function within an anonymous function which is used as the parameter in C#?
Is it safe to use the reference result of a function within an anonymous function which is used as the parameter?
Following is a simplified example:
ClassA result = null;
result = instanceA....
0
votes
2
answers
44
views
replacing elements of character vector with anonymous function does not return full vector
I'm confused by the following behaviour:
y <- letters |>
(\(x) x[stringr::str_which(x, "a|e")] <- c("1", "2"))()
which returns [1] "1" "2"
...
1
vote
1
answer
849
views
Binding variable in loop changes it's type
I'm trying to make some order in a script that uses nicegui. I'm using a dictionary to store all button labels and the pages they will redirect to.
I'm iterating over all keys in pages dictionary and ...
1
vote
0
answers
81
views
SciPy loadmat fails to load matlab structures with anonymous functions when simplify_cells=True
Scipy.io.loadmat fails to load matlab structures from .mat files when they contain anonymous functions if the simplify_cells switch is set to True. I believe the reason is because loadmat registers ...
0
votes
1
answer
220
views
Typescript - Anonymous generic function
I've read quite a few things on the topic and got myself confused, if it turns out the answer is out there, I'll delete this question.
Why would that not work:
type SanitizeFunction = <T extends ...
1
vote
1
answer
1k
views
Use on parenthesis () or use curly brackets {} in react component
I'm testing a react component, but have problems using an array map where is define an anonymous arrow function, and after arrow (=>) I use curly brackets. Then the inside code could not be ...
0
votes
1
answer
179
views
Per-iteration variable in Nim?
var functions: seq[proc(): int] = @[]
functions.add(proc(): int = 233)
for i in 1 .. 5:
functions.add(proc(): int = i)
for i in 1 .. 5:
echo functions[i]()
output
5
5
5
5
5
Seems like Nim stores ...
1
vote
1
answer
80
views
Accessing the first index of an anonymous function [duplicate]
If I have an anonymous function in MATLAB, say
f = @(t) [t, t+5];
and I wanted to create a new anonymous function g that accesses the first index of f, so that, in this example,
g = @(t) t;
how can ...
0
votes
1
answer
102
views
Create an Anonymous Function with no Parameter in Scala
We know that in Scala reflection, we can invoke a method using
clazz.getDeclaredMethod("method").invoke(instance, parameters)
where the function signature of invoke is Object invoke(Object ...
0
votes
2
answers
450
views
value nonEmpty is not a member of Object
Below code works fine on Scala 2.11 and getting error "value nonEmpty is not a member of Object" on Scala 2.12. Can someone provide a solution?
val ds = spark.createDataset(List("abc&...