我有一个新手的问题.我正在阅读"Erlang编程"一书,并在每一章之后进行练习.
在我有一个db.erl
模块的情况下,在其中我已经为几个练习放置了几个函数.经过几天的练习后,我已经厌倦了在erl
shell中重复"compile-> execute exercise-function"动作.假设我正在研究模块中的new()
功能db.erl
; 每次修改这个函数后,我都被迫做下一个erl
:
c(db.erl).
db:new().
Run Code Online (Sandbox Code Playgroud)
一次又一次.有时我忘记重新加载我的模块,结果令人困惑.我可以使用:编译/加载OS shell
erl -compile file.erl; erl -make
,但是我找不到从特定模块运行特定功能的方法.有什么建议?
我正在Erlang中构建一个简单的tic tac toe程序.我将董事会作为一个字符串传递给他,io:format("123\n456\n789\n")
并希望看到:
123
456
789
Run Code Online (Sandbox Code Playgroud)
但是在Erlang shell中io:format("123\n456\n789\n")
打印出来:
123
456
789
ok
Run Code Online (Sandbox Code Playgroud)
有没有办法输出到控制台没有尾随确定?
我需要将两个参数传递给我的Erlang代码.它在Erlang shell中运行良好.
2> crop:fall_velocity(x,23).
21.23205124334434
Run Code Online (Sandbox Code Playgroud)
但是如何在没有Erlang shell的情况下运行Erlang代码.像普通的python,c程序../program_name(不传递$ 1 $ 2参数).
我正在尝试这个
erl -noshell -s crop fall_velocity(x,20) -s init stop
Run Code Online (Sandbox Code Playgroud)
但它给出了意外的令牌错误.
我已经阅读了关于负载测试eJabberd和MongooseIM的链接.作者提到调整Erlang VM Link.
调整:
+K true
+A 5
+P 10000000
-env ERL_MAX_PORTS 1000000
-env ERL_FULLSWEEP_AFTER 2
-env ERL_MAX_ETS_TABLES 100000
Run Code Online (Sandbox Code Playgroud)
我尝试使用它们,就像erl +K true
在此链接中指定的那样.
问题:如何调整Erlang VM?如何检查设置是否已设置?更改设置后是否需要重启eJabberd?
我正在尝试按照Joe Armstrong编写的Erlang编程和软件中的第一个示例.这是代码:
-module(afile_server).
-export([start/1,loop/1]).
start(Dir) -> spawn(afile_server,loop,[Dir]).
loop(Dir) ->
receive
{Client, list_dir} ->
Client ! {self(), file:list_dir(Dir)};
{Client, {get_file, File}} ->
Full = filename:join(Dir,File),
Client ! {self(), file:read_file(Full)}
end,
loop(Dir).
Run Code Online (Sandbox Code Playgroud)
然后我在shell中运行它:
c(afile_server).
FileServer = spawn(afile_server, start, ".").
FileServer ! {self(), list_dir}.
receive X -> X end.
Run Code Online (Sandbox Code Playgroud)
在书中,按预期返回文件列表,但是在我的shell中,它看起来好像程序已经冻结.没有任何东西返回但程序仍在运行.我对erlang一点也不熟悉但是我能理解这应该如何工作.
我在Windows 7 64位中运行它.该目录不为空,因为它包含许多其他erlang文件.
我刚拿起Erlang时遇到一个简单的问题,但无法修复它或找到任何有关它的东西。我正在尝试定义一个模块来检查an atom
是否在给定列表中。我是这样通过Erlang shell输入列表的:
veggies:veggieMember([cucumber,tomato,potato],tomato).
但是我总是 exception error: no function clause matching
也许我误解了基础知识,但是这是我想要做的模块代码:
-module(veggies).
-export([veggieMember/2]).
veggieMember(veggieList,query)->
case lists:member(query, veggieList) of
true->veggieList;
false->[query|veggieList]
end.
Run Code Online (Sandbox Code Playgroud) 我这样开头:
[root@Oracle-linux-60 rabbitmq_server-3.5.6]# erl -pa ebin
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V7.1 (abort with ^G)
1> -include("include/amqp_client.hrl").
** exception error: undefined shell command include/1
Run Code Online (Sandbox Code Playgroud)
为什么它不承认include
?
我有一个.yaws文件,它调用我写setup/0
的authenticate
模块中的函数,我把它放在ebin
目录中.当我authenticate:setup/0
从Erlang shell 调用时,它创建一个表就好了,但是当我在浏览器中加载something.yaws时,调用该authenticate:setup/0
函数,它返回{aborted,{bad_type,users,disc_copies,nonode@nohost}}
(something.yaws只返回authenticate:setup/0
嵌入在html中的返回值以进行调试) .
这是setup/0
功能:
setup() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(users, [{type, set}, {record_name, user}, {disc_copies, [node()]}, {attributes, record_info(fields, user)}]).
Run Code Online (Sandbox Code Playgroud)
这是user
记录:
-record(user, {username, hashed_pw, salt}).
Run Code Online (Sandbox Code Playgroud)
(我已经尝试在浏览器中尝试之后从Erlang shell调用它,因此无法干扰它.)
如果我跑yaws --mnesiadir /usr/local/lib/yaws-appmods/mnesia/
,我得到
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [kernel-poll:true]
Eshell V8.1 (abort with ^G)
1>
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using config file /etc/yaws/yaws.conf
=INFO REPORT==== 7-Nov-2016::00:04:49 ===
Yaws: Using global subconfig …
Run Code Online (Sandbox Code Playgroud) -module(test).
-export([sum/1]).
sum([]) -> 0;
sum([X|Xs]) -> X + sum(Xs)
Run Code Online (Sandbox Code Playgroud)
This is what I have done so far though it only sums the numbers within a list like test:sum([1,2,3,4])
but I want it so that its like test:sum(4)
will output 1+2...+n
How can I do this?