(define-module (starlet colours) #:use-module (oop goops) #:export ( make-colour-cmy make-colour-rgb colour-as-cmy white)) (define-class () (type #:init-form (error "Colour type must be specified") #:init-keyword #:type #:getter colour-type) (value #:init-form (error "Colour value must be specified") #:init-keyword #:value #:getter colour-value)) (define cyan car) (define magenta cadr) (define yellow caddr) (define-method (display (col ) port) (format port "#< ~a ~a>" (colour-type col) (colour-value col))) (define-method (write (col ) port) (let ((cmy (colour-as-cmy col))) (format port "(make-colour-cmy ~a ~a ~a)" (cyan cmy) (magenta cmy) (yellow cmy)))) (define (make-colour-cmy c m y) (make #:type 'cmy #:value (list c m y))) (define (make-colour-rgb r g b) (make #:type 'rgb #:value (list r g b))) (define white (make-colour-cmy 0 0 0)) (define (colour-as-cmy col) (colour-value col))