Erlang

1 program Added 2025-10-22T09:35:55Z Model: anthropic/claude-3.5-sonnetTemp: 0.4 Evidence Report issue View issues
Aliases: erl
Provenance: commit 1c0806938d · authored 2025-10-22T11:35:56+02:00 · model anthropic/claude-3.5-sonnet

Sources mentioning this language

8 sources · pl_id: pl/erlang
LLM (this repo) · 1PldbLinguistPygmentsWikipediaHyperpolyglotRosettacodeWikidata · Q334879

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Paradigmsmulti-paradigm: concurrent · functional
Typingdynamic, strong
Designed byEricsson · Joe Armstrong · Robert Virding · Mike Williams
First appeared1986
Influenced byLisp · PLEX · Prolog · Smalltalk
LicenseApache License 2.0
Homepagehttps://www.erlang.org

Extensions claimed by this language

13 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.erllinguistprimary2.6M files
.erlpygmentsprimary2.6M files
.erlwikidataprimary2.6M files
.applinguistsecondary225.1K files
.eslinguistsecondary187.3K files
.espygmentssecondary187.3K files
.escriptlinguistsecondary9.5K files
.escriptpygmentssecondary9.5K files
.hrllinguistsecondary144.2K files
.hrlpygmentssecondary144.2K files
.xrllinguistsecondary5.1K files
.yrllinguistsecondary9.4K files
.hrlwikipediaproposed144.2K files

Related languages

Purerl (0.32)Luerl (0.32)Core Erlang (0.29)Erjang (0.29)ERDE (0.28)

LLM-contributed programs

Simple TCP Echo Server

Provenance: commit 1c0806938d · authored 2025-10-22T11:35:56+02:00 · model anthropic/claude-3.5-sonnet · Temp 0.4
code.erl · license: MIT · added: 2025-10-22T09:35:55Z
-module(echo_server).
-export([listen/1]).

listen(Port) ->
    {ok, Socket} = gen_tcp:listen(Port, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]),
    accept(Socket).

accept(Socket) ->
    {ok, Conn} = gen_tcp:accept(Socket),
    Handler = spawn(fun () -> handle(Conn) end),
    gen_tcp:controlling_process(Conn, Handler),
    accept(Socket).

handle(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Data} ->
            gen_tcp:send(Socket, Data),
            handle(Socket);
        {error, closed} ->
            ok
    end.

Real programs from Software Heritage

4 samples mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
pg2_fixed.erl · 12585 B · ext .erl · seen 5658× in SWH
via unique-primary
swh:1:cnt:8926b83b77a68a0a9758b0d10df9830cadbfefe8;origin=https://github.com/sky-big/RabbitMQ;anchor=swh:1:rev:ebf324290f3bfad4a713ba54be4a8ce24d0e84c3;path=/src/pg2_fixed.erl
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
%% This is the version of pg2 from R14B02, which contains the fix
%% described at
%% http://erlang.2086793.n4.nabble.com/pg2-still-busted-in-R13B04-td2230601.html.
%% The changes are a search-and-replace to rename the module and avoid
%% clashes with other versions of pg2, and also a simple rewrite of
%% "andalso" and "orelse" expressions to case statements where the second
%% operand is not a boolean since R12B does not allow this.

%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2010. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(pg2_fixed).

-export([create/1, delete/1, join/2, leave/2]).
-export([get_members/1, get_local_members/1]).
-export([get_closest_pid/1, which_groups/0]).
-export([start/0,start_link/0,init/1,handle_call/3,handle_cast/2,handle_info/2,
         terminate/2]).

%%% As of R13B03 monitors are used instead of links.

%%%
%%% Exported functions
%%%

-spec start_link() -> {'ok', pid()} | {'error', term()}.

start_link() ->
    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

-spec start() -> {'ok', pid()} | {'error', term()}.

start() ->
    ensure_started().

-spec create(term()) -> 'ok'.

create(Name) ->
    ensure_started(),
    case ets:member(pg2_fixed_table, {group, Name}) of
        false ->
            global:trans({{?MODULE, Name}, self()},
                         fun() ->
                                 gen_server:multi_call(?MODULE, {create, Name})
                         end),
            ok;
        true ->
            ok
    end.

-type name() :: term().

-spec delete(name()) -> 'ok'.

delete(Name) ->
    ensure_started(),
    global:trans({{?MODULE, Name}, self()},
                 fun() ->
                         gen_server:multi_call(?MODULE, {delete, Name})
                 end),
    ok.

-spec join(name(), pid()) -> 'ok' | {'error', {'no_such_group', term()}}.

join(Name, Pid) when is_pid(Pid) ->
    ensure_started(),
    case ets:member(pg2_fixed_table, {group, Name}) of
        false ->
            {error, {no_such_group, Name}};
        true ->
            global:trans({{?MODULE, Name}, self()},
                         fun() ->
                                 gen_server:multi_call(?MODULE,
                                                       {join, Name, Pid})
                         end),
            ok
    end.

-spec leave(name(), pid()) -> 'ok' | {'error', {'no_such_group', name()}}.

leave(Name, Pid) when is_pid(Pid) ->
    ensure_started(),
    case ets:member(pg2_fixed_table, {group, Name}) of
        false ->
            {error, {no_such_group, Name}};
        true ->
            global:trans({{?MODULE, Name}, self()},
                         fun() ->
                                 gen_server:multi_call(?MODULE,
                                                       {leave, Name, Pid})
                         end),
            ok
    end.

-type get_members_ret() :: [pid()] | {'error', {'no_such_group', name()}}.

-spec get_members(name()) -> get_members_ret().
   
get_members(Name) ->
    ensure_started(),
    case ets:member(pg2_fixed_table, {group, Name}) of
        true ->
            group_members(Name);
        false ->
            {error, {no_such_group, Name}}
    end.

-spec get_local_members(name()) -> get_members_ret().

get_local_members(Name) ->
    ensure_started(),
    case ets:member(pg2_fixed_table, {group, Name}) of
        true ->
            local_group_members(Name);
        false ->
            {error, {no_such_group, Name}}
    end.

-spec which_groups() -> [name()].

which_groups() ->
    ensure_started(),
    all_groups().

-type gcp_error_reason() :: {'no_process', term()} | {'no_such_group', term()}.

-spec get_closest_pid(term()) -> pid() | {'error', gcp_error_reason()}.

get_closest_pid(Name) ->
    case get_local_members(Name) of
        [Pid] ->
            Pid;
        [] ->
            {_,_,X} = erlang:now(),
            case get_members(Name) of
                [] -> {error, {no_process, Name}};
                Members ->
                    lists:nth((X rem length(Members))+1, Members)
            end;
        Members when is_list(Members) ->
            {_,_,X} = erlang:now(),
            lists:nth((X rem length(Members))+1, Members);
        Else ->
            Else
    end.

%%%
%%% Callback functions from gen_server
%%%

-record(state, {}).

-spec init([]) -> {'ok', #state{}}.

init([]) ->
    Ns = nodes(),
    net_kernel:monitor_nodes(true),
    lists:foreach(fun(N) ->
                          {?MODULE, N} ! {new_pg2_fixed, node()},
                          self() ! {nodeup, N}
                  end, Ns),
    pg2_fixed_table = ets:new(pg2_fixed_table, [ordered_set, protected, named_table]),
    {ok, #state{}}.

-type call() :: {'create', name()}
              | {'delete', name()}
              | {'join', name(), pid()}
              | {'leave', name(), pid()}.

-spec handle_call(call(), _, #state{}) -> 
        {'reply', 'ok', #state{}}.

handle_call({create, Name}, _From, S) ->
    assure_group(Name),
    {reply, ok, S};
handle_call({join, Name, Pid}, _From, S) ->
    case ets:member(pg2_fixed_table, {group, Name}) of
        true -> join_group(Name, Pid);
        _    -> ok
    end,
    {reply, ok, S};
handle_call({leave, Name, Pid}, _From, S) ->
    case ets:member(pg2_fixed_table, {group, Name}) of
        true -> leave_group(Name, Pid);
        _    -> ok
    end,
    {reply, ok, S};
handle_call({delete, Name}, _From, S) ->
    delete_group(Name),
    {reply, ok, S};
handle_call(Request, From, S) ->
    error_logger:warning_msg("The pg2_fixed server received an unexpected message:\n"
                             "handle_call(~p, ~p, _)\n", 
                             [Request, From]),
    {noreply, S}.

-type all_members() :: [[name(),...]].
-type cast() :: {'exchange', node(), all_members()}
              | {'del_member', name(), pid()}.

-spec handle_cast(cast(), #state{}) -> {'noreply', #state{}}.

handle_cast({exchange, _Node, List}, S) ->
    store(List),
    {noreply, S};
handle_cast(_, S) ->
    %% Ignore {del_member, Name, Pid}.
    {noreply, S}.

-spec handle_info(tuple(), #state{}) -> {'noreply', #state{}}.

handle_info({'DOWN', MonitorRef, process, _Pid, _Info}, S) ->
    member_died(MonitorRef),
    {noreply, S};
handle_info({nodeup, Node}, S) ->
    gen_server:cast({?MODULE, Node}, {exchange, node(), all_members()}),
    {noreply, S};
handle_info({new_pg2_fixed, Node}, S) ->
    gen_server:cast({?MODULE, Node}, {exchange, node(), all_members()}),
    {noreply, S};
handle_info(_, S) ->
    {noreply, S}.

-spec terminate(term(), #state{}) -> 'ok'.

terminate(_Reason, _S) ->
    true = ets:delete(pg2_fixed_table),
    ok.

%%%
%%% Local functions
%%%

%%% One ETS table, pg2_fixed_table, is used for bookkeeping. The type of the
%%% table is ordered_set, and the fast matching of partially
%%% instantiated keys is used extensively.
%%%
%%% {{group, Name}}
%%%    Process group Name.
%%% {{ref, Pid}, RPid, MonitorRef, Counter}
%%% {{ref, MonitorRef}, Pid}
%%%    Each process has one monitor. Sometimes a process is spawned to
%%%    monitor the pid (RPid). Counter is incremented when the Pid joins
%%%    some group.
%%% {{member, Name, Pid}, GroupCounter}
%%% {{local_member, Name, Pid}}
%%%    Pid is a member of group Name, GroupCounter is incremented when the
%%%    Pid joins the group Name.
%%% {{pid, Pid, Name}}
%%%    Pid is a member of group Name.

store(List) ->
    _ = [case assure_group(Name) of
             true ->
                 [join_group(Name, P) || P <- Members -- group_members(Name)];
             _ ->
                 ok
         end || [Name, Members] <- List],
    ok.

assure_group(Name) ->
    Key = {group, Name},
    ets:member(pg2_fixed_table, Key) orelse true =:= ets:insert(pg2_fixed_table, {Key}).

delete_group(Name) ->
    _ = [leave_group(Name, Pid) || Pid <- group_members(Name)],
    true = ets:delete(pg2_fixed_table, {group, Name}),
    ok.

member_died(Ref) ->
    [{{ref, Ref}, Pid}] = ets:lookup(pg2_fixed_table, {ref, Ref}),
    Names = member_groups(Pid),
    _ = [leave_group(Name, P) || 
            Name <- Names,
            P <- member_in_group(Pid, Name)],
    %% Kept for backward compatibility with links. Can be removed, eventually.
    _ = [gen_server:abcast(nodes(), ?MODULE, {del_member, Name, Pid}) ||
            Name <- Names],
    ok.

join_group(Name, Pid) ->
    Ref_Pid = {ref, Pid}, 
    try _ = ets:update_counter(pg2_fixed_table, Ref_Pid, {4, +1})
    catch _:_ ->
            {RPid, Ref} = do_monitor(Pid),
            true = ets:insert(pg2_fixed_table, {Ref_Pid, RPid, Ref, 1}),
            true = ets:insert(pg2_fixed_table, {{ref, Ref}, Pid})
    end,
    Member_Name_Pid = {member, Name, Pid},
    try _ = ets:update_counter(pg2_fixed_table, Member_Name_Pid, {2, +1, 1, 1})
    catch _:_ ->
            true = ets:insert(pg2_fixed_table, {Member_Name_Pid, 1}),
            _ = [ets:insert(pg2_fixed_table, {{local_member, Name, Pid}}) ||
                    node(Pid) =:= node()],
            true = ets:insert(pg2_fixed_table, {{pid, Pid, Name}})
    end.

leave_group(Name, Pid) ->
    Member_Name_Pid = {member, Name, Pid},
    try ets:update_counter(pg2_fixed_table, Member_Name_Pid, {2, -1, 0, 0}) of
        N ->
            if 
                N =:= 0 ->
                    true = ets:delete(pg2_fixed_table, {pid, Pid, Name}),
                    _ = [ets:delete(pg2_fixed_table, {local_member, Name, Pid}) ||
                            node(Pid) =:= node()],
                    true = ets:delete(pg2_fixed_table, Member_Name_Pid);
                true ->
                    ok
            end,
            Ref_Pid = {ref, Pid}, 
            case ets:update_counter(pg2_fixed_table, Ref_Pid, {4, -1}) of
                0 ->
                    [{Ref_Pid,RPid,Ref,0}] = ets:lookup(pg2_fixed_table, Ref_Pid),
                    true = ets:delete(pg2_fixed_table, {ref, Ref}),
                    true = ets:delete(pg2_fixed_table, Ref_Pid),
                    true = erlang:demonitor(Ref, [flush]),
                    kill_monitor_proc(RPid, Pid);
                _ ->
                    ok
            end
    catch _:_ ->
            ok
    end.

all_members() ->
    [[G, group_members(G)] || G <- all_groups()].

group_members(Name) ->
    [P || 
        [P, N] <- ets:match(pg2_fixed_table, {{member, Name, '$1'},'$2'}),
        _ <- lists:seq(1, N)].

local_group_members(Name) ->
    [P || 
        [Pid] <- ets:match(pg2_fixed_table, {{local_member, Name, '$1'}}),
        P <- member_in_group(Pid, Name)].

member_in_group(Pid, Name) ->
    case ets:lookup(pg2_fixed_table, {member, Name, Pid}) of
        [] -> [];
        [{{member, Name, Pid}, N}] ->
            lists:duplicate(N, Pid)
    end.

member_groups(Pid) ->
    [Name || [Name] <- ets:match(pg2_fixed_table, {{pid, Pid, '$1'}})].

all_groups() ->
    [N || [N] <- ets:match(pg2_fixed_table, {{group,'$1'}})].

ensure_started() ->
    case whereis(?MODULE) of
        undefined ->
            C = {pg2_fixed, {?MODULE, start_link, []}, permanent,
                 1000, worker, [?MODULE]},
            supervisor:start_child(kernel_safe_sup, C);
        Pg2_FixedPid ->
            {ok, Pg2_FixedPid}
    end.


kill_monitor_proc(RPid, Pid) ->
    case RPid of
        Pid -> ok;
        _   -> exit(RPid, kill)
    end.

%% When/if erlang:monitor() returns before trying to connect to the
%% other node this function can be removed.
do_monitor(Pid) ->
    case (node(Pid) =:= node()) orelse lists:member(node(Pid), nodes()) of
        true ->
            %% Assume the node is still up
            {Pid, erlang:monitor(process, Pid)};
        false ->
            F = fun() -> 
                        Ref = erlang:monitor(process, Pid),
                        receive 
                            {'DOWN', Ref, process, Pid, _Info} ->
                                exit(normal)
                        end
                end,
            erlang:spawn_monitor(F)
    end.
rabbit_exchange_type.erl · 1625 B · ext .erl · seen 1438× in SWH
via unique-primary
swh:1:cnt:ab3d00dc28601597bb05f6b713d46329fca03323;origin=https://github.com/SoftwareEngineeringToolDemos/ICSE-2012-Spy-Runtime;anchor=swh:1:rev:503215a023b37da8ad5098a783e479e23cd14a05;path=/rabbitMQ-changed/src/rabbit_exchange_type.erl
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is VMware, Inc.
%% Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
%%

-module(rabbit_exchange_type).

-export([behaviour_info/1]).

behaviour_info(callbacks) ->
    [
     {description, 0},

     %% Should Rabbit ensure that all binding events that are
     %% delivered to an individual exchange can be serialised? (they
     %% might still be delivered out of order, but there'll be a
     %% serial number).
     {serialise_events, 0},

     {route, 2},

     %% called BEFORE declaration, to check args etc; may exit with #amqp_error{}
     {validate, 1},

     %% called after declaration and recovery
     {create, 2},

     %% called after exchange (auto)deletion.
     {delete, 3},

     %% called after a binding has been added or recovered
     {add_binding, 3},

     %% called after bindings have been deleted.
     {remove_bindings, 3},

     %% called when comparing exchanges for equivalence - should return ok or
     %% exit with #amqp_error{}
     {assert_args_equivalence, 2}

    ];
behaviour_info(_Other) ->
    undefined.
rabbit_msg_store.hrl · 799 B · ext .hrl · seen 75× in SWH
via fallback
swh:1:cnt:e9150a97b3e2592d8f9a9ab307144a66fc347259;origin=https://github.com/2600hz-archive/whistle;anchor=swh:1:rev:d20749b7009ae05896861a9a266cb7f0eaf3317a;path=/lib/rabbitmq_server-2.4.1/include/rabbit_msg_store.hrl
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
%% The contents of this file are subject to the Mozilla Public License
%% Version 1.1 (the "License"); you may not use this file except in
%% compliance with the License. You may obtain a copy of the License
%% at http://www.mozilla.org/MPL/
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and
%% limitations under the License.
%%
%% The Original Code is RabbitMQ.
%%
%% The Initial Developer of the Original Code is VMware, Inc.
%% Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
%%

-include("rabbit.hrl").

-ifdef(use_specs).

-type(msg() :: any()).

-endif.

-record(msg_location, {msg_id, ref_count, file, offset, total_size}).
footer.xrl · 163 B · ext .xrl · seen 1× in SWH
via fallback
swh:1:cnt:02a06d03ef2519bc4fe0ba06d26f5895ffbf3f8a;origin=https://github.com/elephantbirdconsulting/netkernel-contribution;anchor=swh:1:rev:a89956388c38cacee4d6a74461ffeb7dd979d1ae;path=/urn.com.elbeesee.demo.xrl/resources/xrl/footer.xrl
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
<div xmlns:xrl="http://netkernel.org/xrl" id="footer">
	<p>All rights reserved. © <span xrl:eval="text">active:widgetCurrentYear</span> 1060 Research</p>
</div>

Disambiguation rules

Linguist heuristic rules that predict this language when one of its claimed extensions is shared with another.
RuleExtKindPredicates (truncated)
h/linguist/.es/0.espredicates[{"kind": "any", "regexes": ["^\\s*(?:%%|main\\s*\\(.*?\\)\\s*->)"]}]
h/linguist/.app/0.apppredicates[{"kind": "any", "regexes": ["^\\{\\s*(?:application|'application')\\s*,\\s*(?:[a-z]+[\\w@]*|'[^']+')\\s*,\\s*\\[(?:.|[\\r\\n])*\\]\\s*\\}\\.[ \\t]*$"]}]

Contribute — propose a file extension

Tell us where to find evidence about Erlang (mapped to pl/erlang). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/Erlang/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← Erjang Erlang (programming language) →