Hi,
I was wondering if there is something equivalent to ftype for macros. I need to produce a highly optimized piece of code and I'm using macros.
According to CLHS, ftype only works for functions. Is there any way to declare the type a macro will return?
Regards,
Luis.
declaring macros returning type
Re: declaring macros returning type
AFAIK a macro returns no type. A macro returns a piece of Lisp code, which will be evaluated, an then the evaluated Lisp code will return a value of some type. So either the macro must produce the declaration:
will expand to:
Or use THE if there's no other way:
will expand to:
HTH - edgar
Code: Select all
(defmacro one ()
'(let ((number 1))
(declare (fixnum number))
number))
(defun return-one ()
(one))
Code: Select all
(defun return-one ()
(let ((number 1))
(declare (fixnum number))
number))
Code: Select all
(defmacro one () '1)
(defun return-one ()
(the fixnum (one)))
Code: Select all
(defun return-one ()
(the fixnum 1))
Re: declaring macros returning type
Hi,
Thank you very much for your answer. You are right when you say that macros return no type. Sorry for my poor explanation. I was referring to the type of the final expression evaluated within the macro. From your examples I'm assuming that including the type declaration inside the macro will do and, therefore, any piece of code calling that macro can get the information about the type from such declaration.
Regards,
Luis.
Thank you very much for your answer. You are right when you say that macros return no type. Sorry for my poor explanation. I was referring to the type of the final expression evaluated within the macro. From your examples I'm assuming that including the type declaration inside the macro will do and, therefore, any piece of code calling that macro can get the information about the type from such declaration.
Regards,
Luis.
Re: declaring macros returning type
I assumed you know thislrodrig wrote:...Sorry for my poor explanation...

Usually one uses declarations to speed-up the compiled code at run-time, not to speed-up the compiling of the code. There may be exceptions, if parts of the the code are intended to compile at run-time, e.g. using Lisp for compiling an "embedded" programming language, but that's a very special case.
Macro-expansion happens at compile-time. During macro-expansion types don't matter much because the compiler compiles the expanded macro code, not the macro definition. This means that for run-time speed it's only important that in the expanded macro code all type declarations are at the correct places.
- edgar