
Harnon wrote:Thx![]()
But i still don't understand exactly how to shadow the function name with the compiler-macro.
Looking at the documentation, it appears you have to (funcall (compiler-macro-function 'name) (name args) nil)
where name is the name of the compiler-macro. If i define a function with the same name, the function will always be used I also tried (setf (symbol-function 'name) (compiler-macro-function 'name)), but this doesn't work...
it appears to always want 2 args even if i only define it with one.
(define-compiler-macro fib (n &whole w)
(if (integerp n)
;Compute the nth fib. number
w))
makia wrote:hmm, but how you have such info at compile time ?
qbg wrote:Then when you compile functions that call FIB with an integer literal ...
(invoke array :insert-object thing :at-index position)
(invoke-by-name array (selector '(:insert-object :at-index)) thing position)
(define-compiler-macro selector (&whole form method-name)
(if (constantp method-name)
(selector-load-time-form (eval method-name))
form))
(defun selector-load-time-form (method-name)
`(load-time-value (handler-case
(find-selector ',method-name)
(serious-condition ()
(warn
(make-condition 'simple-style-warning
:format-control
"~S designates an unknown ~
method selector."
:format-arguments
(list ',method-name)))
',method-name))))
(defun selector-load-time-form (method-name)
`(load-time-value (find-selector ',method-name)))
makia wrote:... but then there is no huge impact in real programs ...?
(defun m* (matrix-1 matrix-2 &optional target)
(if (null target)
(setf target (make-matrix-of-right-size))
; blas call to multiply matrix-1 by matrix-2 and save to target
)
(defun m+ (matrix-1 matrix-2 &optional target)
(if (null target)
(setf target (make-matrix-of-right-size))
; blas call to add matrix-1 by matrix-2 and save to target
)
(define-compiler-macro m+ (matrix-1 matrix-2 &optional target)
(when (and (null target) (listp matrix-2) (eq (car matrix-2) m*))
`(let ((m2 ,matrix-2))
(m+ ,matrix-1 m2 m2))))
Users browsing this forum: No registered users and 10 guests