All Questions
14 questions
0
votes
1
answer
210
views
Scope error when returning function from function [duplicate]
I am having issues with using function generators in python, i.e. returning functions from a function, where some of the inputs are defined via the outer function's arguments, yielding a function with ...
9
votes
2
answers
4k
views
How to implement a multi-level currying function in Rust?
I attempt to implement a currying function similar to Functional Programming Jargon in Rust:
fn add_origin(x: i32) -> impl Fn(i32) -> i32 {
return move |y| {
x + y
};
}
fn main()...
0
votes
1
answer
58
views
What is the flow of execution with this compose function passed into Javascripts reduce?
I just want to know how reduce works in the case of code below(which was provided by a stackoverflow user in my previous question, i'm asking this question as his code snippet led to me having more ...
0
votes
1
answer
98
views
Is there anyway to tell if a function has a state in Javascript?
a = function() {
if(this.n === undefined) {
this.n = 0;
}
this.n += 1;
return(this.b);
}
b = function() {
return(5);
}
In this case a would stateful, and b would be ...
0
votes
1
answer
571
views
Is closure is the way to avoid global variable?
I know that using global variable is not good practice and programmers should avoid it when possible.
func foo(a *A) func() *A {
return func() *A {
return a
}
}
If I call foo_closure ...
0
votes
1
answer
55
views
R: closure can't find object until called
I have a problem with a higher order function in R:
power <- function(x , modify){
return(
function(y){
return( modify( y^x ) )
}
)
}
mod <- function(z){z+1}
sq <-...
1
vote
0
answers
2k
views
What is the best way to implement a parametric function?
Since Python believes There should be one-- and preferably only one --obvious way to do it. I wonder if there is a best way to use parametric functions in Python.
I came across with two approaches, ...
-1
votes
1
answer
127
views
Swift: Calling impure function with another function
I am attempting to use a helper function to call an input context sensitive function within the same context. Within the context of a class function called 'drawGrid()' I have the following code and ...
2
votes
2
answers
53
views
Why would a function be returned in this example instead of just a string
In an answer to this question, I can see the value of i being retained by sort of throwing it into another function:
var funcs = [];
function createfunc(i) {
return function() { console.log("My ...
4
votes
3
answers
484
views
"Side-effecting lexical closure" vs function in Scala
In his answer's comment section, Apocalisp states the following:
Well, you did ask for a function. A side-effenting [sic] lexical closure
is emphatically not a function.
What exactly does he mean ...
1
vote
3
answers
132
views
Can someone explain to me the difference between a Function Object and a Closure
By "Function Object", I mean an object of a class that is in some sense callable and can be treated in the language as a function. For example, in python:
class FunctionFactory:
def __init__ (...
0
votes
5
answers
202
views
is this a good example of a closure?
I saw this as an example on MDN and didn't understand why this was a Good Thing (TM).
function makeSizer(size) {
return function() {
document.body.style.fontSize = size + 'px';
...
6
votes
3
answers
2k
views
Do you use Template Method Pattern in programming languages with closures/delegates/function pointers?
I have been going back and forth between C# and Java for the last 8 years.
One thing that strikes me is that I have completely stopped using the "Template Method" design pattern in C#. Actually, in ...
999
votes
18
answers
192k
views
What is the difference between a 'closure' and a 'lambda'?
Could someone explain? I understand the basic concepts behind them but I often see them used interchangeably and I get confused.
And now that we're here, how do they differ from a regular function?