Partial funciton applications and parentheses?
Dimitry Golubovsky
golubovsky@REDACTED
Mon Mar 15 04:11:55 CET 2010
Hi,
Given the following short program:
%%%%%%%%%%%%%%%%%%%%%%%%%
-module(clos).
-export([start/0]).
clos1(X) ->
fun(Y) ->
U = Y(X),
io:format("Result: ~B~n", [U]),
ok
end.
clos2(X) ->
fun(Y) ->
U = X + Y,
io:format("Result: ~B~n", [U]),
ok
end.
z() -> fun(X) -> X * X end.
start() -> (clos1(2)) (z()),
(clos2(2)) (3).
%%%%%%%%%%%%%%%%%%%%%%%%%
where clos1 and clos2 form sort of partial function application with
their first argument, and then resulting fun is applied to the second
argument.
Why are parens necessary around calls to clos1 and clos2? Without
these parens, I get "syntax error before: '('" messages.
Having them without parens that is, clos2 (2) (3) would IMHO look much better.
Thanks.
--
Dimitry Golubovsky
Anywhere on the Web
More information about the erlang-questions
mailing list