Subject: Re: How To make '(--a) equals 'a
From: Erik Naggum <>
Date: 2000/04/13
Newsgroups: comp.lang.lisp
Message-ID: <>

* 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)

=> (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.