2

I can access a class field by defining a method so (send joe get-name) will return me Joe. But can I get the same behavior without adding a method and just by calling a field, like this: (send joe name)?

#lang racket

(define person%
  (class object%
    (init-field name)
    (super-new)
    (define/public (get-name) name) ))

(define joe (new person% [name 'Joe]))
Aliaksandr Sushkevich
  • 11,550
  • 7
  • 37
  • 44

1 Answers1

1

I think you're looking for get-field.

Example of usage: (get-field name joe)

Let me know if I've misunderstood your question.

Aliaksandr Sushkevich
  • 11,550
  • 7
  • 37
  • 44
John Clements
  • 16,895
  • 3
  • 37
  • 52