From ... Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!129.240.148.23!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail From: Erik Naggum Newsgroups: comp.lang.lisp Subject: Re: Small read macro issue Date: 07 Oct 2002 15:50:56 +0000 Organization: Naggum Software, Oslo, Norway Lines: 71 Message-ID: <3242994656390587@naggum.no> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: maud.ifi.uio.no 1034005857 28677 129.240.65.5 (7 Oct 2002 15:50:57 GMT) X-Complaints-To: abuse@ifi.uio.no NNTP-Posting-Date: 7 Oct 2002 15:50:57 GMT Mail-Copies-To: never User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.lisp:43352 * Adam Warner | I'm just a little stuck on how to turn this syntax: | | (function-name[some text]"more text") | | Into this syntax: | | (function-name :options "[some text]" "more text") That is the wrong goal. | This allows me to distinguish whether an initial optional string has been | input. So you need a mechanism to distinguish them, not an answer to what you are asking for. | Otherwise there is no way to distinguish between these situations: | | (function-name "options" "text1" "text2" ...) | (function-name "text1" "text2" ...) | | (Note: I am unaware of any way to attach a particular type to the initial | optional string so that it can be tested for as different to a regular | string). A wrapper class. The solution is so close you have probably overlooked it. (defclass warner-option () ((option :type string :reader warner-option :initarg :option))) ;; useful for debugging (defmethod print-object ((option warner-option) stream) (print-unreadable-object (option stream :type t) (prin1 (warner-option option) stream))) (defun option-reader (in char) (declare (ignore char)) (prog1 (make-instance 'warner-option :option (with-output-to-string (out) (peek-char #\] (make-echo-stream in out)))) (read-char in))) #| ;; or if you really want the [] with the string: (defun option-reader (in char) (make-instance 'warner-option :option (with-output-to-string (out) (unread-char char in) (with-open-stream (in (make-echo-stream in out)) (peek-char #\] in) (read-char in))))) |# (set-macro-character #\[ 'option-reader) Now, reading this: (function-name[some text]"more text") causes this to be returned: (function-name # "more text") You can now distinguish the option string from other strings. -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.