rs第一节中的定义有什么问题?
palindrome :: [a] -> [a]
palindrome xs = con xs rs
where con a b = rev (rev a []) b
rs = rev xs -- here
where rev [] rs = rs
rev (x:xs) rs = rev xs (x:rs)
Run Code Online (Sandbox Code Playgroud)
我只是在学习Haskell,但它的语法规则让我很困惑.错误消息是
[1 of 1] Compiling Main ( pelindrome.hs, interpreted )
pelindrome.hs:5:8: parse error on input `rs'
Run Code Online (Sandbox Code Playgroud) 我在Erlang NIF中的线程有点问题.您可以在此处查看我的代码:http://pastebin.com/HMCj24Jp.问题是,当我启动线程时,它需要一些参数并启动generate_binary函数.这没关系,但是当我试图读取参数时,一切都崩溃了.
这可能不是最复杂的问题,但我找不到任何关于此的文档,所以我希望你们中的一些人可能知道答案.
RabbitMQ崩溃了.RabbitMQ正常工作了很多天(10-15天).我不明白为什么它会崩溃.
我在Erlang 17.0上使用RabbitMQ 3.4.0
erlang为崩溃创建了转储文件.这表现了
eheap_alloc: Cannot allocate 229520 bytes of memory (of type "old_heap").
Run Code Online (Sandbox Code Playgroud)
另请注意,rabbitmq发布 - 订阅消息负载非常低.(最大:1-2条消息/秒).当RabbitMQ消息到来时,它会被处理,因此RabbitMQ几乎一直是空的.磁盘空间和内存也足够了.
More system info:
Limiting to approx 8092 file handles (7280 sockets)
Memory limit set to 6553MB of 16383MB total.
Disk free limit set to 50MB.
Run Code Online (Sandbox Code Playgroud)
RabbitMQ日志如下.
=ERROR REPORT==== 18-Jul-2015::04:29:31 ===
** Generic server rabbit_disk_monitor terminating
** Last message in was update
** When Server state == {state,"c:/Users/jasmin.joshi/AppData/Roaming/RabbitMQ/db/rabbit@localhost-mnesia",
50000000,28358258688,100,10000,
#Ref<0.0.106.70488>,false}
** Reason for termination ==
** {eacces,[{erlang,open_port,
[{spawn,"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"c:/Users/jasmin.joshi/AppData/Roaming/RabbitMQ/db/rabbit@localhost-mnesia\""}, …Run Code Online (Sandbox Code Playgroud) 我C nif code在函数中写了一个and new,它创建了一个堆栈结构enif_alloc_resource并返回它。当我使用 function 时enif_make_resources,它总是<<>>以 erlang返回。
这是我的 C 代码:
#include "erl_nif.h"
static ErlNifResourceType *MEM_RESOURCE;
typedef struct
{
int n;
int ps;
int pe;
ERL_NIF_TERM *data;
} Stack;
Stack *new(ErlNifEnv *env, int size)
{
Stack *s = (Stack*) enif_alloc_resource(MEM_RESOURCE, sizeof(Stack));
s->n = size;
s->ps = 0;
s->pe = size - 1;
s->data = enif_alloc(sizeof(ERL_NIF_TERM) * size);
return s;
}
static ERL_NIF_TERM new_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int size; …Run Code Online (Sandbox Code Playgroud) 我有一个nif库,每次重新编译它时,都必须重新启动外壳程序才能重新加载或升级该库。
这是我的erlang代码:
-module(q4).
-export([init/0]).
-on_load(init/0).
init() ->
erlang:load_nif("./q4_nif", reload).
Run Code Online (Sandbox Code Playgroud)
每次我编译erlang模块时,都会发生此错误:
`The on_load function for module q4 returned {error,
{upgrade,
"Upgrade not supported by this NIF library."}}`
Run Code Online (Sandbox Code Playgroud)
当我调用init/0函数时,会发生此错误:
{error,{reload,"Reload not supported by this NIF library."}}
无论如何,有没有解决此问题并加载新的nif库,而无需重新启动Shell?
是否可以从NIF调用Erlang函数(回调函数)?
我阅读了doc(http://www.erlang.org/doc/man/erl_nif.html),但没有找到如何做到这一点.
我有一个小问题,我找不到简单的答案.
我设置:
Who = apple.
Message = [{apple, {0,0,0}}, {orange, {1,1,1}}].
Old = [X || {Who, X} <- Message].
Old returns as [{0,0,0},{1,1,1}]
Run Code Online (Sandbox Code Playgroud)
当然我的预期回复是{0,0,0}
相反,我得到了苹果和橘子.
我能做什么??
我打算使用NIF操作二进制文件用于我计划在Erlang中编码的应用程序.下面给出了指向cpp文件的gist链接和NIF的erl文件.
[Erl Gist Link] https://gist.github.com/abhijitiitr/3a5bc97184d6dd32f97b
[C++ Gist Link] https://gist.github.com/abhijitiitr/24d2b780f2cdacebfb07
基本上我正在尝试做一个简单的测试.在NIF调用之间共享二进制文件,并使用连续的NIF调用成功操作它们.
如果你在erlang REPL中测试代码
c(binary_test).
Ref=binary_test:open(<<1>>).
binary_test:increment(Ref,<<3>>).
Run Code Online (Sandbox Code Playgroud)
存储的二进制文件在NIF调用之间发生变化.第三个命令的REPL输出是
1
3
60
60
<<"?">>
Run Code Online (Sandbox Code Playgroud)
我<<1>>在初始化阶段通过了.它为什么改为<<60>>?我无法弄清楚这里发生了什么.有人可以指出错误吗?
C++编译指令
clang++ -std=c++11 -stdlib=libc++ -undefined dynamic_lookup -O3 -dynamiclib binary_test.cpp -o binary_test.so -I /usr/local/Cellar/erlang/17.0/lib/erlang/erts-6.0/include/
Run Code Online (Sandbox Code Playgroud)
在我的Mac上.
此外,我想问一下在NIF中操作共享资源的并发进程.这是可能的还是有一个规则,即必须在单个Erlang进程中访问NIF.
当Erlang VM梁运行一些用C编写的代码时,没有安排用Erlang编写的其他进程.例如:
static ERL_NIF_TERM
nifsleep(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
sleep(10);
return enif_make_atom(env, "ok");
}
Run Code Online (Sandbox Code Playgroud)
当你在Erlang中调用这个C函数时,其他进程没有正常进行schedulling.我想知道为什么?这是一个功能还是受实现限制(也就是说,这是一个错误)?
上面代码的地址是:https://github.com/davisp/sleepy
在实施NIF时,Dialyzer给了我
函数crc16/1没有本地回报
可能是因为我在.erl模块中退出(就像官方文档推荐的那样):
-module(my_nifs).
-export([crc16/1]).
-on_load(init/0).
init() ->
ok = erlang:load_nif("../nifs/my_nifs", 0).
-spec crc16(_Binary :: binary()) -> non_neg_integer().
crc16(_Binary) ->
exit(nif_library_not_loaded).
...
Run Code Online (Sandbox Code Playgroud)
一般来说,似乎使用exit/1始终让Dialyzer抱怨这条消息(-spec .. -> no_return()没有帮助).
怎么解决这个问题?