Parenlog
This package contains an implementation of a language very similar to pure Prolog, except with parenthetical notation.
1 Embedded Parenlog
The easiest way to get started using Parenlog for PLT Scheme is with the main module:
(require (planet jaymccarthy/parenlog:1:2)) |
Here is a basic example of using Parenlog:
Examples: | |||||||||||||||||||
| |||||||||||||||||||
| |||||||||||||||||||
'( #hasheq()) | |||||||||||||||||||
| |||||||||||||||||||
'( #hasheq((X . moria) (Y . larn)) #hasheq((X . moria) (Y . omega)) #hasheq((X . moria) (Y . hack)) #hasheq((X . larn) (Y . moria))) |
(define-model id stmt ...) | |||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||
|
(query-model model-expr maybe-limit body-query) | ||||||||||||
| ||||||||||||
|
Returns a value matching the contract: (listof (hash/c symbol? anc/c)). Each value in this list is a substitution of body-query that model-expr proves.
2 Standalone Parenlog
(require (planet jaymccarthy/parenlog:1:2/lang)) |
Parenlog can also be used as a standalone module language.
#lang planet jaymccarthy/parenlog:1:2
At a high level, the body of a Parenlog module is the body of a define-model form and any REPL interaction is placed within a query-model form. There are, of course, a few caveats.
First, occurrences of (? body-query) in the module body are delayed and used as queries.
X=moria |
Y=larn |
Third, next can be input at the REPL to search for another answer to the last query. If there was no last query, this evaluates to an error. If there are no more answers, done is printed.
#lang planet jaymccarthy/parenlog:1:2 |
(type Gamma numConst num) |
(type Gamma boolConst bool) |
(:- (type Gamma (if Test Then Else) Tau) |
(type Gamma Test bool) |
(type Gamma Then Tau) |
(type Gamma Else Tau)) |
(? (type mt numConst num)) |
(? (type mt (if boolConst numConst numConst) num)) |
(? (type mt (if boolConst numConst boolConst) num)) |
(? (type mt boolConst T)) |
(? (type mt (if boolConst numConst numConst) T)) |
(? (type mt (if boolConst numConst boolConst) T)) |
yes |
yes |
no |
T=bool |
T=num |
no |
We can then query the model from the REPL: