[racket] struct and when the accessors are bound

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Wed Jul 16 13:32:34 EDT 2014

It could be made to work, but it currently doesn't because make-struct-type returns 5 functions, one of which is an index-based reference function. If struct were to produce the accessor identifiers in the same define-values as the defined make-struct-type identifiers, this would work. I can make a PR to fix this.
-Ian
----- Original Message -----
From: "Alexander D. Knauth" <alexander at knauth.org>
To: "racket users list" <users at racket-lang.org>
Sent: Wednesday, July 16, 2014 10:44:24 AM GMT -05:00 US/Canada Eastern
Subject: [racket] struct and when the accessors are bound

If I have a program like this:
#lang racket/base
(define-values (prop:p p? p-ref)
  (make-struct-type-property 'p))
(struct foo (a) #:transparent
  #:property prop:p foo-a)
It gives me this error:
. foo-a: undefined;
 cannot reference an identifier before its definition

Is there a reason why I can’t do this?

And is there any way to get around this other than wrapping foo-a in a lambda?

I know that this works:
#lang racket/base
(define-values (prop:p p? p-ref)
  (make-struct-type-property 'p))
(struct foo (a) #:transparent
  #:property prop:p (λ (x) (foo-a x)))

And I know that it’s not that bad, but is there any other way around it?


____________________
  Racket Users list:
  http://lists.racket-lang.org/users


Posted on the users mailing list.