简体   繁体   English

使用分配给变量的列表时,b-prolog成员函数的行为可疑

[英]b-prolog member function behaves suspiciously when using a list assigned to a variable

While interrogating b-prolog in the terminal, the member function does not seem to behave correctly when assigning a list to a variable and using the variable with the built in "member" function. 在终端中查询b-prolog时,在将列表分配给变量并将变量与内置的“成员”函数一起使用时,成员函数似乎无法正常工作。 I am having trouble interpreting the result when using a variable. 使用变量时,我难以解释结果。 Could anyone tell me if this is the correct behaviour and why it is the case? 谁能告诉我这是否正确,为什么?

B-Prolog Version 8.1, All rights reserved, (C) Afany Software 1994-2014.
| ?- List = [a,b,c,d].
List = [a,b,c,d]
yes
| ?- member(a,List).
List = [a|_14c] ?;
List = [_148,a|_154] ?;
List = [_148,_150,a|_15c] ?;
List = [_148,_150,_158,a|_164] ?;
List = [_148,_150,_158,_160,a|_16c] ?
yes

| ?- member(a,[a,b,c,d]).

yes
| ?-

I am using bprolog v 8.1 running on Windows 10 Pro (10.0.143393 Build 14393) 我正在使用在Windows 10 Pro(10.0.143393 Build 14393)上运行的bprolog v 8.1

Top-level queries are independent and don't share variables. 顶级查询是独立的,并且不共享变量。 If you try instead: 如果您尝试改为:

| ?- List = [a,b,c,d], member(a,List).

you will get the expected results. 您将获得预期的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM