I had used cl-ppcre package recently and I am very curious about how they optimize this package because I want to learn optimizing common lisp. I notice they use Sharpsign Dot a lot in declare expression, like here. The optimized setting is here.
Why do they write like this? Is there any benefit? Or some rule has them to do?
Update: I run
(defvar *b* '(optimize speed))
(pprint (macroexpand-1 '(declaim *b*)))
(pprint (macroexpand-1 '(declaim #.*b*))) ;; => this one is right
So, #.
will eval value even before macro call? Like it eval the value first and replaces it in the macro argument.
Sharpsign Dot will evaluate the next expression at read time. Thus it will act as the reader got fed the result and the other levels of CL don't know this. Macros that rely on literals cannot be made dynamic because of the evaluation rules so s read time macro will circumvent that and make it as the dynamic expression was literal for the other levels than the reader.
The benefit is an extra level of meta programming.
See the difference:
CL-USER 7 > (defvar *answer* 42)
*ANSWER*
CL-USER 8 > '(*answer* #.*answer*)
(*ANSWER* 42)
#.
allows expressions to be evaluated at read-time. The result will be returned from the reader - instead of the original expression.
CL-USER 9 > '(*answer* (* #.*answer* pi) #.(* pi *answer*))
(*ANSWER* (* 42 PI) 131.94689145077132D0)
Note that the value of *answer*
needs to be known at read-time to make this work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With