KRC
KRC

Reputation: 328

scheme/racket super-type and accessing struct properties

How do i access the layer property of r, and where does the 1 go? And i can only access the 2 and 3 using point-x and point-y, even though it's a common-value struct..

#lang racket

(define (object-constructor super-type layer)
  (struct commmon-value(layer)
    #:super super-type
    #:transparent
    #:property prop:procedure (lambda (self)
                                           layer))
  comm)

(struct point (x y) 
  #:transparent
  #:property prop:procedure (lambda (self)
                                      x y)))

(define r ((object-constructor struct:point 1) 2 3 4))
(point-x r)
(point-y r)
r
> (comm 2 3 4)

Upvotes: 1

Views: 277

Answers (1)

soegaard
soegaard

Reputation: 31147

#lang racket

(struct layer (common) 
  #:transparent
  #:property prop:procedure (lambda (self) (layer-common self)))

(struct point layer (x y) 
  #:transparent
  #:property prop:procedure (lambda (self) (layer-common self)))

(define r (point 1 2 3))
(match-define (point c x y) r)

(r)
c
x 
y

The ouput is:

1
1
2
3

Upvotes: 1

Related Questions