;;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10 -*- ;;;; --------------------------------------------------------------------------- ;;;; File name: general-utilities.lsp ;;;; System: ;;;; Author: Shawn Nicholson ;;;; Created: July 15, 2002 16:38:35 ;;;; Purpose: ;;;; --------------------------------------------------------------------------- ;;;; Modified: Wednesday, October 30, 2002 at 14:40:22 by nicholson ;;;; --------------------------------------------------------------------------- (in-package :textual-case-display) (defun pretty-print-to-string (form &optional (width 40)) "Pretty-prints a LISP expression to a string. The output is constrained to a width that is the number of characters specified by width." (let ((*print-right-margin* width) (*package* (find-package :data))) (remove-leading-newline (with-output-to-string (s) (pprint form s))))) (defun remove-leading-newline (string) (if (eq (elt string 0) #\newline) (subseq string 1) string)) (defun mentions (expression elem &key (test 'equal)) ;; Returns true if elem is mentioned anywhere in expression ;; Similar to "member" except is recursive (cond ((null expression) nil) ((funcall test expression elem) expression) ((not (listp expression)) nil) (t (or (mentions (first expression) elem :test test) (mentions (rest expression) elem :test test))))) ;;; ;;;(defun mentions (fact datum) ;;; ;; a recursive member - we want any expression that mentions datum anywhere in the fact... ;;; (let ((found (member datum fact))) ;;; (if found ;;; found ;;; (do ((elem fact (cdr elem))) ;;; ((or (null elem) ;;; found) found) ;;; (when (listp (first elem)) ;;; (setf found (mentions (first elem) datum))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; End of Code