嗨,我正在学习Elixir Atm(才刚刚开始),而我以前从未做过函数编程,所以我的问题是函数名称后面的括号是做什么的。 我正在看一些互联网课程,并且想尝试制作一些用于培训的应用程序,但并不太了解。
defmodule Cards do
def create_deck do
values = ["Ace","Two","Three", "Four", "Five"]
suits = ["Spades", "Clubs", "Hearts", "Diamonds"]
for suit <- suits, value <- values do
"#{value} of #{suit}"
end
end
def shuffle(deck) do
Enum.shuffle(deck)
end
def contains**(deck, card) do
Enum.member?(deck, card)
end
def deal(deck, hand_size) do
Enum.split(deck, hand_size)
end
def save(deck, filename) do
binary = :erlang.term_to_binary(deck)
File.write(filename, binary)
end
def load(filename) do
{status, binary} = File.read(filename)
:erlang.binary_to_term(binary)
end
end