[erlang-questions] The display/1Gotcha

Olivier BOUDEVILLE <>
Wed Jan 26 11:14:51 CET 2011


Hi Kenneth, Hi Lukas,

Thanks for your answers.  At first I was not able to reproduce the issue 
on a minimal example, but, as you both hinted, original code was correct 
and should not have led to a local function being shadowed by a 
"built-in": apparently the culprit is the smart_exception parse transform.

At least this is what is suggested by:

"""
-module(minimal_test).

-export([ run/0, display/1 ]).

run() ->
     display( "Smart exceptions do not seem to work properly." ).

display( T ) ->
     io:format( "My function was called, really?!?~n" ),
     throw( {called_with,T} ).
"""

Then a vanilla compilation works as expected, whereas the one with 
smart_exception behaves wrongly:

"""
> erl
Erlang R14B01 (erts-5.8.2) [source] [64-bit] [smp:8:8] [rq:8] 
[async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.8.2  (abort with ^G)
1> c(minimal_test).
{ok,minimal_test}
2> minimal_test:run().
My function was called, really?!?
** exception throw: {called_with,"Smart exceptions do not seem to work 
properly."}
     in function  minimal_test:display/1
3> c(minimal_test,[{parse_transform, smart_exceptions}]).
{ok,minimal_test}
4> minimal_test:run().
"Smart exceptions do not seem to work properly."
true
"""

It looks like that, unless in my code I use ?MODULE:display/1, 
erlang:display/1 will be called instead if smart exceptions are used.

(by the way, I am using the devel version of smart_exception that I 
downloaded a month ago, since there were an issue with the stable version 
as well, as described in 
http://erlang.2086793.n4.nabble.com/Problems-With-Smart-Exceptions-td3095862.html)

So, unless I am mistaken, I suppose smart exceptions should better be 
disabled? 
This is a bit of a pity as it is a quite nice feature, useful to avoid 
additional intellectual puzzles.

Best regards,

Olivier Boudeville.
---------------------------
Olivier Boudeville

EDF R&D : 1, avenue du Général de Gaulle, 92140 Clamart, France
Département SINETICS, groupe ASICS (I2A), bureau B-226
Office : +33 1 47 65 59 58 / Mobile : +33 6 16 83 37 22 / Fax : +33 1 47 
65 27 13



 
25/01/2011 17:09

A

cc

Objet
Re: [erlang-questions] The display/1Gotcha






Hi,

I don't understand what you mean please provide a complete example.

If we for example have this module

-module(dtest).

-export([f/0]).

f() -> display("String").

display(String) ->
  {local_display_called_with,String}.

Then in both R13B04 and in R14A (when we introduced a change in semantics
so that autoimported BIFs no longer override local functions) the local 
function
named display will be called when you call dtest:f().

Also note that erlang:display/1 is not an autoimported BIF. You must 
always
call it giving the modulename erlang.

/Kenneth Erlang/OTP Ericsson

On Tue, Jan 25, 2011 at 4:32 PM, Olivier BOUDEVILLE
<> wrote:
> Hi,
>
> Wouldn't it be nice if erlang:display/1 did not silently shadow any
> user-defined display/1? I have been bitten more than once by this.
>
> Currently, defining in a module display/1 and calling it from another
> function directly, without mentioning a module (ex: 'f(Term) ->
> display(Term).') will call erlang:display/1instead of calling the
> lesser-astonishing ?MODULE:display/1.
>
> As erlang:display/1is not so very well-known and display is a rather
> common verb, maybe this would deserve forcing its call with an explicit
> module prefix (i.e. 'erlang:display(Term)'; if it is possible not to
> auto-import it) or at least issue a warning like "warning: local 
function
> display/1 will be shadowed by erlang:display/1"?
>
> Best regards,
>
> Olivier Boudeville.
> ---------------------------
> Olivier Boudeville
>
> EDF R&D : 1, avenue du Général de Gaulle, 92140 Clamart, France
> Département SINETICS, groupe ASICS (I2A), bureau B-226
> Office : +33 1 47 65 59 58 / Mobile : +33 6 16 83 37 22 / Fax : +33 1 47
> 65 27 13
>
>
>
> Ce message et toutes les pièces jointes (ci-après le 'Message') sont 
établis à l'intention exclusive des destinataires et les informations qui 
y figurent sont strictement confidentielles. Toute utilisation de ce 
Message non conforme à sa destination, toute diffusion ou toute 
publication totale ou partielle, est interdite sauf autorisation expresse.
>
> Si vous n'êtes pas le destinataire de ce Message, il vous est interdit 
de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou 
partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de 
votre système, ainsi que toutes ses copies, et de n'en garder aucune trace 
sur quelque support que ce soit. Nous vous remercions également d'en 
avertir immédiatement l'expéditeur par retour du message.
>
> Il est impossible de garantir que les communications par messagerie 
électronique arrivent en temps utile, sont sécurisées ou dénuées de toute 
erreur ou virus.
> ____________________________________________________
>
> This message and any attachments (the 'Message') are intended solely for 
the addressees. The information contained in this Message is confidential. 
Any use of information contained in this Message not in accord with its 
purpose, any dissemination or disclosure, either whole or partial, is 
prohibited except formal approval.
>
> If you are not the addressee, you may not copy, forward, disclose or use 
any part of it. If you have received this message in error, please delete 
it and all copies from your system and notify the sender immediately by 
return message.
>
> E-mail communication cannot be guaranteed to be timely secure, error or 
virus-free.
>




Ce message et toutes les pièces jointes (ci-après le 'Message') sont établis à l'intention exclusive des destinataires et les informations qui y figurent sont strictement confidentielles. Toute utilisation de ce Message non conforme à sa destination, toute diffusion ou toute publication totale ou partielle, est interdite sauf autorisation expresse.

Si vous n'êtes pas le destinataire de ce Message, il vous est interdit de le copier, de le faire suivre, de le divulguer ou d'en utiliser tout ou partie. Si vous avez reçu ce Message par erreur, merci de le supprimer de votre système, ainsi que toutes ses copies, et de n'en garder aucune trace sur quelque support que ce soit. Nous vous remercions également d'en avertir immédiatement l'expéditeur par retour du message.

Il est impossible de garantir que les communications par messagerie électronique arrivent en temps utile, sont sécurisées ou dénuées de toute erreur ou virus.
____________________________________________________

This message and any attachments (the 'Message') are intended solely for the addressees. The information contained in this Message is confidential. Any use of information contained in this Message not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval.

If you are not the addressee, you may not copy, forward, disclose or use any part of it. If you have received this message in error, please delete it and all copies from your system and notify the sender immediately by return message.

E-mail communication cannot be guaranteed to be timely secure, error or virus-free.


More information about the erlang-questions mailing list