
24 Jun
2004
24 Jun
'04
2:50 p.m.
;;; 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))) ,@body)))) (with-c++-semantics (stdout *standard-output*) (shiftf stdout "Hello World!"))