I have some lisp source files that contain some (many) floating point numbers. How can I use asdf to ensure these files are read using (setf *read-default-float-format* 'double-float) without setting *read-default-float-format* globally?
Thanks, BvdS
Brett van de Sande writes:
I have some lisp source files that contain some (many) floating point numbers. How can I use asdf to ensure these files are read using (setf *read-default-float-format* 'double-float) without setting *read-default-float-format* globally?
One straightforward way to do this is to subclass CL-SOURCE-FILE and add :AROUND methods for OPERATE that rebind *READ-DEFAULT-FLOAT-FORMAT*. Some systems do the analogous thing to rebind *READTABLE*, I believe.
Untested example below.
Regards, Richard
(defclass cl-source-file-with-read-float-format-rebinding (asdf:cl-source-file) ())
(defmethod operate :around ((o asdf:compile-op) (c cl-source-file-with-read-float-format-rebinding)) (let ((*read-default-float-format* 'double-float)) (call-next-method)))
(defmethod operate :around ((o asdf:load-op) (c cl-source-file-with-read-float-format-rebinding)) (let ((*read-default-float-format* 'double-float)) (call-next-method)))
(defmethod operate :around ((o asdf:load-source-op) (c cl-source-file-with-read-float-format-rebinding)) (let ((*read-default-float-format* 'double-float)) (call-next-method)))
Brett van de Sande wrote:
I have some lisp source files that contain some (many) floating point numbers. How can I use asdf to ensure these files are read using (setf *read-default-float-format* 'double-float) without setting *read-default-float-format* globally?
If you don't want this globally, but you want it for all of the files in your system, you could do something like
(defmethod asdf:perform :around ((op asdf:compile-op) (comp asdf:cl-source-file)) (let ((*read-default-float-format* 'double-float)) (call-next-method)))
I am not sure whether you need to do this for the load-op, as well.
If you want this to be done only for YOUR system, you could make a new subclass of cl-source-file (say "double-float-source-file"), attach the :around method to that, and then set up your system to have double-float-source-file as its default-component-class...
Note that these are very much off-the-cuff and not tested.