{"id":20459756,"url":"https://github.com/rosbit/go-trealla","last_synced_at":"2026-05-29T18:31:32.182Z","repository":{"id":55062526,"uuid":"521467703","full_name":"rosbit/go-trealla","owner":"rosbit","description":"An embeddable Prolog by interacting with trealla-prolog. 通过与trealla-prolog交互实现的嵌入式prolog","archived":false,"fork":false,"pushed_at":"2022-08-19T02:00:05.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T11:16:57.613Z","etag":null,"topics":["embedded","golang","prolog","trealla","trealla-prolog"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rosbit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-05T01:41:33.000Z","updated_at":"2022-08-09T14:01:41.000Z","dependencies_parsed_at":"2022-08-14T10:40:38.961Z","dependency_job_id":null,"html_url":"https://github.com/rosbit/go-trealla","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/rosbit/go-trealla","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-trealla","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-trealla/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-trealla/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-trealla/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosbit","download_url":"https://codeload.github.com/rosbit/go-trealla/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosbit%2Fgo-trealla/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33666290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded","golang","prolog","trealla","trealla-prolog"],"created_at":"2024-11-15T12:17:11.074Z","updated_at":"2026-05-29T18:31:32.167Z","avatar_url":"https://github.com/rosbit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# An embeddable Prolog\n\n[trealla-prolog](https://github.com/trealla-prolog/trealla) is a compact, efficient Prolog interpreter written in C.\n\nThis package is intended to provide a wrapper to interact `trealla` with application written in golang.\nWith some helper functions, `go-trealla` makes it simple to calle Prolog from Golang, and `go-trallea` can be\ntreated as an embeddable Prolog.\n\n### Usage\n\nThe package is fully go-getable, so, just type\n\n  `go get github.com/rosbit/go-trealla`\n\nto install.\n\n#### 1. Instantiate a Prolog interpreter\n\n```go\npackage main\n\nimport (\n  \"github.com/rosbit/go-trealla\"\n  \"fmt\"\n)\n\nfunc main() {\n  ctx, err := trealla.NewTrealla(\"/path/to/trealla/exe\") // linux executable trealla-prolog(tpl) can be downloaded from releases.\n  if err != nil {\n      // error processing\n  }\n  ...\n}\n```\n\n#### 2. Load a Prolog script\n\nSuppose there's a Prolog file named `music.pl` like this:\n\n```prolog\nlisten(ergou, bach).\nlisten(ergou, beethoven).\nlisten(ergou, mozart).\nlisten(xiaohong, mj).\nlisten(xiaohong, dylan).\nlisten(xiaohong, bach).\nlisten(xiaohong, beethoven).\n```\n\none can load the script like this:\n\n```go\n   if err := ctx.LoadFile(\"music.pl\"); err != nil {\n      // error processing\n   }\n```\n\n#### 3. Prepare arguments and variables\n\n```go\n   // query Who listens to Music\n   args := []interface{}{trealla.PlVar(\"Who\"), trealla.PlVar(\"Music\")}\n   // solution #1: map[string]interface {}{\"Music\":\"bach\", \"Who\":\"ergou\"}\n   // solution #2: map[string]interface {}{\"Music\":\"beethoven\", \"Who\":\"ergou\"}\n   // solution #3: map[string]interface {}{\"Music\":\"mozart\", \"Who\":\"ergou\"}\n   // solution #4: map[string]interface {}{\"Music\":\"mj\", \"Who\":\"xiaohong\"}\n   // solution #5: map[string]interface {}{\"Music\":\"dylan\", \"Who\":\"xiaohong\"}\n   // solution #6: map[string]interface {}{\"Music\":\"bach\", \"Who\":\"xiaohong\"}\n   // solution #7: map[string]interface {}{\"Music\":\"beethoven\", \"Who\":\"xiaohong\"}\n\n   // query Who listens to \"bach\"\n   args := []interface{}{trealla.PlVar(\"Who\"), \"bach\"}\n   // solution #1: map[string]interface {}{\"Who\":\"ergou\"}\n   // solution #2: map[string]interface {}{\"Who\":\"xiaohong\"}\n\n   // query Which Music \"ergou\" listens to\n   args := []interface{}{\"ergou\", trealla.PlVar(\"Music\")}\n   // solution #1: map[string]interface {}{\"Music\":\"bach\"}\n   // solution #2: map[string]interface {}{\"Music\":\"beethoven\"}\n   // solution #3: map[string]interface {}{\"Music\":\"mozart\"}\n\n   // check whether \"ergou\" listens to \"bach\"\n   args := []interface{}{\"ergou\", \"bach\"}\n   // true\n```\n\n#### 4. Query the goal with arguments and variables\n\n```go\n   solutions, ok, err := ctx.Query(\"listen\", args...)\n```\n\n#### 5. Check the result\n\n```go\n   // error checking\n   if err != nil {\n      // error processing\n      return\n   }\n\n   // proving checking with result `false`\n   if !ok {\n      // the result is false\n      return\n   }\n\n   // proving checking with result `true`\n   if solutions == nil {\n      // the result is true\n      return\n   }\n\n   // solutions processing\n   for sol := range solutions {\n      fmt.Printf(\"solution: %#v\\n\", sol)\n   }\n```\n\nThe full usage sample can be found [sample/main.go](sample/main.go).\n\n### Status\n\nThe package is not fully tested, so be careful.\n\n### Contribution\n\nPull requests are welcome! Also, if you want to discuss something send a pull request with proposal and changes.\n\n__Convention:__ fork the repository and make changes on your fork in a feature branch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-trealla","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosbit%2Fgo-trealla","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosbit%2Fgo-trealla/lists"}