ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - ichiban/prolog: The only reasonable scripting engine for Go.
The only reasonable scripting engine for Go. Contribute to ichiban/prolog development by creating an account on GitHub.
Visit Site

GitHub - ichiban/prolog: The only reasonable scripting engine for Go.

GitHub - ichiban/prolog: The only reasonable scripting engine for Go.

prolog - the only reasonable scripting engine for Go

Go Reference Actions Status Go Report Card codecov Mentioned in Awesome Go

What is this?

ichiban/prolog is an embeddable ISO Prolog interpreter in Go.

Comparison with Other Libraries

prolog otto go-lua
Language ISO Prolog ECMA Script Lua
Paradigm ๐ŸŽ“ Logic Object-oriented Object-oriented
Go API ๐Ÿ˜ป database/sql-like original original
Declarative โœ… โŒ โŒ
Sandboxing โœ… โŒ โœ…

Getting started

Install latest version

go get -u github.com/ichiban/prolog

Usage

Instantiate an interpreter

p := prolog.New(os.Stdin, os.Stdout) // Or `prolog.New(nil, nil)` if you don't need user_input/user_output.

Or, if you want a sandbox interpreter without any built-in predicates:

// See examples/sandboxing/main.go for details.
p := new(prolog.Interpreter)

Load a Prolog program

if err := p.Exec(`
	human(socrates).       % This is a fact.
	mortal(X) :- human(X). % This is a rule.
`); err != nil {
	panic(err)
}

Similar to database/sql, you can use placeholder ? to insert Go data as Prolog data.

if err := p.Exec(`human(?).`, "socrates"); err != nil { // Same as p.Exec(`human("socrates").`)
	panic(err)
}

Run the Prolog program

sols, err := p.Query(`mortal(?).`, "socrates") // Same as p.Query(`mortal("socrates").`)
if err != nil {
	panic(err)
}
defer sols.Close()

// Iterates over solutions.
for sols.Next() {
	fmt.Printf("Yes.\n") // ==> Yes.
}

// Check if an error occurred while querying.
if err := sols.Err(); err != nil {
	panic(err)
}

Or, if you want to query for the variable values for each solution:

sols, err := p.Query(`mortal(Who).`)
if err != nil {
	panic(err)
}
defer sols.Close()

// Iterates over solutions.
for sols.Next() {
	// Prepare a struct with fields which name corresponds with a variable in the query.
	var s struct {
		Who string
	}
	if err := sols.Scan(&s); err != nil {
		panic(err)
	}
	fmt.Printf("Who = %s\n", s.Who) // ==> Who = socrates
}

// Check if an error occurred while querying.
if err := sols.Err(); err != nil {
	panic(err)
}

The Default Language

ichiban/prolog adheres the ISO standard and comes with the ISO predicates as well as the Prologue for Prolog and DCG predicates.

See the Wiki for the directives and the built-in predicates.

Top Level

1pl is an experimental top level command for testing the default language and its compliance to the ISO standard.

You can install it with go install:

go install github.com/ichiban/prolog/cmd/1pl@latest

Then, you can enter the top level with 1pl:

$(go env GOPATH)/bin/1pl [<file>...]

Extensions

  • predicates: Native predicates for ichiban/prolog.
  • kagomelog: a Japanese morphological analyzing predicate.

License

Distributed under the MIT license. See LICENSE for more information.

Contributing

See ARCHITECTURE.md for architecture details.

  1. Fork it (https://github.com/ichiban/prolog/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Acknowledgments

We would like to extend our thanks to the following individuals for their contributions to this project:

We are grateful for the support and contributions of everyone involved in this project. Arigatou gozaimasu!

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory