Preparing for the 0.2 draft
Rémi Forax
forax at univ-mlv.fr
Fri Jan 29 14:25:20 PST 2010
Le 29/01/2010 21:05, Joshua Bloch a écrit :
> Alex,
>
> Thanks for your continued work on this, and for soliciting our input at this
> phase. I'm heading off for a weekend vacation, and will get back to you on
> Monday. I think it would be useful to solicit input from other interested
> parties as well, given the self-selected nature of this group. Very
> briefly:
>
> The "foo.()" invocation syntax looks like a winner,
>
>
> Agreed.
>
>
Don't agree.
Anyway, what is the proposed way to do reflection on a
lambda invocation method ?
>
>> and I am seriously considering
>> rearranging the function type syntax to have argument types first.
>>
>>
> This seems iffy. It is very much at odds with the way things look today. I
> think you'd have a better chance of making a facility that achieved
> widespread use by the working programmer if you didn't do this.
>
>
>
>
>> Requiring a lambda expression to denote its return type is also
>> increasingly appealing. SAM classes are staying for now.
>>
>>
> My natural inclination would be to permit but not require this. If the
> compiler can guess the type, great! If not, help the compiler. Just like
> type inference for generic method invocations.
>
>
>
>
>> The discussion of transparent 'this' v. non-transparent 'this' comes
>> down to the question of what a lambda in Java is for.
>>
>
> True, but I haven't heard *any *arguments in favor of the "transparent this"
> that are in any way applicable to Java. Maybe I'm being dense, but I believe
> it's cargo cult language design. In Java, I believe it would be a
> gratuitous inconsistency, pure and simple. And I believe it would bite us
> sooner rather than later. If I'm wrong, I'd love to see some compelling,
> practical examples where having this refer to the enclosing instance is
> useful (in Java).
>
public class AuthGroup {
private final List<User> userList;
private final int priority;
...
public List<User> getAuthorizedUsers() {
//filter works like filter in Python
return userList.filter(#(User user) (user.getPriority() >=
this.priority));
}
}
A lambda is an anonymous function so it's a function,
this is the receiver of the current method (a method is not a function),
I don't understand why you want to reference the current function
using 'this'.
If you want a reference to the current function one can use 'gizmo'
or any other name but not 'this'.
Let me try to explain it differently, there is two part in a lambda,
the declaration of the lambda, here: #(User user) and the expression
(or the block) of the lambda.
I see the declaration part of the lambda as a way to reify the lambda
expression
to an object.
As 'new' is used to reifies a class, the declaration of a lambda transforms
an expression (or a block) to an object.
If you agree about that, 'this' can not be used in a lambda expression
because trying to reference an object that doesn't exist make no sense.
>
> More next week,
>
> Josh
>
>
regards,
Rémi
More information about the lambda-dev
mailing list