;;; -*- Mode:LISP; Package:USER; Base:10 -*-


;;; i thought there was a bug here, but there isnt...

(defmacro with-funny-semantics (&body body)
  `(condition-bind (((si:undefined-function si:unbound-variable)
		     'funny-semantics-handler))
     ,@body))

(defun funny-semantics-handler (obj)
  (let ((symbol (send obj :symbol))
	(cell-type (send obj :cell-type)))
    (cond ((not symbol) nil)
	  ((eq :function cell-type)
	   (values :new-value (make-funny-function-trampoline symbol)))
	  ((eq :value cell-type)
	   (values :new-value symbol)))))

(defun make-funny-function-trampoline (symbol)
  #'(lambda (&rest argument-list)
      (cons symbol (copy-list argument-list))))

