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.
51 questions
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 ...
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/...
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?
...
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
...
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 ...
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 ...
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 ...
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 ...
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:
...
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,...
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 ...
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
...
-3
votes
1
answer
80
views
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 ...
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 ...