मैं Études for Elixir पुस्तक से Étude 3-1: Pattern Matching
को हल करने का प्रयास कर रहा हूं, निम्न कोड का उपयोग कर रहा हूं।संकलन त्रुटि: "एकाधिक खंडों और डिफ़ॉल्ट मानों के साथ परिभाषाओं को फ़ंक्शन हेड की आवश्यकता होती है"
16 def area(:rectangle, a \\ 1, b \\ 1) do
17 a * b
18 end
19
20 def area(:triangle, a, b) do
21 a * b/2.0
22 end
23
24 def area(:shape, a, b) do
25 a * b * :math.pi()
26 end
और मैं निम्न त्रुटि हो रही है:
** (CompileError) geom.ex:20: definitions with multiple clauses and default values require a function head.
वहाँ सही त्रुटि संदेश के बाद व्याख्या दी गई है:
Instead of:
def foo(:first_clause, b \\ :default) do ... end
def foo(:second_clause, b) do ... end
one should write:
def foo(a, b \\ :default)
def foo(:first_clause, b) do ... end
def foo(:second_clause, b) do ... end
def area/3 has multiple clauses and defines defaults in a clause with a body
geom.ex:20: (module)
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
जाहिर है मैं डिफ़ॉल्ट मान का उपयोग नहीं कर सकते हैं: समझ गया। पर क्यों?