Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:29:25+00:00 2026-05-15T22:29:25+00:00

what is closure and its correspondence example ? I have research a lot and

  • 0

what is closure and its correspondence example ?

I have research a lot and could not understand.
Please explain in generic programming language concept aspect and specific programming language aspect.

Please help.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:29:26+00:00Added an answer on May 15, 2026 at 10:29 pm

    Here is how I think of a closure….

    A function object consists of two things. The first thing is the code for the function, the second is the scope in which it executes. In a closure, the scope in which the function executes and the code are detached from each other. The same code can execute in a variety of scopes.

    If this were allowed in a completely unrestricted way it would result in great confusion. Even when it’s something as loose as dynamic scoping (the function inherits the scope of the place where it was called from) it becomes very confusing.

    Closures are a convenient way of specifying scope rules that make a lot of sense because they only require reading the code instead of tracing it. In a closure, the function gets the scope of where it was declared. If it was declared while executing another function, it gets the scope of that specific instance of the function’s stack. This is a lot simpler and easier to understand than being able to give the closure and arbitrary scope, or dynamic scoping.

    Here is an example of a trivial closure in Python:

    def outer():
        def closure():
            pass
        return closure
    

    Here the function closure is a closure. It doesn’t actually use any variables from the scope in which it was defined, so it’s pretty trivial, but it still is one.

    Here is a not-so-trivial, but still simple closure in Python:

     def outer(x):
          def closure():
              return x
          return closure
     f1 = outer(5)
     f2 = outer(6)
    

    Calling f1() will return 5 and calling f2() will return 6. As you can see, the function closure is part code, and part scope.

    When outer(5) is called, it creates a stack entry for the call that contains a version of the variable x holding the value 5. It then declares the function closure which gets that scope.

    When outer(6) is called, it creates a stack entry for the call that contains a version of the variable x holding the value 6. It then declares the function closure which gets that scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented an object as a closure in JavaScript, some of the methods
Suppose I have a garden-variety closure like this bare-bones sample: (let ((alpha 0) #|
I have a MySQL database holding hierarchical data using the Closure Table method. A
As far as I understand, Prototypal inheritance and closure are two incompatible ways for
This solution must use the google closure javascript library and not any other javascript
I have an array of objects that I generate from JSON.parse. I access its
See code below. I've tried to strip it to its bare bones. I have
It seems that myFunction in the following example loses its scope. $().grep(myArray, myFunction) By
I have a groovy class that has the ability to write its output to
I'm creating an application with Google Closure Library and its Compiler. To debug values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.