On this page:
define-model
:  -
query-model
model?

1 Embedded Parenlog🔗ℹ

The easiest way to get started using Parenlog for Racket is with the main module:

 (require parenlog) package: parenlog

Here is a basic example of using Parenlog:

Examples:
> (define-model family-tree
    (parent rogue moria)
    (parent rogue larn)
    (parent rogue omega)
    (parent rogue hack)
    (parent moria angband)
    (parent hack nethack)
    (parent angband tome)
    (parent angband zangband)
    (parent omega adom)
    (parent nethack adom)
    (parent nethack zapm)
    (parent nethack slashem)
    (parent nethack crawl)
  
    (:- (sibling X Y)
        (parent Z X)
        (parent Z Y)
        (,(compose not equal?) X Y))
  
    (:- (adds? X Y Z)
        (,+ X Y :- Z)))
> (query-model family-tree
               (sibling adom zapm))

'(#hasheq())

> (query-model family-tree
               #:limit 4
               (sibling X Y))

'(#hasheq((X . moria) (Y . larn))

  #hasheq((X . moria) (Y . omega))

  #hasheq((X . moria) (Y . hack))

  #hasheq((X . larn) (Y . moria)))

> (query-model family-tree
               (adds? 5 6 Z))

eval:5:0: query-model: expected parenlog query s-expr or

expected the identifier `unsyntax'

  at: 5

  in: (query-model family-tree (adds? 5 6 Z))

  parsing context:

   while parsing parenlog query s-expr

    term: (5 6 Z)

    location: eval:5:0

   while parsing parenlog query s-expr

    term: (adds? 5 6 Z)

    location: eval:5:0

   while parsing parenlog query form

    term: (adds? 5 6 Z)

    location: eval:5:0

   while parsing parenlog query

    term: (adds? 5 6 Z)

    location: eval:5:0

syntax

(define-model id (~seq #:require model-id) ... stmt ...)

 
stmt = head-query
  | (:- head-query body-query ...)
     
head-query = s-expr
     
body-query = s-expr
  | (== s-expr s-expr)
  | (,pred s-expr ...)
  | (,fun s-expr ... :- s-expr ...)
 
  id : identifier?
  pred : (any/c ... -> boolean?)
  fun : (any/c ... -> any)
Defines id as a Parenlog model, extending each model-id.

_ counts as variable that is unique at every occurrence.

A s-expr may contain unsyntax to escape to Racket.

syntax

:-

Syntax that may only appear within define-model.

syntax

(query-model model-expr maybe-limit body-query)

 
maybe-limit = 
  | #:limit limit-expr
 
  model-expr : model?
  limit-expr : number?
Queries model-expr with body-query until limit-expr results are found or no results remain.

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.

procedure

(model? v)  boolean?

  v : any/c
Returns #t if v was bound by define-model; #f otherwise.