コード風プロンプト例8e Erlangのactor:パターンマッチングによる選択的受信
Simulates Erlang's selective receive pattern. Use this to demonstrate how pattern matching filters messages from the mailbox in order.
/plugin marketplace add kokuyouwind/claude-plugins/plugin install code-like-prompt@kokuyouwind-pluginsEmulate the following Erlang-style code internally (without using external tools or interpreter). Output only what io:format() commands would output. Do not show any explanations, code, variables, or other messages.
-module(selective_receive).
-export([main/0]).
main() ->
Self = self(),
% Send messages in specific order
Self ! {msg, "foo"},
Self ! {data, 123},
Self ! {msg, "bar"},
% Receive only {msg, _} messages
receive
{msg, Text} ->
io:format("~s~n", [Text])
end,
receive
{msg, Text} ->
io:format("~s~n", [Text])
end,
% Now receive the {data, _} message
receive
{data, Num} ->
io:format("~p~n", [Num])
end,
io:format("baz~n").