LINUX.ORG.RU

История изменений

Исправление staseg, (текущая версия) :

В общем, если (function) дешевая, у меня сразу был такой вариант. На SBCL не могу проверить.

(defun mkstr (&rest args)
 (with-output-to-string (s)
   (dolist (x args) (princ x s))))

(let ((cache (make-hash-table)))
 (defmacro make-fun ((&rest args) &rest body)
  (let ((name (intern (mkstr (list args body)))))
   (if (gethash name cache)
       `(function ,name)
       (progn
	(setf (gethash name cache) t)
	`(defun ,name ,args ,@body))))))

UPD. В Clozecl работает через -load/(compile-file). Замыкания работают.

Исходная версия staseg, :

В общем, если (function) дешевая, у меня сразу был такой вариант. На SBCL не могу проверить.

(defun mkstr (&rest args)
 (with-output-to-string (s)
   (dolist (x args) (princ x s))))

(let ((cache (make-hash-table)))
 (defmacro make-fun ((&rest args) &rest body)
  (let ((name (intern (mkstr (list args body)))))
   (if (gethash name cache)
       `(function ,name)
       (progn
	(setf (gethash name cache) t)
	`(defun ,name ,args ,@body))))))