gpt4 book ai didi

ocaml - ocaml 中的异常 "Stack_overflow"

转载 作者:行者123 更新时间:2023-12-01 09:29:56 27 4
gpt4 key购买 nike

我想问下exception :"exception Stack_overflow"是否会导致死循环,特别是异常出现在下面的代码中:

    ( *the loop "while" should stop when both stacks are empty*)
while (not (Stack.is_empty stackFalse) )|| ( not (Stack.is_empty stackTrue)) do
(
if (not ( Stack.is_empty stackTrue )) then
(
let q1 = Stack.pop stackTrue in
let (_,_,ptrs) = fst (Hashtbl.find graph ( fst q1) ) in
List.iter ( fun elem ->

let app = Hashtbl.find graph elem in
let (typeNode,last,ptrs') = fst app in

if typeNode = "Or-node" then
(
Stack.push (elem,true) stackTrue;
Hashtbl.add labeled elem true
)
else if last = false then
Hashtbl.replace graph elem ((typeNode,true,ptrs'),snd app)
else
(
Stack.push (elem,true) stackTrue;
Hashtbl.add labeled elem true
) ) ptrs ;
);

if (not ( Stack.is_empty stackFalse )) then
(
let q2 = Stack.pop stackFalse in
let (_,_,ptrs1) = fst (Hashtbl.find graph (fst q2) )in

List.iter ( fun elem ->

let app = Hashtbl.find graph elem in
let (typeNode,last,ptrs') = fst app in

if typeNode = "And-node" then
(
Stack.push (elem,false) stackFalse;
Hashtbl.add labeled elem false
)
else if last = false then
Hashtbl.replace graph elem ((typeNode,true,ptrs'),snd app)
else
(
Stack.push (elem,false) stackFalse;
Hashtbl.add labeled elem false
) ) ptrs1 ;
);

)
done;

最佳答案

标准急救:使用 -g 重新编译并使用 OCAMLRUNPARAM=b(参见手册)运行以查看回溯。

PS 我怀疑结构比较(例如 Hashtbl.find 使用的),hashtbl 元素中是否有任何循环引用?

关于ocaml - ocaml 中的异常 "Stack_overflow",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4605091/

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