- changed status to resolved
Accessors of generated field of define-record-type don't point proper field
Issue #188
resolved
From R7RS-large (WG2) group:
(import (scheme base) (scheme write))
(define-syntax define-tuple-type
(syntax-rules ()
((define-tuple-type name make pred x->vec (defaults ...))
(deftuple name (make) pred x->vec (defaults ...) (defaults ...) ()))))
(define-syntax deftuple
(syntax-rules ()
((deftuple name (make args ...) pred x->vec defaults (default . rest)
(fields ...))
(deftuple name (make args ... tmp) pred x->vec defaults rest
(fields ... (tmp tmp))))
((deftuple name (make args ...) pred x->vec (defaults ...) ()
((field-name get) ...))
(begin
(define-record-type name (make-tmp args ...) pred
(field-name get) ...)
(define (make . o)
(if (pair? o) (apply make-tmp o) (make-tmp defaults ...)))
(define (x->vec x)
(vector (get x) ...))))))
(define-tuple-type point make-point point? point->vector (0 0))
(write (point->vector (make-point)))
(newline)
(write (point->vector (make-point 1 2)))
(newline)
This should print #(1 2)
but #(2 2)
. The reason why is because expanded form doesn't recognise the difference of identifier tmp
and just creates slot name tmp
. The solution would be:
- Making
record-accessor
generate a procedure which accessk
th slot without searching the name of the slot. - Making
define-record-type
to generate different field name so that underlying slot name can also be different.
Probably it's better to implement both of them since we don't check duplicate field names.
Comments (2)
-
reporter -
reporter Took option 1.
- Log in to comment
Accessing record field by index instead of class and slot name. (Fixes
#188)→ <<cset 256449f82111>>