Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×

Comment Re:I'm disappointed (Score 1) 434

Let me try a different tack.

Imagine Java had function pointers added to it. You might be able to do such a thing using introspection, but I'm not sure.

Now define a lambda-accepting method that takes a lambda function as an argument.

The implementation specifies an anonymous method accepting the arguments of the function pointer signature inline with the invocation of the lambda-accepting method. Within the body of that anonymous function you have access to the variables of the enclosing method as well as the members of the method's class.

Because the anonymous method is an inline argument to the invocation of the lambda-accepting method, you can specify more than one lambda as an argument to that method.

With Erlang, everything is based on functions and function pointers, but their syntax and implementation are cleaned up greatly compared to a language like C++ so you have a much harder time hanging yourself.

It's also much lighter weight than a class method override, because you don't instantiate a new instance when the lambda body gets invoked, but pass the existing object instance of it's enclosing method.

Comment Re:Still 32GB barrier (Score 1) 434

For example, it prevents you from reading a binary object larger than 2^32 into memory for subsequent manipulation or serving up from cache. With modern media files, it's quite possible (and even common) to exceed the 2GB file size limit of 32 bits.

Comment Re:I'm disappointed (Score 1) 434

No, I think we're talking about different things.

With Erlang, any function that matches an argument signature can be passed to a function that can take a lambda. But with Erlang, a given function can take more than one lambda at the same time as an argument. The closest analogy I could think of with the Java approach is to override *multiple* methods with a single lambda specification, not jujst one.

So it's not polymorphic in the sense that I think you're describing. It's just a broader-scoped implementation.

For example, you might define one lambda in Erlang that gets the next value from some abstract container to be defined by the programmer. You might define another lambda to compare elements. The lambda-receiving function sort() accepts both, producing a sorted list based on the arbitrary "key" of the lambdas. I don't see any way of doing that with the Java approach, because there is no way to specify multiple lambda arguments for the implementation of sort().

In "normal" Java you could do it by expecting two interfaces for sort()'s arguments, so perhaps you could then specify lambdas of the interfaces, but I'm not sure. I'm pretty sure Java would mandate that you use classes, not interfaces, which kind of limits the generic approach that Erlang offers.

Comment Re:I'm disappointed (Score 3, Interesting) 434

I think the bigger reason they probably didn't do it is that Erlang only lets you assign a variable once, so there are no concurrency issues with read/write of variables. One of the neat side effects of this is that a service/method which takes a lambda argument can be parallelized behind the scenes without changing the meaning of the code execution.

Another thing that puzzles me is that Java lambdas seem to be based on the idea of overriding a method of a class. That seems to me to be a critically limiting way of implementing them vs. function prototypes/templates, as there is no way to specify multiple lambdas being passed to the evaluator.

Comment I'm disappointed (Score 2) 434

I'm disappointed. I expected Lambda functions to be closer to Erlang's implementation, where you can access the variables of the enclosing function/method safely. But perhaps the examples in the article are just too simplistic to show such behaviour.

Slashdot Top Deals

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...