changeset 583: |
1a0df4444a9f |
parent: |
efb4a19ff530
|
child: |
35bb0d5ec95e |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Thu, 08 Aug 2024 23:01:20 -0400 |
permissions: |
-rw-r--r-- |
description: |
dql notes |
1 ;;; dql.lisp --- Deductive Query Langs 3 ;; Query Engine for Inference-based query langs. 7 ;; Prolog, Datalog, etc. 11 ;; My current understanding is that Prolog and SQL-derived langs share much in 12 ;; common. You can certainly do deductive logic in SQL and you can do 13 ;; relational table-based logic in Prolog. 15 ;; It is interesting to note that they were both discovered around the same 16 ;; time in the 60s-70s, but in very different contexts. Prolog was intended 17 ;; for NLP and SQL (relational-algebra/RA) was the foundation for 18 ;; RDBMS. Prolog never really found the same sort of success had by SQL, but 19 ;; with the AI summer in full bloom and NLP being a hot-topic, perhaps we will 20 ;; see the scales shift. 24 ;; The WAM compiler is a bit too much to understand let alone implement at 25 ;; this stage. The design of this package will be much simpler and optimized 26 ;; for compatibility with Lisp Objects. 28 ;; The design we're going for in this package is what I would consider the 29 ;; Lisper's version of Datalog. We want to implement just enough to be useful 30 ;; as a query language, and then use it to bootstrap a more elegant Prolog 31 ;; compiler, likely in SYN/PROLOG. 35 ;; compiled code + constants -> physical plan -> arena + hash-tables -> engine 53 ;; https://franz.com/support/documentation/11.0/prolog.html 55 ;; https://github.com/wmannis/cl-gambol 57 ;; https://norvig.com/paip/README.html 59 ;; https://en.wikipedia.org/wiki/Negation_as_failure 61 ;; https://github.com/bobschrag/clolog/blob/main/architecture.md 68 (declaim (fixnum *lips*)) 70 "Count of logical inferences performed.") 73 (defvar *interactive* t "true iff interacting with user") 74 (defvar *auto-backtrack* nil "return all solutions if true") 75 (defvar *last-continuation* nil "saved state of the system") 76 (defvar *trail* nil "the trail, for backtracking") 77 (defvar *x-env* nil "env for goals") 78 (defvar *y-env* nil "env for rules") 79 (defvar *top-level-envs* nil "saves top-level environments") 80 (defvar *top-level-vars* nil "saves top-level variable names") 81 (defvar *num-slots* -1 "number of logical variables in a query") 82 (defvar *rules* (make-hash-table) "hash table for prolog rule heads") 85 (define-condition dql-error (error) ()) 87 (deferror simple-dql-error (dql-error simple-error) ()) 89 (defun simple-dql-error (ctrl &rest args) 90 (error 'simpl-dql-error :format-control ctrl :format-arguments args)) 93 (defclass dql-query (query) ()) 95 (defclass dql-data-source (data-source) () 96 (:documentation "Data source which can be used withing DQL expressions.")) 100 ;; NOTE 2024-08-03: we're loosely following along with CL-GAMBOL, but sticking 101 ;; with defstructs instead of vectors for the most part. I'm willing to pay 102 ;; the immediate cost of not vectorizing in hopes that the fact that structs 103 ;; are vector-backed and multi-threaded contexts exist will minimize the 107 (defmacro ?- (&body clauses)) 109 (defmacro *- (head &body body)) 112 (defclass dql-parser (query-parser) ())