Erlang mode

1
%% -*- mode: erlang; erlang-indent-level: 2 -*-
2
%%% Created :  7 May 2012 by mats cronqvist <masse@klarna.com>
3
 
4
%% @doc
5
%% Demonstrates how to print a record.
6
%% @end
7
 
8
-module('ex').
9
-author('mats cronqvist').
10
-export([demo/0,
11
         rec_info/1]).
12
 
13
-record(demo,{a="One",b="Two",c="Three",d="Four"}).
14
 
15
rec_info(demo) -> record_info(fields,demo).
16
 
17
demo() -> expand_recs(?MODULE,#demo{a="A",b="BB"}).
18
 
19
expand_recs(M,List) when is_list(List) ->
20
  [expand_recs(M,L)||L<-List];
21
expand_recs(M,Tup) when is_tuple(Tup) ->
22
  case tuple_size(Tup) of
23
    L when L < 1 -> Tup;
24
    L ->
25
      try
26
        Fields = M:rec_info(element(1,Tup)),
27
        L = length(Fields)+1,
28
        lists:zip(Fields,expand_recs(M,tl(tuple_to_list(Tup))))
29
      catch
30
        _:_ -> list_to_tuple(expand_recs(M,tuple_to_list(Tup)))
31
      end
32
  end;
33
expand_recs(_,Term) ->
34
  Term.
35
 
 

MIME types defined: text/x-erlang.