Comment Re:I'm disappointed (Score 1) 434
Whereas with Erlang lambdas are anonymous inner methods/functions. Much lighter weight invocation, and no issues with trying to invoke something other than the default constructors.
Whereas with Erlang lambdas are anonymous inner methods/functions. Much lighter weight invocation, and no issues with trying to invoke something other than the default constructors.
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.
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.
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.
I'd hardly call it "difficult" to use, any more than it is to use the wrappers for the native types. Still, it would be *nice* if you could use "+" instead of "add()", but really that's just syntactic sugar.
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.
Sorry. I meant "BigDecimal".
How would your Decimal concept be any more powerful than Number?
The one thing I wish they'd have done with Number is added Precision and Scale to it's usage, which would be invaluable for things like financial and scientific calculations.
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.
The Congress and Senate and President of the US are traitors to the United States Constitution that they swore to uphold, not Snowden.
I'm tired of hearing that cop out.
Where are the protests?
The calls for the resignations or impeachment?
The demands for accountability?
You are responsible for the actions of your government. YOU.
Well, when you think the run the world, you tend to overestimate your power.
Personally I hope Snowden stays in Russia. Their nuclear arsenal would make the US think twice about trying to pull a "Bin Laden" on Snowden.
Obviously I meant to say "I'm not an American citizen."
As per usual the narcissistic US government thinks it runs the world. Fuck you all.
He has not acquired a fortune; the fortune has acquired him. -- Bion