Macro wrapped define-record-type renames field accessors

Create issue
Issue #241 invalid
Takashi Kato repo owner created an issue

This should work and return v but raises an error

(import (rnrs))
(define-syntax define-single-valued-token
  (syntax-rules ()
    ((_ name)
     (define-record-type name
       (fields value)))))

(define-single-valued-token t)

(define v (make-t 'v))
(t-value v)

The error

Unhandled exception
  Condition components:
  1. &undefined
  2. &who t-value
  3. &message unbound variable t-value in library user
  4. &stack-trace

stack trace:
  [1] #f
    src: (t-value v)
    "test2.scm":9
  [2] eval
  [3] main-loop
  [4] dynamic-wind
  [5] script

Comments (1)

  1. Takashi Kato reporter

    After looking at the issue, this is proper behaviour as macro expansion. The value is not bound in the same context, thus the identifier must be renamed. To make this work, the field must be passed.

    Also, Racket (plt-r6rs) raises an error as well due to the unbound identifier of t-value.

  2. Log in to comment