;;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10 -*- ;;;; --------------------------------------------------------------------------- ;;;; File name: macros.lsp ;;;; System: FIRE ;;;; Version: v1 ;;;; Author: John Everett ;;;; Created: March 5, 2001 09:22 ;;;; Purpose: Centralize all macros to ensure early definition ;;;; --------------------------------------------------------------------------- ;;;; Modified: Tuesday, March 23, 2004 at 10:42:39 by hinrichs ;;;; --------------------------------------------------------------------------- (in-package :fire) (declaim (special *kb* *retriever* *retrieval-coverage* *n-answers-sought*)) ;;; Define ALL macros here. This file is loaded first, ensuring that macro ;;; definitions are present prior to macro calls in the source code. ;;; See ask-tell.lsp for related source ;;; 7/7/03 (TRH) fixed variable capture of *reasoner* (defmacro ask-it (query &key reasoner (context :all) (number :all) (response :pattern) (effort :all)) "Ask-it provides friendly macro for debugging/development/interaction" `(ask ,query ,(or reasoner 'fire::*reasoner*) ,context ,number ,response ,effort)) ;;; 7/7/03 (TRH) fixed variable capture of *reasoner* (defmacro tell-it (fact &key reasoner (reason :user) (context :base-kb)) "Tell-it provides user-friendly interface for TELL." `(tell ,fact ,(or reasoner 'fire::*reasoner*) ,reason ,context)) ;;; See defs.lsp for related source ;;; ;;; trap-error is now in the QRG package and since FIRE "uses" the QRG package, ;;; grrrr, we can't let it be redefined here. (N.B. be very sparing in which ;;; packages you "use" it can cause all sorts of name conflicts -- the very ;;; things you use different packages to avoid.) Since we want FIRE to use ;;; QRG's trap-error anyway, I've just commented out FIRE's own definition ;;; of it. ;;; (JMU 1/14/2004) ;;; ;;;(eval-when (:load-toplevel :compile-toplevel :execute) ;;; (defmacro trap-error ((error-type &rest trap-forms) &body body) ;;; "Executes trap-forms whenever an error of error-type occurs in body." ;;; (let ((tag (gensym "error-handling-block"))) ;;; `(block ,tag ;;; (handler-bind ((,error-type ;;; #'(lambda (condition) ;;; (declare (ignorable condition)) ;;; (return-from ,tag ;;; (progn ,@trap-forms))))) ;;; ,@body))))) ;;; See kb-api.lsp for related source (defmacro with-kb (kb &rest forms) `(let ((*kb* ,kb)) ,@ forms)) ;;; See reasoner.lsp for related source (defmacro with-reasoner (reasoner &rest forms) `(let ((*reasoner* ,reasoner)) (ltre::with-ltre (ltre *reasoner*) ,@ forms))) ;; lambda binds :coverage argument to retrieve, defaults to :specs. (defmacro with-retrieve-coverage (retrieve-coverage &rest forms) `(let ((*retrieve-coverage* ,retrieve-coverage)) ,@forms)) ;;; Bind *n-answers-sought* intelligently: (defmacro with-n-answers-sought ((term &optional (num 1)) &body body) (let ((termvar (gensym)) (n (gensym))) `(let ((,termvar ,term) (,n nil)) (cond ((and (consp ,termvar) (eq (first ,termvar) 'cl-user::thereExistAtLeast)) (setq ,n (second ,termvar))) ((and (consp ,termvar) (eq (first ,termvar) 'cl-user::thereExistAtMost)) (setq ,n (1+ (second ,termvar)))) (t (setq ,n ,num))) (let ((*n-answers-sought* ,n)) ,@body)))) (define-modify-macro unionf (other-set &rest keywords) union) (define-modify-macro nunionf (other-set &rest keywords) nunion) ;;;; --------------------------------------------------------------------------- ;;;; END OF CODE