r/prolog • • Oct 11 '20

Trealla Prolog: A compact, efficient Prolog interpreter written in plain-old C.

https://github.com/infradig/trealla
55 Upvotes

1 comment sorted by

10

u/mtriska Oct 11 '20

This is a very interesting new Prolog system, the first system that uses the system call mmap to map file contents directly to memory for very efficient and convenient parsing with DCGs.

For instance, with the non-terminal list//1 defined as:

list([]) --> [].
list([L|Ls]) --> [L], list(Ls).

We can apply the DCG to a file with phrase_from_file/2:

?- phrase_from_file(list(Ls), "README.md").

Yielding the file contents of README.md, represented as a list of characters Ls:

Ls = "Trealla ProLog..."

Internally, strings are very compactly represented in packed UTF-8 encoding, while to Prolog programs, they are accessible for convenient reasoning as lists of characters. This representation was pioneered by Scryer Prolog, and makes all well-known predicates over lists, like append/3, reverse/2, last/2 etc. automatically available for reasoning about strings.

This is a really nice and exciting development, and I hope other systems will also adopt this idea in the future!