我根据OTP gen_server行为创建了一个新文件。
这是它的开始:
-module(appender_server).
-behaviour(gen_server).
-export([start_link/1, stop/0]).
-export([init/1, handle_call/3, handle_cast/2]).
start_link(filePath) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, filePath, []).
init(filePath) ->
{ok, theFile} = file:open(filePath, [append]). % File is created if it does not exist.
...
文件使用c(appender_server)编译成功。
当我尝试从shell调用start_link函数时,如下所示:
appender_server:start_link("c:/temp/file.txt").
我得到:
**异常错误:没有与appender_server:start_link(“c:/temp/file.txt”)匹配的函数子句(appender_server.erl,第10行)
我做错了什么?
1条答案
按热度按时间vbkedwbf1#
filePath
is an atom--not a variable:In erlang, variables start with a capital letter. The only way erlang could match your function clause would be to call the function like this:
Here is an example:
In the shell: