Skip to content

Commit

Permalink
Merge pull request #303 from ichiban/prioritize-max-depth-over-cycle-…
Browse files Browse the repository at this point in the history
…detection

prioritize max_depth over cycle detection
  • Loading branch information
ichiban authored Aug 11, 2023
2 parents b77736e + 4c60406 commit 982dbc1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions engine/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4053,6 +4053,7 @@ func TestWriteTerm(t *testing.T) {
{title: `write_term(S, s(s(0)), [max_depth(2)]).`, sOrA: w, term: NewAtom("s").Apply(NewAtom("s").Apply(Integer(0))), options: List(atomMaxDepth.Apply(Integer(2))), ok: true, output: `s(s(...))`},
{title: `write_term(S, _, [max_depth(_)]).`, sOrA: w, term: NewVariable(), options: List(atomMaxDepth.Apply(NewVariable())), err: InstantiationError(nil)},
{title: `write_term(S, _, [max_depth(foo)]).`, sOrA: w, term: NewVariable(), options: List(atomMaxDepth.Apply(NewAtom("foo"))), err: domainError(validDomainWriteOption, atomMaxDepth.Apply(NewAtom("foo")), nil)},
{title: `L = [a, b|L], write_term(S, L, [max_depth(9)]).`, sOrA: w, term: l, options: List(atomMaxDepth.Apply(Integer(9))), env: NewEnv().bind(l, PartialList(l, NewAtom("a"), NewAtom("b"))), ok: true, output: `[a,b,a,b,a,b,a,b,a|...]`}, // https://github.com/ichiban/prolog/issues/297#issuecomment-1646750461
}

var vm VM
Expand Down
2 changes: 1 addition & 1 deletion engine/compound.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func writeCompoundList(w io.Writer, c Compound, opts *WriteOptions, env *Env) er
opts = opts.withPriority(999).withLeft(operator{}).withRight(operator{})
_, _ = fmt.Fprint(&ew, "[")
_ = c.Arg(0).WriteTerm(&ew, opts, env)
iter := ListIterator{List: c.Arg(1), Env: env}
iter := ListIterator{List: c.Arg(1), Env: env, AllowCycle: opts.maxDepth > 0}
for iter.Next() {
opts.maxDepth--
if opts.maxDepth == 0 {
Expand Down

0 comments on commit 982dbc1

Please sign in to comment.