diff options
author | Anthony Ramine <[email protected]> | 2012-11-12 10:02:58 +0100 |
---|---|---|
committer | Anthony Ramine <[email protected]> | 2013-12-12 12:46:31 +0100 |
commit | ad882c4ae17d23fd0ce0affbf2cccefc264de6a9 (patch) | |
tree | fe141b9f249c3eae2c76c3fc5f7f931cc45b57c9 /lib/stdlib/src/shell.erl | |
parent | 8261c96c35d0691dc2619456a29ee41c1b944b1c (diff) | |
download | otp-ad882c4ae17d23fd0ce0affbf2cccefc264de6a9.tar.gz otp-ad882c4ae17d23fd0ce0affbf2cccefc264de6a9.tar.bz2 otp-ad882c4ae17d23fd0ce0affbf2cccefc264de6a9.zip |
Support named funs in the shell
The current code for the evaluation of ordinary funs is dependent
on the order on variables in the fun environment as returned by
erlang:fun_info(Fun, env).
To avoid the problem in the future, make sure that we only have one
free variable in the funs that we will need to inspect using
erlang:fun_info(Fun, env).
Diffstat (limited to 'lib/stdlib/src/shell.erl')
-rw-r--r-- | lib/stdlib/src/shell.erl | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl index 0d2fc47d13..3b90542452 100644 --- a/lib/stdlib/src/shell.erl +++ b/lib/stdlib/src/shell.erl @@ -424,6 +424,8 @@ expand_expr({remote,L,M,F}, C) -> {remote,L,expand_expr(M, C),expand_expr(F, C)}; expand_expr({'fun',L,{clauses,Cs}}, C) -> {'fun',L,{clauses,expand_exprs(Cs, C)}}; +expand_expr({named_fun,L,Name,Cs}, C) -> + {named_fun,L,Name,expand_exprs(Cs, C)}; expand_expr({clause,L,H,G,B}, C) -> %% Could expand H and G, but then erl_eval has to be changed as well. {clause,L,H, G, expand_exprs(B, C)}; @@ -1313,6 +1315,11 @@ list_bindings([{Name,Val}|Bs], RT) -> F = {'fun',0,{clauses,FCs}}, M = {match,0,{var,0,Name},F}, io:fwrite(<<"~ts\n">>, [erl_pp:expr(M, enc())]); + {named_fun_data,_FBs,FName,FCs0} -> + FCs = expand_value(FCs0), % looks nicer + F = {named_fun,0,FName,FCs}, + M = {match,0,{var,0,Name},F}, + io:fwrite(<<"~ts\n">>, [erl_pp:expr(M, enc())]); false -> Namel = io_lib:fwrite(<<"~s = ">>, [Name]), Nl = iolist_size(Namel)+1, |