X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=utils.lisp;h=2d2a9d82e818ea33eada60dadfcb7783883fa28d;hb=91da637a38b3a1f38d0bf25b2e3584b80400664f;hp=20f6a452de2284afcb0df17cfc9fae7168311561;hpb=a5621a5bf235313916f437a55d9998418ee26f5a;p=lml2.git diff --git a/utils.lisp b/utils.lisp index 20f6a45..2d2a9d8 100644 --- a/utils.lisp +++ b/utils.lisp @@ -1,6 +1,18 @@ -;;; $Id: utils.lisp,v 1.1 2003/06/20 04:12:29 kevin Exp $ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION ;;;; -;;;; General purpose utilities +;;;; Name: utils.lisp +;;;; Purpose: General purpose utilities +;;;; Author: Kevin M. Rosenberg +;;;; Date Started: June 2002 +;;;; +;;;; $Id$ +;;;; +;;;; This file, part of LML2, is copyrighted and open-source software. +;;;; Rights of modification and redistribution are in the LICENSE file. +;;;; +;;;; ************************************************************************* (in-package #:lml2) @@ -12,35 +24,16 @@ `(aif ,test-form (progn ,@body))) -(defun keyword-symbol? (x) - "Returns T if object is a symbol in the keyword package" - (and (symbolp x) - (string-equal "keyword" (package-name (symbol-package x))))) - -(defun list-to-spaced-string (list) - (format nil "~{~A~^ ~}" list)) - -(defun print-n-chars (char n stream) - (declare (fixnum n) - (optimize (speed 3) (safety 0) (space 0))) - (do ((i 0 (1+ i))) - ((= i n) char) - (declare (fixnum i)) - (write-char char stream))) - -(defun indent-spaces (n &optional (stream *standard-output*)) - "Indent n*2 spaces to output stream" - (print-n-chars #\space (+ n n) stream)) - (defun print-file-contents (file &optional (strm *standard-output*)) "Opens a reads a file. Returns the contents as a single string" (when (probe-file file) - (with-open-file (in file :direction :input) - (do ((line (read-line in nil 'eof) - (read-line in nil 'eof))) - ((eql line 'eof)) - (write-string line strm) - (write-char #\newline strm))))) + (let ((eof (cons 'eof nil))) + (with-open-file (in file :direction :input) + (do ((line (read-line in nil eof) + (read-line in nil eof))) + ((eq line eof)) + (write-string line strm) + (write-char #\newline strm)))))) (defun date-string (ut) (check-type ut integer) @@ -80,3 +73,17 @@ #-(or allegro clisp cmu scl sbcl cormanlisp lispworks lucid mcl) (truename ".")) +#+ignore +(defun fformat (&rest args) + (declare (dynamic-extent args)) + (apply (if (find-package 'kmrcl) + (symbol-function (intern (symbol-name #:fformat) + (symbol-name #:kmrcl))) + #'format) + args)) + +(defmacro fformat (stream control-string &rest args) + (if stream + `(funcall (formatter ,control-string) ,stream ,@args) + `(format nil ,control-string ,@args))) +