Hi all!! Just wanted to share a little lang that I've been working on over the weekend: #lang clingo
This library/language provides FFI bindings to the libclingo Answer Set programming solver (think something like datalog with some funky semantics).
I've written a little wrapper lang ontop of these bindings to provide a racket-friendly syntax to it:
#lang clingo
(set-clingo-option! "solve.models" 0)
(person (|| 'alice 'bob))
(evil 'alice)
(:- (good p)
(person p) (not (evil p)))
;; returns '((person alice) (person bob)
;; (evil alice)
;; (good bob))
This corresponds to the following clingo program if you're familiar with it:
person(alice;bob).
evil(alice).
good(P) :- person(P), not evil(P).
6 Likes
Happy to field any questions!
I'd like to also ask for a help question as well...
In the DSL, there are these prolog like rules --- I'd like to setup the syntax objects such that Racket interprets them as proper identifiers with the lines and everything.
Currently what I'm trying is:
Where this attribute datum
, returns a function that sends the syntax object being visited back via a callback.
This callback is setup in the outermost step of the parsing, so when parsing a rule, before parsing the LHS, we setup a callback to store these syntax objects into a list:
[(_ lhs:constraint rhs ...)
(define defined-variables '())
(define (handle-definition stx)
(set! defined-variables (cons stx defined-variables))
stx)
(define data
(parameterize ([current-resolve-symbol-fun handle-definition])
((attribute lhs.datum))))
(with-syntax ([lhs-datum data]
[(var ...) defined-variables])
#'(let-syntax ([var #'var] ...)
(rule lhs-datum
(list (clingo-constraint rhs) ...))))]
I then bind these syntax variables with let-syntax so that later when I run syntax-local-value
they'll retrieve the syntax objects from the LHS, and can thus use them for source location information.
This is based off some examples I've seen in the docs, but honestly, I'm really don't have a very good clue of what I'm doing here... I would appreciate if anyone could point me in the right direction w.r.t this...
1 Like
So, am I going to be excited to use this extension when I finally get past day 3 of Advent of Code? Perhaps so...
2 Likes