>>>> "Holger" == Holger Schauer
<schauer(a)coling.uni-freiburg.de> writes:
Holger> ;; The following snippet behave differently whether
Holger> ;; compiled or interpreted (i.e. evaluated at top-level)
Holger> (setq gee 23)
Holger> (format t "gee => ~d~%" gee)
Holger> (defmacro fun ()
Holger> gee)
Holger> (format t "(fun) => ~d~%"
Holger> (fun))
Holger> (defun baz ()
Holger> (fun))
Holger> (format t "(baz) => ~d~%"
Holger> (baz))
Holger> (setq gee 42)
Holger> (format t "(setq gee 42)~%")
Holger> (format t "(fun) => ~d~%" (fun))
Holger> (format t "(baz) => ~d~%"
Holger> (baz))
Holger> Michael, in Scheme, to which values would baz and fun evaluate ?
First, the code:
(define gee 23) ; (1)
(display "gee => ") (display gee) (newline)
(define-syntax fun
(syntax-rules ()
((fun) gee))) ; this always refers to the binding established in (1)
(display "(fun) => ") (display (fun)) (newline)
(define (baz) ; note that the expansion of (fun) refers to the
(fun)) ; of (1)
(display "(baz) => ") (display (baz)) (newline)
(set! gee 42) ; same binding, different value from now on
(display "(set! gee 42)") (newline)
(display "(fun) => ") (display (fun)) (newline)
(display "(baz) => ") (display (baz)) (newline)
Output:
gee => 23
(fun) => 23
(baz) => 23
(set! gee 42)
(fun) => 42
(baz) => 42
Note this is identical to the behavior of the code if you replace the
definition of fun by
(define (fun) gee)
--
Cheers =8-} Chipsy
Friede, Völkerverständigung und überhaupt blabla