[Small-cl-src] apply in terms of funcall

Andreas Fuchs asf at boinkor.net
Sat May 15 11:42:57 UTC 2004


;;; A few months ago, there was a thread about FUNCALL and APPLY on
;;; c.l.l. I wrote this code to show how APPLY might be defined in
;;; terms of FUNCALL.

(defun apply-definer (max-args)
  `(defun my-apply (f &rest args)
     (case (length args)
       ,@(loop for arg-count from 0 to max-args
	       collect `((,arg-count)
			 (funcall
			   f
			   ,@(loop for arg-idx from 0 to (1- arg-count)
				   collect `(nth ,arg-idx args)))))
       (otherwise
	(error ,(format nil "Can't apply to more than ~A args" max-args))))))

(defmacro define-apply (max-args)
  (apply-definer (etypecase max-args
		   (symbol (symbol-value max-args))
		   (number max-args))))

(apply-definer call-arguments-limit)

;;; License: BSD-sans-advertising.

-- 
Andreas Fuchs, <asf at boinkor.net>, asf at jabber.at, antifuchs




More information about the Small-cl-src mailing list