--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
Is there a page with the proposal set out? Have the authors of the
earlier proposals written up anything about this?
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
If an interface declares methods already defined in Object, they don't count either...
For instance, the interface java.util.Comparator has two methods:
int compare(T o1, T o2);
boolean equals(Object obj);
The second method is in there because it has some javadoc on it. Since Object has a method with the same signature, Comparator still qualifies as a SAM.
Roel
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
I think it shows it in its worst light, when others show examples it
is OK I guess...
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
hhmmm...
wouldn't that be
List<String> userNames = userList.map(#(User u)(
u.getName() // note: round parens, no ";", implicit "return"
));
or
List<String> userNames = userList.map(#(User u){
return u.getName(); // note: "return"
});
But yea, it's not so bad, considering that it's Java.
// Ben
Quite the opposite, I want to promote java-the-platform vs .net, ruby, etc.
Java is a great language if you want compatibility all the way back to 1.0 code, but in terms of having contemporary features and being fun to use it's already lost a great deal of mindshare.
Scala is, frankly, the lowest impact change for java developers willing to move to a better integrated functional syntax (at the cost of legacy functionality)
I *could* promote Java by defending an outdated legacy syntax that must be kept for reasons of backward-compatibility. I could also promote Star Trek by shouting down anyone who says that Kirk's character is over-acted. But to me, the true essence of Star Trek is perhaps better captured with Patrick Stewart at the helm...
And so it is with Java vs Scala, we may mourn the loss of mini-skirts from time to time (who doesn't?). Nevertheless, the end product is arguably better, and you have to admit that holo-decks are pretty cool - there are many stories that just wouldn't have been written without them (a bit like built-in FP then).
So did Star Trek NG denigrate the original series? I'd like to think not - it's full of nostalgia for me. I'd also like to think that Scala isn't denigrating Java, it's just the future of the same universe.
As for Scala mailing lists? Yes, I'm a frequent contributor there, where they boldly go to some amazing new places at times. The best part is that we manage to do so without the dilithium crystals failing every third episode, and I'm finding that I really don't miss it as a plot element all that much.
On 1 Jun 2010 12:32, "Reinier Zwitserloot" <rein...@gmail.com> wrote:
Oh, yeah, we'll just move every single existing java programmer over.
Easy peasy.
I get really annoyed at people who have this 'oh, give up java
already' vibe. If you don't care, that's fine. Why don't you go and be
positive on the scala mailing list, instead of being negative here?
Some of us are trying to make java a better language. If you'd rather
torch java's future to increase scala adoption, I don't want to talk
to you. The more languages the merrier, let them win on their merits,
not by the demerits of other languages. Also, it's all on the JVM.
When one JVM language gains strength, that solidifies the JVM as a
platform, which is good for all JVM languages. I want a strong Scala
*AND* a strong Java.
On Jun 1, 10:56 am, Kevin Wright <kev.lee.wri...@gmail.com> wrote:
> Syntax wise, we can be a lot s...
> On 1 June 2010 09:35, Moandji Ezana <mwa...@gmail.com> wrote:
>
>
>
>
>
> > On Tue, Jun 1, 2010 at 7:12 AM, Michael Neale <michael.ne...@gmail.com>wrote:
>
> >> I think it shows it in its worst light, when others show examples it
> >> is OK I guess...
>
...
> > javaposse+...@googlegroups.com<javaposse%2Bunsubscribe@googlegroups .com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/javaposse?hl=en.
>...
> mail/google talk: kev.lee.wri...@gmail.com
> wave: kev.lee.wri...@googlewave.com
> skype: kev.lee.wright
> twitter: @thecoda
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group...
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
So basically, this is just syntax sugar around single-method anonymous inner classes.
What really counts though is that we get 1st-class method handles.
the annoying "final limitation"
What really counts though is that we get 1st-class method handles.Agreed. That's pretty awesome. Also, the prospect that the VM might be able to make dynamic languages as fast or nearly as fast as static ones.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
A clarifying comment by Maurizio on lambda-dev claims that they are
currently implementing something that's similar to the straw man
presented by Mark Reinhold at Devoxx '09, with some of the tough
questions in it removed (such as using .() instead of plain parens to
'execute' a closure), so the widespread discussion on lambda-dev can
at least experiment better.
In otherwords, 'making the compiler-writer's job easy' is apparently
part of the plan, at least for now.
A standard function type in the JVM *already exists* in the jdk7
specs; it's called MethodHandle. There are already calls going out
amongst the alternative languages on the JVM crowd to start switching
to it. Also, partly motivated by the closures stuff, MethodHandle
objects will most likely gain a JVM-based 'asSam()' method which means
at least some of the structural typing that other languages offer can
be done 'natively' instead of working by using a lot of reflection
magic. So, Josh, Michael, time to lobby your friendly local
alternative language developer to get on the bandwagon :)
Learning java closure syntax is more complicated than learning scala?
You've got to be kidding me.
"Scala is, frankly, the lowest impact change for java developers willing to move to a better integrated functional syntax (at the cost of legacy functionality)"
Having a functional syntax that is closely integrated into a language (ideally from the point of conception) is a desirable thing. Unfortunately, this deep integration is not possible with Java due to backward-compatibility constraints.For Java developers wanting a syntax that is more natural and effortless than this proposal, it would therefore seem wise to look beyond Java-the-Language. In this broader space of alternate JVM languages the barrier to entry seems lowest for Scala, thanks to static typing and conscious efforts at making Java-Scala interop effortless. Scala can be initially used as though it were no more than a tidied-up variant of Java, allowing developers to become productive again in a very short space of time.
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
Actually, I think Reiner's example is subtly misleading since each
iteration of the for loop conceptually gets a fresh variable 'i',
else using the final modifier would not be possible.
The example, using current Java:
Runnable[] r = new Runnable[3];
for (final int i = 0 ; i < 3; i++)
r[i] = new Runnable() {
public void run() { System.out.println(i); }
};
for (int i = 0; i < 3; i++)
r.run();
Prints 1 2 3
I suspect that if Java didn't require final i, the results would still
be the same, because the implementation would still be forced to copy
values into compiler-generated fields of the inner Runnable() class on
allocation. There's no way to store a reference to a variable in Java.
Having the compiler silently promote i to a mutable object on the heap
just so everyone can share a copy would be the only way to get the
behavior Reiner suggests and that just seems baroque.
***
There seems to be a lot of confusion in this discussion. There 's an
important distinction that we're glossing over, which causes us to
talk past each other. What *exactly* is the closure capturing? The
*variable* or the variable's *value*? This distinction is often not
clear to users of languages that pass everything by value, like Java.
A few examples:
# python
def demo():
x = 0
def foo():
x = 1
foo()
print x # prints 0
The inner function foo() captures read-only access to the outer variable x,
which leads to some oddities. x=1 actually creates a new 'x' local to
foo, hiding the outer x. reading from x in foo before assigning to it
will get us the outer x. Trying this x = x + 1 leads to a runtime
error because the x must necessarily be interpreted as local to foo in
that expression, but that means we can't read a value from it (the
second x in the expression) since it hasn't been bound (assigned to)
yet.
Python is capturing read-only access to the outer *variable* itself.
How can I tell it's not simply copying the value?
def example():
x = 0
def foo(): print x
foo(); x = 1; foo(); # output: 0 1
// java
void demo() {
final int x = 0;
new Runnable() {
public void run() {
x = 1; // COMPILE ERROR
}
}.run();
System.out.println(x);
}
Java protects us from the sort of confusion that Python can produce by
requiring outer variables be marked as 'final'. That way, there is no
expectation that they can be mutated from within the inner function
(the Runnable). Yes, the 'final' requirement is a little pedantic, but
at least
it's clear what the expected behavior is.
They could just as easily have defined that outer variables get copied
to compiler generated instance fields upon inner class creation (which
is what happens) and that left them mutable.
In any event, Java is capturing a *copies* of the *values* of outer
variables in its closure-like inner classes.
(* Oberon: sorry about the shouting *)
PROCEDURE Demo();
VAR x: INTEGER;
PROCEDURE Foo();
BEGIN
x := 1;
END Foo;
BEGIN
x := 0;
Foo;
Out.WriteInt(x); (* prints 1 *)
END Demo;
Foo has read/write access to the actual *variable* x, which is why
this example prints 1. The trade-off in this case is that the inner
procedure Foo can not outlive the call to Demo that created it. Oberon
doesn't have true Closures. The language enforces this by only
allowing top-level procedures to be assigned to variables are returned
from Functions.
;; clojure
(defn demo []
(let [x (atom 0)] ;; only references are mutable in clojure
(letfn [(foo [] (swap! x (constantly 1)))]
(foo)
(print @x)))) ;; prints 1
In Clojure the example almost doesn't make sense. Clojure variables
are all effectively final. i.e. They're not "variable", they're just
names for *values*. But it turns out, that some of these values can be
Clojure reference types, which allow mutability with defined
concurrency semantics.
Like Java, Clojure's closures capture the *values* of outer bindings
when they are created.
;; scheme
(define (demo)
(let ((x 0)
(foo (lambda () (set! x 1))))
(foo)
(print x))) ;; prints 1
Unlike Clojure, Scheme is permissive about mutability. Like Oberon,
foo captures the *variable* x. Unlike Oberon, this binding continues
to exist even after the call to demo completes. That is, foo has a
lifetime independent of demo.
As far as I am concerned, all of the presented languages (apart from
Oberon) can be said to have closures. Where they differ is in how
exactly they capture the surrounding environment. Do they capture
*values* or *variables*? Are they funky like Python?
// Ben
> Runnable[] r = new Runnable[3];
> for (final int i = 0 ; i < 3; i++)
> r[i] = new Runnable() {
> public void run() { System.out.println(i); }
> };
> for (int i = 0; i < 3; i++)
> r.run();
>
> Prints 1 2 3
Prints 0 1 2
duh
//Ben
You're quite correct, I've gotten to used to
for (final Object a: array_of_Object), where this works. I would have
had to introduce a (final) temporary variable at the top of the loop
to make my example work.
for (int i = 0; i < 10; i++) {
final int temp = i;
... new Runnable() { ... temp ... };
// ben
[ ... snip ... ]
>> What *exactly* is the closure capturing? The
>> *variable* or the variable's *value*?
>
> The variable itself, not the value. Period. Always. In any language,
> or they're abusing the term "closure" even more than java already
> does. Java, to be precise, has never strayed from this definition
> either, and is not going to. Right now it doesn't really matter
> because java's reaction to capturing a non-final variable is always:
> Make it final first. And for final variables, the distinction between
> capturing the variable and its value is moot.
Good analysis. I guess where we differ is that I'm willing to accept
closures which copy only the values as sufficient. There are two
reasons for this:
(1) I'm getting away from mutable state in my programming anyway, and
as you point out the two approaches are indistinguishable when
variables are immutable. So, I'm not losing much by having closures
that copy values rather than capture variables.
(2) In my experience having closures capture mutable variables is
mostly useful for simulating stateful objects (e.g. doing OOP in
Scheme), but in Java we don't need to simulate objects and classes
using closures.
p.s. For those who haven't read it, there's a cute little koan about
the equivalence of objects and closures (in the full
variable-capturing sense) at the end of the post linked below:
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
The definition may be hotly debated in some circles (almost exclusively
Groovy and Python ones), but in most places the definition is well
understood and indeed well defined. From some dictionary or other:
. . . a closure is a data structure that holds an expression and
an environment of variable bindings in which that expression is
to be evaluated.
see also Simon L Peyton Jones, "The Implementation of Functional
Languages", Prentice-Hall, p.378, where different words are used but the
meaning is the same.
Language is indeed a living and mutating entity, but it much better not
to run headlong into "Humpty Dumpty Syndrome"
`When I use a word,' Humpty Dumpty said in rather a scornful
tone, `it means just what I choose it to mean -- neither more
nor less.'
In fact the meaning of a word is a social construct. Jargon is slightly
different in that there needs to be a common definition in order for the
term to be at all useful. There is currently a definition of closure
which works very well for almost all of the world of programming and
computing (except Groovy), let's stick to it.
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel...@ekiga.net
41 Buckmaster Road m: +44 7770 465 077 xmpp: rus...@russel.org.uk
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
On Jun 10, 9:44 am, Casper Bang <casper.b...@gmail.com> wrote:
> Once again, Stephen Colebourne to the rescue?Colebourne essentially proposes to deprecate checked exceptions. It
>
> http://mail.openjdk.java.net/pipermail/lambda-dev/2010-June/001544.html
>
> I like it, reads much easier than the Strawman proposal (people
> already have a hard enough time with bounds and co/contra-variance
> without tossing the throws keyword in there).
will be a cool day in heck before that happens.
Current discussion on the lambda mailing list suggests it may be
possible to do without the throws keyword in a type parameter.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
On Sun, Jun 13, 2010 at 8:52 PM, gafter <neal....@gmail.com> wrote:On Jun 10, 9:44 am, Casper Bang <casper.b...@gmail.com> wrote:
> Once again, Stephen Colebourne to the rescue?Colebourne essentially proposes to deprecate checked exceptions. It
>
> http://mail.openjdk.java.net/pipermail/lambda-dev/2010-June/001544.html
>
> I like it, reads much easier than the Strawman proposal (people
> already have a hard enough time with bounds and co/contra-variance
> without tossing the throws keyword in there).
will be a cool day in heck before that happens.
'Tis ok, us in Scalaland are already free. :)
Current discussion on the lambda mailing list suggests it may be
possible to do without the throws keyword in a type parameter.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
--
Viktor Klang
| "A complex system that works is invariably
| found to have evolved from a simple system
| that worked." - John Gall
Akka - the Actor Kernel: Akkasource.org
Twttr: twitter.com/viktorklang
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
--
You received this message because you are subscribed to the Google Groups "The Java Posse" group.
To post to this group, send email to java...@googlegroups.com.
To unsubscribe from this group, send email to javaposse+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.