[Small-cl-src] Abusing shift operations for fun and profit...

Ingvar ingvar at cathouse.bofh.se
Thu Jun 24 14:50:46 UTC 2004


;;; This is a creative abuse of symbol-macros
;;; Inspired by the question:
;;;   How do you do:
;;;    stdout << "Hi" << endl;
;;;   in lisp?
(defpackage "EVILHACK"
  (:use "CL"))
(in-package "EVILHACK")

(defclass c++-stream ()
  ((thestream :reader thestream :initarg :thestream)))

(defmethod (setf thestream) (new-value (obj c++-stream))
  (print new-value (thestream obj))
  obj)

(defmacro with-c++-semantics ((streamvar stream) &body body)
  (let ((cpstream (gensym)))
    `(let ((,cpstream (make-instance 'c++-stream :thestream ,stream)))
       (symbol-macrolet ((,streamvar (thestream ,cpstream)))
	 , at body))))

(with-c++-semantics (stdout *standard-output*)
  (shiftf stdout "Hello World!"))






More information about the Small-cl-src mailing list