[erlang-questions] Erlang4Android

Tony Rogvall <>
Sat Jan 19 15:13:54 CET 2013


On 18 jan 2013, at 16:50, Loïc Hoguin <> wrote:

> Dialyzer will complain if the function is undefined. It also breaks expectations, what's the type going in? Out?
> 
> You shouldn't use it.
> 
I did not see a smiley, serious man.

Of course you must use it, it is there!

For example:
- I am currently building a version system for Erlang modules and can use this feature
to implement proof of concept. The function can be used as dispatcher to different versions,
one small component in the implementation of the POC.

- Implement curry of functions with a little help of a simple parse_transform.
	-module(curry).
	-export([add/2]).
	add(X,Y) -> X + Y.
	foo(X,Y,Z) -> X+Y-Z.

	%% some parse_transform magic may generate this
	'$handle_undefined_function'(add, [X]) -> fun(Y) -> add(X,Y) end;

	'$handle_undefined_function'(foo, [X]) -> fun(Y) -> fun(Z) -> foo(X,Y,Z) end end;
	'$handle_undefined_function'(foo, [X,Y]) -> fun(Z) -> foo(X,Y,Z) end;
	...

	Now we can call:

	(currry:add(1))(2)


- implement varadic functions also with a little help of parse_transform

	-module(m).

	sum(Xs) -> lists:sum(Xs).

	 %% some parse_transform magic may generate this
	'$handle_undefined_function'(sum, Xs) -> sum(Xs).

	Now we can call

	m:sum(1),
	m:sum(1,2,3,4).
	

- a flavour of the above is to make simple proxy modules, trace, debug...

And ... well the list can be extended with some creativity.

/Tony

> On 01/18/2013 04:32 PM, Tony Rogvall wrote:
>> Wow, this must be abused without hesitation.
>> 
>> Really nice !
>> 
>> /Tony
>> 
>> On 18 jan 2013, at 16:25, Björn Gustavsson <
>> <mailto:>> wrote:
>> 
>>> 
>>> 
>>> 
>>> On Tue, Jan 15, 2013 at 1:33 PM, Erik Reitsma <
>>> <mailto:>> wrote:
>>> 
>>>    On 01/15/2013 10:41 AM, Joe Armstrong wrote:
>>>>    Golly - I read the code - you modified error_handler.erl !!!!
>>>> 
>>>>    So what happens is ...
>>>> 
>>>>       I call android:fooBar(Args) - fooBar is not defined in android.erl
>>>>       so it's caught in error_handler and then android:rpc(fooBar,
>>>>    [...]) is called
>>>>       and this ends up as a Json call to a socket -
>>>> 
>>>    Yes, that is what happens.
>>>> 
>>> It might interest you to know, that in R16, you can have a handler for
>>> undefined functions in each module. (We needed that to implement the parse
>>> transformation for parameterized modules.)
>>> 
>>> This new feature has just been merged to the master branch:
>>> 
>>> https://github.com/erlang/otp/commit/209a479080214ab901116d48b90e91d6c056278d
>>> 
>>> /Bjorn
>>> 
>>> _______________________________________________
>>> erlang-questions mailing list
>>>  <mailto:>
>>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
>> "Installing applications can lead to corruption over time. Applications
>> gradually write over each other's libraries, partial upgrades occur,
>> user and system errors happen, and minute changes may be unnoticeable
>> and difficult to fix"
>> 
>> 
>> 
>> 
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
> 
> 
> -- 
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
> http://ninenines.eu

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130119/c8cb980d/attachment.html>


More information about the erlang-questions mailing list