From 7c955ad68965f7cf1d4654a774bc06d8de249adc Mon Sep 17 00:00:00 2001 From: guregu Date: Sat, 2 Nov 2024 21:59:26 +0900 Subject: [PATCH] update readme --- README.md | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9090cda..293c210 100644 --- a/README.md +++ b/README.md @@ -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