Re: pi seems not to be a constant
[email protected] (Don Cohen)
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
> If long-float-digits is changed and the "constants" are not adjusted > then STANDARD PORTABLE CL code will break. This is incomplete: Not only the constants should be adjusted, but all the standard portable CL code that has been compiled so far needs to be compiled again, because defconstant constants can be inlined. This is to avoid having to recompile and reload everything each time you set ext:long-float-digits, that cl:pi is not a constant. If I understand correctly, you are saying that *If* pi, etc. were declared defconstant and changing precision changed it, then everything using pi would have to be recompiled. And depending on what you think it means to change precision, you might also want to reread and recompile all the code containing long constants. I think you agree with me that it's a bad idea to change the values of things that are declared defconstant. I can't tell whether you think pi should not be defconstant because of this, or whether you agree with me that it should be declared defconstant and then not changed. And it should be noted, that if you keep modifying long-float-digits, you can have in the image, and still use and combine in expressions, long-float values of different precisions. The user shall know what he's doing. But for values like pi or e, you definitely want to provide the value in the new (or best) precision. This sounds like you want to change the value of pi. But maybe you're willing to accept my version of "provide the value in the new (or best) precision", which is that (pi) returns the value in the current precision and (pi n) returns the value in precision n, and similar functions are supplied for all the other defconstants. Then you can write code that changes its behavior in response to changing precision. This doesn't solve the larger problem of constants in code. You probably don't want to replace 1l0 in your code with (read-from-string "1l0"), at leat if that code is to run many times. It's possible to write a macro (adjust-precision "1l0") that generates code that checks whether precision has been changed since it was last run (I hope that's cheap) and if so rereads the constant. It could even keep a cache of values of different precisions. While we're at it, I suggest that it would be a lot more convenient to programmatically control precision if there were a function to read long floats of precision n, e.g., (read-long "1l0" n), which returns the rough equivalent (I hope much more efficiently) of (let ((p (ext:long-float-digits))) (setf (ext:long-float-digits) n) (prog1 (read-from-string "1l0") (setf (ext:long-float-digits) p))) It would also be nice if different threads could work in different default precisions. For this purpose it seems better to make long-float-digits a regular special variable that can be rebound by any code and only affect the reads that are done with that binding. Of course, I don't propose that pi be changed or even rebound when long-float-digits is rebound. But the rebinding will affect the value of (pi). So now I'm proposing somewhat larger changes, but I think they make the resulting system quite a bit more useful. The underlying clisp seems perfectly well adapted to using different precisions under program control, but this facility is made unnecessarily inconvenient to use, in my opinion, by the current mechanism of (setf long-float-digits) and its adjustments, along with the lack of the read-long function and the functions like (pi &optional precision). ------------------------------------------------------------------------------ _______________________________________________ clisp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-list