Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
guregu committed Nov 2, 2024
1 parent ed5d4a5 commit 7c955ad
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,34 @@ These structs can also be used to bind variables in queries.
```

```go
// You can embed trealla.Functor to represent Prolog compounds using Go structs.

// kv(Flag, Value)
type KV struct {
trealla.Functor `prolog:"kv/2"` // tag is optional, but can be used to specify the functor/arity
Flag trealla.Atom // 1st arg
Value trealla.Term // 2nd arg
type pair struct {
trealla.Functor `prolog:"-/2"` // tag is optional, but can be used to specify the functor/arity
Flag trealla.Atom // 1st arg
Value trealla.Term // 2nd arg
}

var result struct {
Flags []KV // Flags variable
Flags []pair // Flags variable
}

ctx := context.Background()
pl, err := trealla.New()
if err != nil {
panic(err)
}
answer, err := pl.QueryOnce(ctx, `
findall(Flag-Value, (member(Flag, [double_quotes, encoding, max_arity]), current_prolog_flag(Flag, Value)), Flags).
`)
if err != nil {
panic(err)
}
if err := answer.Solution.Scan(&result); err != nil {
panic(err)
}
answer.Solution.Scan(&result)
fmt.Printf("%v\n", result.Flags)
// Output: [{- double_quotes chars} {- encoding 'UTF-8'} {- max_arity 255}]
```

## Documentation
Expand Down

0 comments on commit 7c955ad

Please sign in to comment.