use pattern definitions to clean up some code

This commit is contained in:
darkf 2013-10-25 14:42:41 -07:00
parent a96869b5b3
commit 3b2441db92
1 changed files with 5 additions and 8 deletions

View File

@ -16,9 +16,6 @@ splitirc(str) -> splitirc'(str, "", []).
head(x::_) -> x. head(x::_) -> x.
tail(_::xs) -> xs. tail(_::xs) -> xs.
fst((x, _)) -> x.
snd((_, y)) -> y.
-- (result, rest) -- (result, rest)
takeUntilSpace'(" "::xs, acc) -> (acc, xs). takeUntilSpace'(" "::xs, acc) -> (acc, xs).
takeUntilSpace'(x::xs, acc) -> takeUntilSpace'(xs, acc + x). takeUntilSpace'(x::xs, acc) -> takeUntilSpace'(xs, acc + x).
@ -81,12 +78,12 @@ handleCommand(src, cmd, args) ->
handleLine(line) -> do handleLine(line) -> do
if head(line) == ":" then do if head(line) == ":" then do
-- source -- source
sp = takeUntilSpace(tail(line)); (source, rest) = takeUntilSpace(tail(line));
message = splitirc(snd(sp)); command::args = splitirc(rest);
handleCommand(fst(sp), head(message), tail(message)) handleCommand(source, command, args)
end else do end else do
message = splitirc(line); command::args = splitirc(line);
handleCommand("", head(message), tail(message)) handleCommand(source, command, args)
end end
end. end.