chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] Strange macro expansion


From: Jörg F . Wittenberger
Subject: [Chicken-hackers] Strange macro expansion
Date: 30 Jul 2013 20:10:58 +0200

;; Hi All,

;; This looks wrong to me.  I'd expect both tests to the same thing.

;; (Or am I doing something wrong here?)

;;

;; Just the 'foo', anything would do here.

(define-record-type foo
 (make-foo a b r)
 foo?
 (a foo-a set-foo-a!)
 (b foo-b set-foo-b!)
 (r foo-r set-foo-r!))

(define xx (make-foo 1 2 #f))

;; A different syntax: (set-slot 'X y) .  For X in {a,b} redirect to
;; set-foo-X! otherwise set-foo-r! .

(define-syntax set-slot!
 (syntax-rules (a b quote)
   ((_ foo 'a value) (set-foo-a! foo value))
   ((_ foo 'b value) (set-foo-b! foo value))
   ((_ foo 'slot value)
    (let ((v value))
      (if (memq 'slot '(a b))
           (error (format "Should Not Happen ~a ~a\n" 'slot v))
           (set-foo-r! foo v))))
   ))

;; ## 1st Test

(display "Can we \"set-foo-a!\" with \"a\" bound in global scrope ? If yes, '7' is printed\n")

(define a 7)
(set-slot! xx 'a a)

(print (foo-a xx))

;; Still running: that's the expected result.

;; ## 2nd Test

(display "Now try the same with \"b\" bound lexically\n")

(let ((b 6))
 (set-slot! xx 'b b))

;; Ups!  That ran into "Should Not Happen"!

(display "Did we manage to \"set-foo-b!\"? If yes, '6' is printed\n")
(print (foo-b xx))

(exit 0)










;...........



reply via email to

[Prev in Thread] Current Thread [Next in Thread]