Skip to main content

Questions tagged [closure]

A function (often anonymous) bound to the referencing environment in its original lexical scope in such a way that it will still have access to that environment (its variables and other references) if executed outside that scope.

5 votes
1 answer
94 views

Advent of Code 2015 "Not Quite Lisp", in Common Lisp (Part 2)

I asked for feedback on part 1 of this Advent of Code challenge: Advent of Code 2015 "Not Quite Lisp", in Common Lisp I have read everyone's feedback and done a lot of further reading. I ...
Mountain Man's user avatar
1 vote
2 answers
207 views

Each item of the array must loop and show message for some time (duration) and repeat msg each value of delay

Is there a better way to loop item of an array using forEach and make repeat it using setTimout/...
HackerMF's user avatar
  • 121
2 votes
0 answers
52 views

Make better solution for Bean counting example from "Eloquent JavaScript" book

How can this code be improved by "closuring" of functions here? ...
maxiwer's user avatar
  • 21
2 votes
1 answer
587 views

Display a Text() with a foreground color based on a condition

I decided to write a simple tab bar for macOS using Swift. tabs.swift ...
shreyasm-dev's user avatar
4 votes
1 answer
245 views

A tabbed calculator with tkinter

For learning purposes, I have written a small calculator app on Python with tkinter. I want to check if my design uses best practices for OOP and seek advice on ...
Mattey's user avatar
  • 59
2 votes
0 answers
55 views

Finding, substituting and executing values in dictionaries

I wrote this code for finding, substituting and executing values in dictionary, much like $() bash operator works. I used nested functions for this, forming ...
nonForgivingJesus's user avatar
2 votes
0 answers
75 views

Immutable-Object-like Structure in PHP

I made a closure-based PHP structure that behaves mostly like a classical object. To change the object's state, one must derive a new copy by passing the altered state to the ...
Benni's user avatar
  • 153
2 votes
1 answer
148 views

Toggling the background color of a page using JavaScript closures

This question is to see if I can get some input on the "design pattern" I tried to implement here. I'm just learning about closure in JavaScript and I think I'm starting to get it. I'm wondering if ...
Anthony's user avatar
  • 191
5 votes
2 answers
1k views

Groovy script to get average price per group from different data arrays

I've been trying to learn Groovy lately and I tried to solve a problem which involves designing a routine that will calculate the average Product price per Group. I have the following data: ...
Marcelo Tataje's user avatar
7 votes
1 answer
2k views

Logging with decorators (passing log file name as argument)

This is for some quantum mechanics software so there will be references to molecules/atoms etc but the core issue is a python logging one, unrelated to all that. I have a couple of logging decorators,...
QuantumChris's user avatar
  • 1,405
3 votes
1 answer
409 views

Rust closure to be called on a cache miss

The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash map ...
qwerty's user avatar
  • 33
2 votes
1 answer
163 views

Closure implementation

I have custom cell of tableview which is used as header as well as normal cell. In custom cell I have this properties ...
Prashant Tukadiya's user avatar
-3 votes
1 answer
80 views

Javascript - How does this preservation of variable works in Closure javascript? [closed]

...
sofs1's user avatar
  • 97
11 votes
2 answers
2k views

Throttling execution of a function

I have a Javascript function that calls my backend API using AJAX, let's say, updateDataUsingAjax. This is a resource intensive process, and I do not wish to allow ...
Nisarg Shah's user avatar
1 vote
2 answers
138 views

Performing a sum with Swift

I wrote the following in Swift to perform a sum: let total:Double = session.courses.reduce(0) { $0 + $1.totalPrice() } It's concise, it does the job but it does ...
Arnaud's user avatar
  • 111

15 30 50 per page