Erlang: qlc:info 抛出错误,而 qlc:eval 没有 - 为什么?
有效
root@test # erl
Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]
Eshell V5.8.3 (abort with ^G)
1> Tmp = ets:new(test, [bag]), Ref = make_ref(),
1> qlc:eval(qlc:q([Ref1 || Ref1 <- ets:table(Tmp), Ref =:= Ref1])).
[]
2> qlc:info(qlc:q([Ref1 || Ref1 <- ets:table(Tmp), Ref =:= Ref1])).
"ets:table(16400,\n [{traverse,\n {select,\n [{'$1',\n [{'=:=',{const,#Ref<0.0.0.29>},'$1'}],\n ['$1']}]}}])"
3> halt().
无效
root@test # erl
Erlang R14B02 (erts-5.8.3) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]
Eshell V5.8.3 (abort with ^G)
1> Tmp = ets:new(test, [bag]), Ref = make_ref(),
1> qlc:eval(qlc:q([Ref1 || {Ref1} <- ets:table(Tmp), Ref =:= Ref1])).
[]
2> qlc:info(qlc:q([Ref1 || {Ref1} <- ets:table(Tmp), Ref =:= Ref1])).
** exception error: no match of right hand side value {error,{1,erl_parse,["syntax error before: ",["Ref"]]}}
in function qlc:abstract/3
in call from qlc:abstract/3
in call from qlc:abstract/4
in call from qlc:info/2
3> halt().
我不明白为什么。在一个更复杂的查询中发现了此错误,由于此错误,我无法解释和分析该错误。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管该帖子很旧,但我想了解这种行为。我的理解有什么不对的地方请指正。
考虑代码中的以下更改
输出中的更改是在第二种情况下使用 match_spec_run(qlc 句柄不同)。这意味着 qlc 信息需要从 qlc 句柄获取数据的方式发生了变化。
下面的代码给出了错误
当调试qlc的代码时发现,对于match_spec_run相关的查询处理qlc:info使用抽象格式函数erl_parse:parse_exprs/1 获取解析树。但这种情况下的问题是 Erlang 引用没有解析树!为了简单理解
NewRef = #Ref<0.0.0.134>.
和 pidNewPid = <0.34.0>.
给出语法错误,它们只能是值绑定到变量,编译器无法解释/解析它们。因此在这种情况下会导致错误。Even though the post is very old, I wanted to understand the behavior. Please correct me wherever there is something wrong in my understanding.
Consider the following change in the code
The change in the output is that match_spec_run is used in the second case(qlc handles are different). This means there is a change how the qlc info needs to get the data from the qlc handle.
The below code gives error
When debugging the code of qlc found that, for match_spec_run related query handle the qlc:info uses abstract format function erl_parse:parse_exprs/1 to get the parse tree. But the problem in this case is that the Erlang reference has no parse tree!! For simple understanding
NewRef = #Ref<0.0.0.134>.
and also pidNewPid = <0.34.0>.
gives syntax error, they can only be values bound to a variable and compiler cannot interpret/parse them. Thus in this case it results in the error.