-module(rpn).
-export([rpn/1]).
rpn(Code) when is_list(Code) ->
rpn(string:tokens(Code, " "), []).
rpn([], Stack) ->
io:format("Result: ~B~n", [hd(Stack)]);
rpn([Token|Tail], Stack) ->
rpn(Tail, token_execute(Token, Stack)).
token_execute("+", [Arg1,Arg2|Tail]) ->
[Arg1 + Arg2|Tail];
token_execute("-", [Arg1,Arg2|Tail]) ->
[Arg2 - Arg1|Tail];
token_execute("*", [Arg1,Arg2|Tail]) ->
[Arg1 * Arg2|Tail];
token_execute("/", [Arg1,Arg2|Tail]) ->
[Arg2 div Arg1|Tail];
token_execute("_", [Arg1|Tail]) ->