/ / मॉड्यूल Erlang में कार्य करते हैं - फ़ंक्शन, मॉड्यूल, इरलैंग

एरलांग में मॉड्यूल फ़ंक्शन - फ़ंक्शन, मॉड्यूल, इरलैंग

तो, यह यहाँ एक मॉड्यूल मैं "मी लेखन का हिस्सा है:

request(Pid, ListOfDocuments) when is_pid(Pid), is_list(ListOfDocuments) ->
io:format("We get here~n"),
case whereis(jdw_api) of
undefined -> [no, api];
ApiPid when is_pid(ApiPid) ->
io:format("... and here~n"),
% (1) Won"t work: spawn(?MODULE, loop, [Pid, ListOfDocuments])
% (2) Won"t work, either: ?MODULE:loop(Pid, ListOfDocuments)
loop(Pid, ListOfDocuments) % (3) and neither does this...
end.

... और ऐसा है:

loop(Pid, Docs) when is_list(Docs), length(Docs) > 0 ->
H = hd(Docs),
T = tl(Docs),
io:format("... but not here...~w~n", H),
case ?MODE of
sync ->
Ref = make_ref(),
jdw_api ! {self(), Ref, doc, H},
Ans = loop_sync(Ref, [], []),
Pid ! Ans,
loop(Pid, T);
async -> {error, "async mode not implemented yet", ?FILE, ?LINE};
_ -> {"?MODE must be either async or sync"}
end;
loop(Pid, Docs) -> io:format("Done with document list").

... लेकिन किसी कारण से, "लूप" फ़ंक्शन को कभी नहीं बुलाया जाता है। न तो तीन अलग-अलग तरीकों से जादू होता है ... कोई संकेत?

उत्तर:

जवाब के लिए 2 № 1

आपके लूप फ़ंक्शन को कॉल किया जा सकता है, लेकिन कोडआप ऊपर दिखाते हैं कि उस फ़ंक्शन का केवल एक क्लॉज है, और यह केवल तभी चलेगा जब उसे पिड और दस्तावेजों की गैर-रिक्त सूची के साथ बुलाया जाए। दूसरी समस्या यह है कि आपका छोटी गाड़ी कॉल है io:format("... but not here...~w~n", H) जो होना चाहिए io:format("... but not here...~w~n", [H])। वह कॉल लूप कोड को क्रैश कर सकता है। अधिक स्रोत के बिना काम करने के लिए और तर्कों का उदाहरण दें request/2 यह बताना मुश्किल है।