I want to be able to do something like this:
(struct point (x y))
(define p1 (point 1 2))
(define p2 (point 10 20))
(+ p1 p2) ; -> (point 11 22)
Is it possible to teach a struct like point
to work with built-in math operators like +
?
The docs seem to manage to implement custom (equal? ...)
handling in section 5.5 on this page. What I'm trying to do is quite similar ...
Or should I just define function like (point-add p1 p2)
?
add
function accept arbitrarily many arguments? With this implementation it is limited to 2 arguments ... – Arletha