I don't know if I am clear in the title, but here me out. I have a package in which I bind *read-default-float-format* to 'double-float.
So far so good. When I load the library into fresh SBCL process in terminal, it works: I can read floats in double format. However, when I connect from Sly and switch to the package in repl, than I get an error:
The value
1.0
is not of type
DOUBLE-FLOAT
when binding INVISTRA::VALUE
[Condition of type TYPE-ERROR]
Is this because Slynk run in another thread?
I have tried, and would prefer to just let-bind over the function which needs to perform calculations with double precision, not for the entire process, but it is not a deal-breaker if I have to set it for the entire process. This is what I would like to achieve:
(in-package #:invistra)
#+sbcl
(declaim
(sb-ext:disable-package-locks *read-default-float-format*))
(defun ensure-symbol (name &optional (package *package*))
(intern (string name) package))
(defmacro define-interface ((client-var client-class &optional intrinsic) &body body)
(declare (ignore client-class))
(let* ((intrinsic-pkg (if intrinsic (find-package '#:common-lisp) *package*))
(format-func (ensure-symbol '#:format intrinsic-pkg))
(initialize-func (ensure-symbol '#:initialize-invistra))
(*read-default-float-format* 'double-float))
`(progn
(defun ,format-func (control-string &rest args)
(apply #'format ,client-var control-string args))
(defmacro ,(ensure-symbol '#:formatter intrinsic-pkg) (control-string)
(formatter ,client-var control-string))
(define-compiler-macro ,format-func (&whole form control-string &rest args)
(format-compiler-macro ,client-var form control-string args))
(defun ,initialize-func ()
,@body))))
That does not work at all :-), but Setf-ing the *read-default-float-format* does. However, I have to set it again when I connect from Slynk.
What do I miss here, and how do I make it to work?
(For the info: it's a fork of Invistra which I have adapted to implement a similar format function; haven't changed any names yet).
Edit:
My personal solution, after the info from @coredump is to start SBCL with --eval flag and tell it which double format to use:
sbcl --noinform --eval "(setq *read-default-float-format* 'double-float)"
Seems to work well for my use case.
sb-ext:disable-package-lockslooks like a code smell to me, is it necessary? I don't see whyinitialize-invistrashould ever be added to the Common Lisp package