From: Wheeler Ruml

Subject: Re: numbers and I/O

Date: 1996-8-25 14:14

> See below the compiler messages one gets when submitting your code to > ACL 4.3. > [...] > Warning: While compiling these undefined functions were referenced: > WR-UTILS::CLONE-ARRAY, WR-UTILS::WHITESPACE-P, > WR-UTILS::WITH-OPEN-IB, WR-UTILS::F, WR-UTILS::WHILE, > WR-UTILS::GET-WAITING-STREAM-STRING, WR-UTILS::EAT-WHITESPACE.
My apologies to everyone who tried running the code I posted - I forgot to remove calls to utilities in other files, and I listed the files in reverse order (fast-io should be loaded before parse-nums). Below I enclose the missing utilities, which should be in an additional file which is loaded first (it contains macros which call macros). Wheeler -- Wheeler Ruml, Aiken 220, <eecs.harvard.edu, at ruml> (617) 496-1066 (fax) http://www.das.harvard.edu/users/students/Wheeler_Ruml/Wheeler_Ruml.html ================ ;; Utilities needed by fast-io and parse-nums. ;; ;; Wheeler Ruml <eecs.harvard.edu) at (ruml> (defpackage "WR-UTILS" (:nicknames "WR") (:use common-lisp) ;; (:export ... add what you want ...) ) (in-package wr-utils) (deftype non-neg-fixnum () `(integer 0 ,most-positive-fixnum)) (deftype basic-vector (elt-type &optional (size '*)) `(simple-array ,elt-type (,size))) ;; from Graham's On Lisp book. useful for writing macros. (defmacro with-gensyms (syms &body body) "set the value of each symbol in SYMS to a unique gensym" `(let ,(mapcar #'(lambda (s) `(,s (gensym))) syms) <body)) at ,> ;; see also "loop while" (defmacro while (test &body body) "repeat BODY while TEST is true" `(do () ((not ,test)) <body)) at ,> ;; see also "loop for" (defmacro for ((var start end &key (type 'non-neg-fixnum)) &body body) "do BODY from VAR = START (inclusive) up to END (exclusive), taking care to evaluate END only once. Returns NIL." (with-gensyms (end-val) `(do ((,var ,start (1+ ,var)) (,end-val ,end)) ((>= ,var ,end-val)) (declare (type ,type ,var ,end-val)) <body))) at ,> (defun eat-chars (strm char-set) (declare (type stream strm)) (loop (let ((ch (read-char strm nil nil))) (unless (member ch char-set) (when ch (unread-char ch strm)) (return))))) (defconstant +whitespace+ '(#\Newline #\Space #\Tab #\Page #\Linefeed #\Return)) ;;;;;;; SHOULD BE AN INLINE FUNCTION ;; (but even ACL 4.3 doesn't seem to have them!?) (defun whitespace-p (ch) (member ch +whitespace+ :test #'char=)) (defun eat-whitespace (strm) (eat-chars strm +whitespace+)) (defun get-waiting-stream-string (output-stream &optional (eof-error-p nil) (eof-val nil)) "returns all waiting characters on the OUTPUT-STREAM and returns them as a string. If encounters EOF and EOF-ERROR-P is non-nil, returns EOF-VAL(defaults to NIL)." (do ((output-string (make-array 128 :element-type 'character :adjustable 't :fill-pointer 0)) (new-ch (read-char-no-hang output-stream nil t) (read-char-no-hang output-stream nil t))) ((null new-ch) output-string) (if (eq new-ch t) (if eof-error-p (return eof-val) (return output-string)) (vector-push-extend new-ch output-string 512)))) (defmacro do-vector ((var vec &key (start 0) (end nil) (elt-type nil) (key nil) (var-type elt-type) (index (gensym))) &body body) "binds VAR to each element of VEC in turn. returns NIL." (with-gensyms (the-vec) `(let ((,the-vec ,vec)) ,(when elt-type `(declare (type (basic-vector ,elt-type) ,the-vec))) (for (,index ,start ,(if end end `(the non-neg-fixnum (length ,the-vec)))) (let ((,var ,(if key `(,key (aref ,the-vec ,index)) `(aref ,the-vec ,index)))) ,(cond (var-type `(declare (type ,var-type ,var))) ((and (null key) elt-type) `(declare (type ,elt-type ,var)))) <body))))) at ,> ;; implemented as a macro to allow in-lining of arefs on certain types (defmacro clone-array (src-seq new-len &key (elt-type t) (copy-end nil)) "returns a new simple vector of NEW-LEN which has elements from SRC-SEQ as its first COPY-END elements (default is length of SRC-SEQ)." (with-gensyms (new-array el i) `(let ((,new-array (make-array ,new-len :element-type ',elt-type))) (declare (type (basic-vector ,elt-type) ,new-array)) (when ,src-seq (do-vector (,el ,src-seq :end ,copy-end :index ,i :elt-type ,elt-type) (setf (aref ,new-array ,i) ,el))) ,new-array))) ;; EOF - utilities needed for fast-io and parse-nums