Schemer
Schemer

Reputation: 1665

Racket/Scheme: working with structs

I have been given a struct to work with:

(struct Binding (id (value #:mutable)))

This struct represents a variable binding such as (set! x 3) where I would expect id = x and value = 3.

How do I create and initialize this struct? How do I get the values of id and value and to set the value of value?

Upvotes: 1

Views: 3346

Answers (1)

Eli Barzilay
Eli Barzilay

Reputation: 29546

> (struct Binding (id (value #:mutable)))
> (define b (Binding 'x 123))
> (Binding-id b)
'x
> (Binding-value b)
123
> (set-Binding-value! b 456)
> (Binding-value b)
456

(See also the documentation page on structs.)

Upvotes: 4

Related Questions