From ... From: Erik Naggum Subject: Re: How To make '(--a) equals 'a Date: 2000/04/13 Message-ID: <3164645518513769@naggum.no>#1/1 X-Deja-AN: 610815634 Content-Transfer-Encoding: 8bit References: <8d4spq$ntl$1@nnrp1.deja.com> mail-copies-to: never Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: newsmaster@eunet.no X-Trace: oslo-nntp.eunet.no 955656912 5446 195.0.192.66 (13 Apr 2000 20:15:12 GMT) Organization: Naggum Software; vox: +47 8800 8879; fax: +47 8800 8601; http://www.naggum.no User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.5 Mime-Version: 1.0 NNTP-Posting-Date: 13 Apr 2000 20:15:12 GMT Newsgroups: comp.lang.lisp * David | I am a beginner in Lisp. Recently I have been doing a programming | exercise in Lisp which is to build a test-tree using a so-called ID3 | algorithm in A.I. one of the smaller tasks to solve this problem is to | make "not not a" (ie. '(--a) ) equals "a"; where "a" is any atom in | Lisp. This is trivial in Maths, but to make this equivalence work in Lisp | seems very tricky to me. My main difficulty is that I don't know how to | separate '(--a) into "-", "-" and "a". once I know how to do this the | problem is straight forward. if you use a richer character set, you can use the ¬ operator (found in ISO 8859-1, or "ISO Latin 1", also known among Microsoft victims as "the ANSI character set"), and you can teach your Common Lisp reader to make that a single-character operator that either returns itself or returns the "not" operator already in the language, listifying its argument like quote (') does. (defun not-reader (stream char) (list 'not (read stream nil nil t))) (set-macro-character #\¬ #'not-reader nil) '¬¬a => (not (not a)) simplifying this expression can now be done at the semantic level, which basically entails walking over your expressions looking for not forms and replacing the form with the cadadr of the form. the normal evaluation rules in Common Lisp makes (not (not a)) the canonical true boolean value, t, for any non-nil a, and nil for nil. don't know if this answered your question, it's kind of vague. #:Erik