gpt4 book ai didi

erlang - 什么是合法的二郎卫?

转载 作者:行者123 更新时间:2023-12-05 00:53:55 24 4
gpt4 key购买 nike

下面问题的解答是否正确?

从下面的列表中选择合法的保护表达式,变量 A 已经绑定(bind)。

true, false, apple, 1+2, 1+2 > 3, is_atom(A), B = 3, A = 3, A == 3,length(A), lists:max(A), list_to_atom(A), A and B, (A > 3) and (A < 12)

我的解决方案是(正确的 guard ):
true,  false,  1+2 > 3,  is_atom(A), A == 3,  length(A), lists:max(A), list_to_atom(A),  A and B,  (A > 3) and (A < 12)

最佳答案

lists:max/1 不是有效的守卫。只是盯着你的解决方案,除了 list:max/1 之外它似乎是正确的

来自文档 (http://erlang.org/doc/reference_manual/expressions.html)

The set of valid guard expressions (sometimes called guard tests) is a subset of the set of valid Erlang expressions. The reason for restricting the set of valid expressions is that evaluation of a guard expression must be guaranteed to be free of side effects. Valid guard expressions are the following:


The atom true, 
Other constants (terms and bound variables), all regarded as false
Calls to the BIFs specified in table Type Test BIFs
Term comparisons
Arithmetic expressions
Boolean expressions
Short-circuit expressions (andalso/orelse)
is_atom/1
is_binary/1
is_bitstring/1
is_boolean/1
is_float/1
is_function/1
is_function/2
is_integer/1
is_list/1
is_map/1
is_number/1
is_pid/1
is_port/1
is_record/2
is_record/3
is_reference/1
is_tuple/1
abs(Number)
bit_size(Bitstring)
byte_size(Bitstring)
element(N, Tuple)
float(Term)
hd(List)
length(List)
map_size(Map)
node()
node(Pid|Ref|Port)
round(Number)
self()
size(Tuple|Bitstring)
tl(List)
trunc(Number)
tuple_size(Tuple)

关于erlang - 什么是合法的二郎卫?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40497541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com