Subject: Re: The usual silly subject elided From: Erik Naggum <erik@naggum.no> Date: 1999/10/29 Newsgroups: comp.lang.lisp Message-ID: <3150148973811268@naggum.no> * Rahul Jain | I know the utility of the s-exp form, but it's a real pain to have to | convert a mathematical equation to it. Maybe it's just because I'm only | used to in- and postfix notation. Eventually I'll master prefix notation | and be the master of all notation (except for any really strange ones | that I've never head of....) :P (defun trivial-infix-reader (input-stream char) (declare (ignore char)) (let ((list (read-delimited-list #\] input-stream t))) (cond ((null (cddr list)) list) ;trivial: 1- and 2-lists ((null (cdddr list)) ;swap first and second of 3-lists (list (second list) (first list) (third list))) (t (list* (second list) (first list) (loop with operator = (second list) for pair on (cdr list) by #'cddr unless (cdr pair) do (error "infix expression is not well-formed") unless (eq operator (first pair)) do (error "infix operator is not properly redundant") collect (second pair))))))) when this definition is available, you may evaluate (set-macro-character #\[ 'trivial-infix-reader) (set-syntax-from-char #\] #\)) and type things like [2 + 3], [sqrt pi], [10 log 2], [x < y < z], and have them all come out right. for a more powerful infix reader that does precedence and such, there is some stuff available in the Common Lisp archives, but I suggest you stick to the above simplicity so you don't get dragged into maintaining a mini- language which nobody will benefit from, including yourself some ways down the road. enjoy! #:Erik