[racket] struct and when the accessors are bound

From: J. Ian Johnson (ianj at ccs.neu.edu)
Date: Wed Jul 16 15:30:56 EDT 2014

Scratch that, it uses make-struct-field-accessor to make the accessor, which I can't unroll under a lambda before the make-struct-type. I would rather not local-expand, look for field accessors in the free variables and introduce an eta-expanded version in that case due to the hidden complexity.

If make-struct-field-accessor weren't a #%kernel function, perhaps it would be doable.
-Ian
----- Original Message -----
From: "J. Ian Johnson" <ianj at ccs.neu.edu>
To: "Alexander D. Knauth" <alexander at knauth.org>
Cc: "racket users list" <users at racket-lang.org>
Sent: Wednesday, July 16, 2014 1:32:34 PM GMT -05:00 US/Canada Eastern
Subject: Re: [racket] struct and when the accessors are bound

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

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


Posted on the users mailing list.