-
Notifications
You must be signed in to change notification settings - Fork 638
Predicate JavaDoc claims they are lambdas or closures #1495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The word "lambda" is borrowed from lambda calculus, not from Java's syntactical definition of a "lambda expression". It also fits the wikipedia definition of a closure fairly well: "Operationally, a closure is a record storing a function[a] together with an environment.[" |
Thanks @mohrezaei but I do not get your point. Suppose that: Do you agree that And if so, are you claiming that |
Yes, in the general sense of lambda/closure, it is. See the wikipedia articles. lambda/closure has a long history far longer and richer than the meager implementation in Java. |
Thanks @mohrezaei Do you agree that BooleanPredicates.ALWAYS_TRUE is "a |
Sure. It's also an example of a constant function; it's even explicitly mentioned in the lambda calculus article: "Further, ( λ x . y ) represents the constant function x ↦ y, the function that always returns y, no matter the input." |
Thanks @mohrezaei
Are you using "lambda" and "closure" as synonymous terms? |
They are very closely related concepts. They are often mentioned together (e.g. from C++, just to broaden this a bit: "In C++11 and later, a lambda expression—often called a lambda—is a convenient way of defining an anonymous function object (a closure) right at the location where it's invoked or passed as an argument to a function.") If you're interested in the colloquial usage of the terms, read the first answer here. If you're interested in the historically accurate definition, read the second answer. |
Thanks @mohrezaei , that question is interesting, and there are definitely multiple senses for these terms. Is |
|
Thank you @mohrezaei I think the confusion is much clearer now. So, I do agree that The problem is the current description claims:
To give a perhaps clearer analogy, while many would agree that the string "10" is ten, that is technically incorrect. Even though the sequence of the digit 1 followed by the digit 0 can represent ten, that is only a representation, which is only valid in the Indo-Arabic numeral system. In different systems, "10" could represent two, or even sixteen. One way to convince oneself would be to imagine that the Indo-Arabic system and Arabic numerals would disappear. Would the number 10―the concept itself―disappear? No; ten is not "10", and it could still be represented as "X". And even before Roman numerals, the quantity ten existed. To go back to our topic, while |
To me, it doesn't matter how it was instantiated. What matters is how it behaves. Does it take a parameter and return a result? Yub, it sure is a lambda. If you want it in formal terms, any 8000 instance of a single function Java interface is a lambda or closure. I'm not sure what to make of your string example. It seems to hold the same sort of confusion about what something is (its true essence) and what it looks like (the characters somebody typed in). If there was a programming language where the literal (== true (== "17" (+ "10" "7"))) would it not be ten? A Java string In case it's still not clear: what Java labels as a lambda expression is just syntax. I don't care about syntax. |
Hi @mohrezaei
That's exactly my point.
Ah, sorry, I had misunderstood, but thank you, this is an excellent characterization of this confusion, which is rather semantic. There is lots of jargon used in IT, but properly speaking, a "lambda" in an expression. A function (just like a class) is not an expression. As for "closure", the term is much more ambiguous. If we take the
Just to clarify, the analogy was with a mathematical concept, not with Java.
Technically, a lambda expression is an expression. For example:
In the Java world, a lambda expression remains an expression, albeit one complying with a different syntax. For example, the following is a lambda expression which would correspond to the identify function in Java terminology:
A (Java) lambda expression which could represent
|
Source? It seems rather contradictory on its face. A "lambda expression" is an expression. Why would people go around using "lambda expression", "lambda term" (which is also an expression) and "lambda calculus" (which is not an expression), if lambda simply meant "lambda expression"??? I don't know how long you've been coding and how many languages you've been exposed to, but using the word "lambda" to refer to functions that can be passed around as arguments to other functions is a very typical usage of that word 1,2,3. Is it really that far a stretch to refer to the thing a lambda expression creates as a lambda? The purpose of the original sentence in the documentation is to give context. That assumes some shared notions. Clearly, "lambda" and "closure" are not part of your programming notions. I'm reasonably sure I didn't write that sentence, but it succinctly expresses the role a |
Right, that is my point: What current documentation means by "a lambda" (a lambda expression) is an expression.
There are very few people who know of multiple "lambda calculuses". Using "a lambda" meaning "a lambda calculus" would be cryptic. Obviously, nobody is saying that "lambda" simply means "lambda expression". I was assuming that "a lambda" meant a lambda expression since the noun "lambda" has no other common sense in the domain... but if you think that's incorrect, by all means tell us what you think it meant!
Neither do I ;-)
The Devil is in the details; if you take for example the last reference, it doesn't actually refer to functions by the term "lambda" (it only discusses "lambda expressions" and "lambda functions").
Well, if my mother had asked me 20 years ago to "fix her Internet", I would not have alerted ICANN that the Internet was broken before making sure that her desktop still had a shortcut to launch Internet Explorer. That is not to say that calling a browser or a browser installation "an Internet" is necessarily acceptable. As indicated right from the start, the sentence is (at least for me) understandable, but that doesn't mean it's acceptable. Context matters, and the official description of a core class of a foundational library should warrant minimal exactitude.
I'm afraid what's clearer is that reading or communication are not part of your strengths. As I already wrote, I am not against keeping the word "lambda" in the description. As long as it's used properly, it might even help if it doesn't mislead readers. |
Thank you @BrijeshPatra |
Ok, let's start there. Let's agree that there are two things: "lambda expression" and "lambda function". The wiktionary you referenced lists them as such.
Funny you should say that, because it's obvious you didn't see the clear usage of lambda-as-function-not-expressin in the first two links. Just so this point is a bit more clear, here are 3 more such references: Lambda comes from the Lambda Calculus and refers to anonymous functions in programming. "Lambdas" are a shortened name for anonymous functions
Incorrect. What the documentation currently means by lambda is a "lambda function". The defining feature of Predicate is the The wiktionary you referenced also includes "lambda function" as a derived term for lambda, and interestingly, that page refers to a "closure" as its hyponym. A reader seeing "a lambda or closure" deducing that the first term in that phrase refers to a lambda-expression instead of a lambda-function clearly has never read the wiktionary.
Seriously? You're equating calling a "lambda function" a "lambda" the same as calling a "browser" the "internet"? |
Hi @mohrezaei ,
Reading ability doesn't require a reader to accept everything he reads from random sources on the Internets. For example, to take your first reference, it's a confused piece whose author doesn't even understand what a code block is (and sorry if you were hoping to get it fixed, but it's so outdated it's still unaware of "Java lambda expressions").
And that will be the case of 100% of EC users. Not only is Wiktionary indeed unreliable, but it's also huge. Even if you only meant the English Wiktionary, it's already got millions of entries. Nevertheless, you are basically right. Technically, Java has no first-class functions, but one could argue that an object like one implementing
No, what I provided was just an analogy to distinguish understandability from correctness, clarity and acceptability. My point is that even if a description is understandable by us experts, it can be misleading and inappropriate in a given context. When my mother told me about her problems with "the Internet" 20 years ago, her voice tone indicated she wasn't sure about the word choice, and I could quickly validate my understanding if I wasn't sure how to interpret. Unfortunately, EC readers will have have much more difficulty determining if the author of My point was that as I wrote, context matters, and the JavaDoc of a core class of a foundational library with potential to be used by hundreds of thousands of developers should warrant minimal exactitude. In that context, calling a functional object a "lambda" just because it can serve as a callback is not merely unclear/incorrect―it's unacceptable. |
I feel like the conversation may be most productive if we focus here:
We could answer this in our Javadoc and clarify why our Predicate exists. Off the cuff:
Ours is not deprecated and we don't plan on getting rid of it. Keeping it doesn't seem to create a lot of problems, and getting rid of it may break code for some long-time users. |
Thank you very much @motlin That makes sense. I believe every element of your reply is interesting and worth documenting, so I recommend that the Javadoc provide at least those elements. However, it should be evaluated whether |
The
Predicate
interface's description reads:The first sentence is understandable but incorrect, just like it would be incorrect to claim that a Java
String
IS a list of letters between double quotes. AString
can be instantiated by a list of letters between double quotes, but it represents (is) a sequence of characters. Like other functional interfaces, a class implementing org.eclipse.collections.api.block.predicate.Predicate can indeed be instantiated by lambda expressions or closures, but it doesn't have to, and an object implementingPredicate
is neither a lambda expression nor a closure.I am unsure what exactly an org.eclipse.collections.api.block.predicate.Predicate represents, but this could take example from the JDK
Predicate
's description:By the way
I strongly discourage referring to a predicate as a "Filter". Filters and predicates are highly related concepts, but clearly different.
The text was updated successfully, but these errors were encountered: