Fri Feb 5 09:02:42 UTC 2010 pix@kepibu.org * Add (enable-template-reader), so it is easy to turn on the template reader Useful when there are conflicts on #T, such as with closure-html. diff -rN -u old-cl-unification/cl-unification.asd new-cl-unification/cl-unification.asd --- old-cl-unification/cl-unification.asd 2014-03-26 04:18:29.000000000 +0000 +++ new-cl-unification/cl-unification.asd 2014-03-26 04:18:29.000000000 +0000 @@ -25,6 +25,7 @@ (:file "substitutions") (:file "lambda-list-parsing") (:file "templates-hierarchy") + (:file "template-reader") (:file "unifier") (:file "match-block") (:file "apply-substitution") diff -rN -u old-cl-unification/template-reader.lisp new-cl-unification/template-reader.lisp --- old-cl-unification/template-reader.lisp 1970-01-01 00:00:00.000000000 +0000 +++ new-cl-unification/template-reader.lisp 2014-03-26 04:18:29.000000000 +0000 @@ -0,0 +1,67 @@ +;;; Setting up the reader macro. +(in-package "CL.EXT.DACF.UNIFICATION") + +;;; 20080711 MA: +;;; Reverted to the old version with MAKE-LOAD-FORM added. Template +;;; objects are created at read-time. + +(defun |sharp-T-reader| (stream subchar arg) + (declare (ignore subchar arg)) + (let ((spec (read stream t nil t))) + (typecase spec + (null (make-template nil spec)) + (cons (make-template (first spec) spec)) + (t (make-template spec spec))))) + +(defmethod make-load-form ((x template) &optional env) + (make-load-form-saving-slots x :environment env)) + + +#|| +;;; Version with more 'macro-like' behavior. The previous version +;;; created an object at read-time, which may cause problems with +;;; MAKE-LOAD-FORMs, constant-ness etc etc. +;;; +;;; 20080713 MA +;;; Removed because it was not working well with nested templates. +;;; Reverted to the original one plus MAKE-LOAD-FORM. + +(defun |sharp-T-reader| (stream subchar arg) + (declare (ignore subchar arg)) + (let ((spec (read stream t nil t))) + (typecase spec + (null `(make-template nil ',spec)) + (cons `(make-template ',(first spec) ',spec)) + (t `(make-template ',spec ',spec))) + )) +||# + +(eval-when (:load-toplevel :execute) + (set-dispatch-macro-character #\# #\T '|sharp-T-reader|)) + + +#|| Useless with the read time templates and MAKE-LOAD-FORM. + +(defun rewrite-template-spec (spec) + "Rewrites a template specification. +The rewriting simply makes sure that sub-templates are created as needed. +The result is either the SPEC itself or an appropriate call to LIST." + + (typecase spec + (atom `',spec) + (cons (destructuring-bind (head &rest tail) + spec + (case head + (quote spec) + (make-template `(make-template ,(first tail) + ,(rewrite-template-spec (second (second tail))))) + (t `(list ',head ,@(mapcar #'rewrite-template-spec tail))) + ))) + (t `',spec))) + +||# + +(defmacro enable-template-reader () + `(eval-when (:compile-toplevel :load-toplevel :execute) + (setf *readtable* (copy-readtable *readtable*)) + (set-dispatch-macro-character #\# #\T '|sharp-T-reader|))) diff -rN -u old-cl-unification/templates-hierarchy.lisp new-cl-unification/templates-hierarchy.lisp --- old-cl-unification/templates-hierarchy.lisp 2014-03-26 04:18:29.000000000 +0000 +++ new-cl-unification/templates-hierarchy.lisp 2014-03-26 04:18:29.000000000 +0000 @@ -231,70 +231,6 @@ (defgeneric make-template (kind spec)) -;;; Setting up the reader macro. - -;;; 20080711 MA: -;;; Reverted to the old version with MAKE-LOAD-FORM added. Template -;;; objects are created at read-time. - -(defun |sharp-T-reader| (stream subchar arg) - (declare (ignore subchar arg)) - (let ((spec (read stream t nil t))) - (typecase spec - (null (make-template nil spec)) - (cons (make-template (first spec) spec)) - (t (make-template spec spec))))) - -(defmethod make-load-form ((x template) &optional env) - (make-load-form-saving-slots x :environment env)) - - -#|| -;;; Version with more 'macro-like' behavior. The previous version -;;; created an object at read-time, which may cause problems with -;;; MAKE-LOAD-FORMs, constant-ness etc etc. -;;; -;;; 20080713 MA -;;; Removed because it was not working well with nested templates. -;;; Reverted to the original one plus MAKE-LOAD-FORM. - -(defun |sharp-T-reader| (stream subchar arg) - (declare (ignore subchar arg)) - (let ((spec (read stream t nil t))) - (typecase spec - (null `(make-template nil ',spec)) - (cons `(make-template ',(first spec) ',spec)) - (t `(make-template ',spec ',spec))) - )) -||# - -(eval-when (:load-toplevel :execute) - (set-dispatch-macro-character #\# #\T '|sharp-T-reader|)) - - -#|| Useless with the read time templates and MAKE-LOAD-FORM. - -(defun rewrite-template-spec (spec) - "Rewrites a template specification. -The rewriting simply makes sure that sub-templates are created as needed. -The result is either the SPEC itself or an appropriate call to LIST." - - (typecase spec - (atom `',spec) - (cons (destructuring-bind (head &rest tail) - spec - (case head - (quote spec) - (make-template `(make-template ,(first tail) - ,(rewrite-template-spec (second (second tail))))) - (t `(list ',head ,@(mapcar #'rewrite-template-spec tail))) - ))) - (t `',spec))) - -||# - - - (defmethod make-template ((kind null) (spec symbol)) (assert (null spec) (spec) "MAKE-TEMPLATE called erroneously with ~S and ~S." kind spec) (make-instance 'nil-template :spec spec)) diff -rN -u old-cl-unification/unification-package.lisp new-cl-unification/unification-package.lisp --- old-cl-unification/unification-package.lisp 2014-03-26 04:18:29.000000000 +0000 +++ new-cl-unification/unification-package.lisp 2014-03-26 04:18:29.000000000 +0000 @@ -16,6 +16,7 @@ The package also has the \"UNIFY\" nickname.") (:export + "ENABLE-TEMPLATE-READER" "MAKE-TEMPLATE" "TEMPLATEP" "TEMPLATE-SPEC")