Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathsou/picolog
Minimal Prolog interpreter
https://github.com/nathsou/picolog
Last synced: 25 days ago
JSON representation
Minimal Prolog interpreter
- Host: GitHub
- URL: https://github.com/nathsou/picolog
- Owner: nathsou
- License: mit
- Created: 2020-09-30T04:27:55.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-11T15:00:51.000Z (over 3 years ago)
- Last Synced: 2023-10-20T21:59:18.205Z (about 1 year ago)
- Language: TypeScript
- Size: 48.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Picolog
## Minimalistic prolog interpreter
Picolog provides a minimal prolog
interpreter implementation that can be embedded in other js/ts/node/deno projects to perform logical computations.### Installation
Picolog is available on [deno.land](https://deno.land/x/pico)
### Usage
See the [documentation](https://doc.deno.land/https/deno.land/x/pico/mod.ts)
To launch the REPL:
```bash
deno run -A --unstable https://deno.land/x/pico/repl/Repl.ts src.pl
```the --unstable flag is needed since Deno.setRaw (used by the REPL) is a new API.
To embed in a project :
```typescript
import {
resolve, parse, program, query,
isOk, formatAnswer
} from 'https://deno.land/x/pico/mod.ts';const prog = parse(`
append([], Bs, Bs).
append([A|As], Bs, [A|ABs]) :- append(As, Bs, ABs).
`, program);const goals = parse('append(A, B, [1, 2, 3]).', query);
if (isOk(prog) && isOk(goals)) {
// iterator of all solutions
const solutions = resolve(prog.value, goals.value);for (const answer of solutions) {
// answer maps free variables from the query
// to values satisfying the rules
console.log(formatAnswer(answer));
}
}// output:
// A = []
// B = [1, 2, 3]// A = [1]
// B = [2, 3]// A = [1, 2]
// B = [3]// A = [1, 2, 3]
// B = []
```### Todo
- [x] support the cut operator
- [ ] support arithmetic expressions
- [ ] add modules
- [ ] add a trace mode
- [ ] compile to [WAM](https://www.wikiwand.com/fr/Warren%27s_Abstract_Machine) for better performance?