summaryrefslogtreecommitdiff
path: root/lib/stdlib/test/shell_docs_SUITE_data/unknown_erlang_fun_to_list_1_func.txt
blob: ecd103b4964d484d3c238a4228ef62bc7b947757 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  -spec erlang:fun_to_list(Fun) -> String :: string()
                              when Fun :: function().

  Returns String that represents the code that created Fun.

  String has the following form, if Fun was created by a fun
  expression of the form fun ModuleName:FuncName/Arity:

  "fun ModuleName:FuncName/Arity"

  The form of String when Fun is created from other types of 
  fun expressions differs depending on if the fun expression was
  executed while executing compiled code or if the fun expression
  was executed while executing uncompiled code (uncompiled escripts,
  the Erlang shell, and other code executed by the erl_eval module):

  compiled code:
    "#Fun<M.I.U>", where M, I and U correspond to the values
    named module, index and uniq in the result of 
    erlang:fun_info(Fun).

  uncompiled code:
    All funs created from fun expressions in uncompiled code with
    the same arity are mapped to the same list by fun_to_list/1.

  Note:
    Generally, one can not use fun_to_list/1 to check if two
    funs are equal as fun_to_list/1 does not take the fun's
    environment into account. See erlang:fun_info/1 for how to
    get the environment of a fun.

  Note:
    The output of fun_to_list/1 can differ between Erlang
    implementations and may change in future versions.

  Examples:

    -module(test).
    -export([add/1, add2/0, fun_tuple/0]).
    add(A) -> fun(B) -> A + B end.
    add2() -> fun add/1.
    fun_tuple() -> {fun() -> 1 end, fun() -> 1 end}.
            

    > {fun test:add/1, test:add2()}.
    {fun test:add/1,#Fun<test.1.107738983>}

  Explanation: fun test:add/1 is upgradable but test:add2() is
  not upgradable.

    > {test:add(1), test:add(42)}.
    {#Fun<test.0.107738983>,#Fun<test.0.107738983>}

  Explanation: test:add(1) and test:add(42) has the same string
  representation as the environment is not taken into account.

    >test:fun_tuple().
    {#Fun<test.2.107738983>,#Fun<test.3.107738983>}

  Explanation: The string representations differ because the funs
  come from different fun expressions.

    > {fun() -> 1 end, fun() -> 1 end}. > 
    {#Fun<erl_eval.45.97283095>,#Fun<erl_eval.45.97283095>}

  Explanation: All funs created from fun expressions of this form in
  uncompiled code with the same arity are mapped to the same list by 
  fun_to_list/1.