[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #+ and #-

           #+ and #- work just fine; the problem is that ":CCL" is in the *FEATURES*
           list but the symbol "CCL" is not.
        No.  This is an obnoxious "bug" in MACL.  I say "bug" because while it
        really didn't contradict anything in CLtL, it was different from every
        other Lisp implementation I've used (>= 6 others).  Other implementations
        treat #+foo feature names as being read in the KEYWORD package.  The ANSI
        X3J13 committee voted to include this behavior explicitly in evolving
        standard.  In other words #+foo should be the same as #+:foo (and not
        Too bad this wasn't fixed in 1.3.2.
     This will be fixed in 2.0.
Or perhaps sooner:

; Replace the #+ and #- reader macros with versions which read
; the feature specification with the KEYWORD package as the default.
; Finally.

(defun eval-feature (form)
  (if (consp form)
    (ecase (car form)
      ((not :not) 
       (not (eval-feature (cadr form))))
      ((and :and)
       (dolist (feature (cdr form) t)
         (unless (eval-feature feature) (return nil))))
      ((or :or) 
       (dolist (feature (cdr form))
         (when (eval-feature feature) (return t)))))
    (not (null (member form *features* :test #'eq)))))

(defun read-feature (stream)
  (let* ((*package* ccl:*keyword-package*))
    (eval-feature (read stream))))

(defun read-time-conditional-reader (stream subchar arg)
  (if arg 
    (error "Numeric argument ~s not allowed in #+/#- reader macros ." arg))
  (unless *read-suppress*
    (let ((feature (read-feature stream)))
      (if (if (eql #\+ subchar) (not feature) feature)
        (let* ((*read-suppress* t))
          (read stream)))))

(set-dispatch-macro-character #\# #\+ #'read-time-conditional-reader)
(set-dispatch-macro-character #\# #\- #'read-time-conditional-reader)