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 327209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:22:51+00:00 2026-05-12T09:22:51+00:00

Found the following snippet on the Closure page on wikipedia //# Return a list

  • 0

Found the following snippet on the Closure page on wikipedia

//# Return a list of all books with at least 'threshold' copies sold.
def bestSellingBooks(threshold: Int) = bookList.filter(book => book.sales >= threshold)
//# or
def bestSellingBooks(threshold: Int) = bookList.filter(_.sales >= threshold)

Correct me if I’m wrong, but this isn’t a closure? It is a function literal, an anynomous function, a lambda function, but not a closure?

  • 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-12T09:22:51+00:00Added an answer on May 12, 2026 at 9:22 am

    Well… if you want to be technical, this is a function literal which is translated at runtime into a closure, closing the open terms (binding them to a val/var in the scope of the function literal). Also, in the context of this function literal (_.sales >= threshold), threshold is a free variable, as the function literal itself doesn’t give it any meaning. By itself, _.sales >= threshold is an open term At runtime, it is bound to the local variable of the function, each time the function is called.

    Take this function for example, generating closures:

    def makeIncrementer(inc: Int): (Int => Int) = (x: Int) => x + inc
    

    At runtime, the following code produces 3 closures. It’s also interesting to note that b and c are not the same closure (b == c gives false).

    val a = makeIncrementer(10)
    val b = makeIncrementer(20)
    val c = makeIncrementer(20)
    

    I still think the example given on wikipedia is a good one, albeit not quite covering the whole story. It’s quite hard giving an example of actual closures by the strictest definition without actually a memory dump of a program running. It’s the same with the class-object relation. You usually give an example of an object by defining a class Foo { ... and then instantiating it with val f = new Foo, saying that f is the object.

    -- Flaviu Cipcigan

    Notes:

    • Reference: Programming in Scala, Martin Odersky, Lex Spoon, Bill Venners
    • Code compiled with Scala version 2.7.5.final running on Java 1.6.0_14.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found the following code snippet: List[T] forSome { type T } The forSome
I found the following snippet (I think in Wikipedia) that creates a different run-time
In this tutorial I've found the following snippet: deposit :: (Num a) => a
I found a script which has the following snippet:- userid=`expr \`id\` : .*uid=[0-9]*(\(.[0-9a-z]*\)) .*`
I found the following code snippet here : with TClipper.Create do try AddPolygon(subject, ptSubject);
I'm using the following snippet of code in an MVC Action to return an
In a response elsewhere, I found the following snippet: In general it is nicer
Reviewing a quite old project I found the following curious code snippet (only relevant
What does the phrase std::string::npos mean in the following snippet of code? found =
What does isset($_SESSION) mean? I found the following code snippet- if (!isset($_SESSION)) { //

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.