From 5508e32f08873a59e25fb25158060580108b6726 Mon Sep 17 00:00:00 2001 From: Yutaka Ichibangase Date: Sun, 2 Apr 2023 12:14:25 +0900 Subject: [PATCH] update examples to respect double_quotes flag --- examples/call_go_from_prolog/main.go | 7 ++++++- examples/dcg/main.go | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/call_go_from_prolog/main.go b/examples/call_go_from_prolog/main.go index 8dc4a99..44309cd 100644 --- a/examples/call_go_from_prolog/main.go +++ b/examples/call_go_from_prolog/main.go @@ -16,7 +16,7 @@ func main() { // Check if the input arguments are of the types you expected. u, ok := env.Resolve(url).(engine.Atom) if !ok { - return engine.Error(fmt.Errorf("%s is not an atom", url)) + return engine.Error(engine.TypeError(engine.NewAtom("atom"), url, env)) } // Do whatever you want with the given inputs. @@ -35,6 +35,11 @@ func main() { return k(env) }) + // Treat a string argument as an atom. + if err := p.Exec(`:- set_prolog_flag(double_quotes, atom).`); err != nil { + panic(err) + } + // Query with the custom predicate get_status/2 but parameterize the first argument. sols, err := p.Query(`get_status(?, Status).`, "https://httpbin.org/status/200") if err != nil { diff --git a/examples/dcg/main.go b/examples/dcg/main.go index 30560d1..d9840fa 100644 --- a/examples/dcg/main.go +++ b/examples/dcg/main.go @@ -26,6 +26,8 @@ func main() { // Then, define DCG rules with -->/2. if err := i.Exec(` +:- set_prolog_flag(double_quotes, atom). + sentence --> noun_phrase, verb_phrase. verb_phrase --> verb. noun_phrase --> article, noun.