I have a point record type defined as follows:
(define-record-type point
(make-point x y)
point?
(x point-x)
(y point-y)
)
Now, I want to extend the point record type and define a new record type as follows:
(define-record-type cpoint
(make-cpoint color)
cpoint?
(color cpoint-color)
(parent point)
)
When I run the above to definitions in the scheme shell everything works fine. I can construct point types properly. However, when I try to construct the cpoint type as follows:
(define p2 (make-cpoint 8 9 'red))
I get the following error:
; ...rfi/9/record.rkt:100:28: arity mismatch;; the expected number of arguments does not match the given number; expected: 1; given: 3; [,bt for context]
I thought since cpoint is child of point, it should have accepted the arguments to the point type in its constructor.
How can I make this work?
P.S I am new to Scheme.
There are no child records in SRFI-9. Thus you need to specify them independently:
Thus the accessors to get
xandyforcpointandpointare different.Alternatives that has parents
In R6RS you have
(rnrs records syntactic (6))which is similar to SRFI-9, but not compatible. Your code would look like:You have tagged Racket and if you are using the default language,
#lang racket, they havestruct:I added
#:transparentsince it is the default in R6RS. Of you really want the constructor name to bemake-xxxyou need to specify it: