Skip to content

Commit

Permalink
Merge pull request #291 from ichiban/examples-double_quotes
Browse files Browse the repository at this point in the history
update examples to respect double_quotes flag
  • Loading branch information
ichiban authored Apr 2, 2023
2 parents 1864911 + 5508e32 commit 5ad402c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/call_go_from_prolog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/dcg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5ad402c

Please sign in to comment.