Functional define-record à la Tuplanolla added by DerGuteMoritz on Sat Apr 5 16:39:50 2014

(import-for-syntax matchable)

(define-syntax define-record
  (ir-macro-transformer
   (lambda (x i c)
     (match x
       ((_ record
           (make-record xs ...)
           record?
           (and (x record-x record-with-x)
                record-fields) ...)
        `(begin
           (define-record-type ,record
             (,make-record ,@xs)
             ,record?
             ,@record-fields)
           ,@(map (lambda (record-with-x* record-x*)
                    `(define (,record-with-x* r y)
                       (,make-record
                        ,@(map (lambda (record-x**)
                                 (if (eq? record-x* record-x**)
                                     'y
                                     `(,record-x** r)))
                               record-x))))
                  record-with-x
                  record-x)))))))