[CM] Unexpected behavior of record types in lists

bil at ccrma.Stanford.EDU bil at ccrma.Stanford.EDU
Tue May 17 06:26:33 PDT 2022


Thanks for the bug report.  I think that was an
overlooked name collision in the macro.  I
haven't tested this much, but here's a possible
new version:

(define-macro (define-record-type type make ? . fields)
   (let ((obj (gensym))
	(typ (gensym))
	(args (map (lambda (field)
		     (values (list 'quote (car field))
			     (let ((par (memq (car field) (cdr make))))
			       (and (pair? par) (car par)))))
		   fields)))
     `(begin
        (define (,? ,obj)
	 (and (let? ,obj)
	      (eq? (let-ref ,obj ',typ) ',type)))

        (define ,make
          (inlet ',typ ',type , at args))

        ,@(map
	  (lambda (field)
	    (when (pair? field)
	      (if (null? (cdr field))
		  (values)
		  (if (null? (cddr field))
		      `(define (,(cadr field) ,obj)
			 (let-ref ,obj ',(car field)))
		      `(begin
			 (define (,(cadr field) ,obj)
			   (let-ref ,obj ',(car field)))
			 (define (,(caddr field) ,obj val)
			   (let-set! ,obj ',(car field) val)))))))
	  fields)
        ',type)))


More information about the Cmdist mailing list