Skip to content

Commit

Permalink
fix Compound.String argument rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Oct 12, 2022
1 parent 4cd1c0d commit dc366ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions trealla/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func Example() {

// start a new query
query := pl.Query(ctx, "member(X, [1, foo(bar), c]).")
// calling Close is not necessary if you iterate through the whole query, but it doesn't hurt
defer query.Close()

// iterate through answers
for query.Next(ctx) {
Expand Down
7 changes: 6 additions & 1 deletion trealla/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ func (c Compound) String() string {
if i > 0 {
buf.WriteString(", ")
}
buf.WriteString(fmt.Sprintf("%v", arg))
text, err := marshal(arg)
if err != nil {
buf.WriteString(fmt.Sprintf("<invalid: %v>", err))
continue
}
buf.WriteString(text)
}
buf.WriteRune(')')
return buf.String()
Expand Down
2 changes: 1 addition & 1 deletion trealla/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "testing"
func TestCompound(t *testing.T) {
c0 := Compound{
Functor: "foo",
Args: []Term{"bar", 4.2},
Args: []Term{Atom("bar"), 4.2},
}
want := "foo(bar, 4.2)"
if c0.String() != want {
Expand Down

0 comments on commit dc366ae

Please sign in to comment.