From ... From: Erik Naggum Subject: Re: The usual silly subject elided Date: 1999/10/29 Message-ID: <3150148973811268@naggum.no>#1/1 X-Deja-AN: 541877056 References: <87zox5ooiz.fsf@orion.dent.isdn.cs.tu-berlin.de> <3816A93E.42BEDFEA@owlnet.rice.edu> <87aep4oj9l.fsf@orion.dent.isdn.cs.tu-berlin.de> <38178DF4.5BB36F17@owlnet.rice.edu> <87bt9kq69z.fsf@foobar.orion.no> <3818BBC9.B4CE19B1@owlnet.rice.edu> mail-copies-to: never X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 941160174 18554 195.0.192.66 (29 Oct 1999 01:22:54 GMT) Organization: Naggum Software; +47 8800 8879; +1 510 435 8604; http://www.naggum.no NNTP-Posting-Date: 29 Oct 1999 01:22:54 GMT Newsgroups: comp.lang.lisp * 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