10.09 query-lang-init

10.09 - CS1102 Macros and quote to embed a little query language in Scheme Kathi Fisler adapted from Paul Graham's OnLisp query language October 8

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; CS1102: Macros and quote to embed a little query language in Scheme ;; Kathi Fisler, adapted from Paul Graham's OnLisp query language ;; October 8, 2007 ;;;;;;;;;;;; A DATABASE API ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define make-db make-hash-table) (define the_DB_ (make-db)) (define (db-add key value) (hash-table-put! the_DB_ key (cons value (db-query key)))) (define (db-query key) (hash-table-get the_DB_ key (lambda () empty))) (define-syntax fact (syntax-rules () [(fact pred data . ..) (db-add 'pred (list 'data . ..))])) ;;;;;;;;;;;; SEARCHING FOR BINDINGS ;;;;;;;;;;;;;;;;;;;;;;;;;; ;; A bindlist is a list[(varname value)] ;; example: '((?x apple) (?y orange)) ;; binding : var bindlist -> value or false ;; return value associated with var in bindlist, or false if no such binding (define (binding var bindlist) (let ([b (assq var bindlist)]) (if b (second b) false))) ;; match : list[numsym] list[sym] bindlist -> bindlist ;; Tries to match tuple of constants to args, respecting existing arg
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/06/2008 for the course CS 1102 taught by Professor Fisler during the Fall '07 term at WPI.

Page1 / 2

10.09 - CS1102 Macros and quote to embed a little query language in Scheme Kathi Fisler adapted from Paul Graham's OnLisp query language October 8

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online