Can compiler macros make use of type declarations?

Chaitanya Gupta mail at chaitanyagupta.com
Thu Nov 9 08:18:11 UTC 2017


So thanks to the replies on this I now know that most of the popular
Lisps do support inspecting the environment to figure out declared
types.

But what about inferred types (e.g. in CMUCL, SBCL)? Do these Lisps
provide a way to know the inferred type of a variable if no
declaration was made explicitly?

Chaitanya

On 7 November 2017 at 02:13, Chaitanya Gupta <mail at chaitanyagupta.com> wrote:
> Let's say I have created a function called `FOO`:
>
> (defun foo (x)
>   ...)
>
> To optimize this function, I write a compiler macro. Can I make use of
> type declarations that users of `FOO` might have made for the argument
> `X` that is passed in to it?
>
> That is, let's say `FOO` is used like this:
>
> (let ((a (something-that-returns-an-integer)))
>   (declare (integer a))
>   (foo a))
>
> The compiler macro for `FOO` cannot make any optimizations on the
> value of `A`, but can it take advantage of the fact that `A` is
> declared as in `INTEGER` here?
>
> Chaitanya



More information about the pro mailing list