From d2be7e3c4ba8d6d0dde9b4c0bff623ab85637424 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 29 Mar 2019 22:40:55 +0100 Subject: records: Support custom 'this' identifiers. This lets record users choose an identifier other than 'this-record'. * guix/records.scm (make-syntactic-constructor): Add #:this-identifier. [wrap-field-value]: Honor it. (define-record-type*): Add form with extra THIS-IDENTIFIER and honor it. * tests/records.scm ("define-record-type* & thunked & inherit & custom this"): New test. --- tests/records.scm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests/records.scm') diff --git a/tests/records.scm b/tests/records.scm index 45614093a0..16b7a9c35e 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -210,6 +210,24 @@ (define-record-type* foo make-foo (= 40 (foo-bar z)) (= -2 (foo-baz z)))))) +(test-assert "define-record-type* & thunked & inherit & custom this" + (let () + (define-record-type* foo make-foo + foo? this-foo + (thing foo-thing (thunked))) + (define-record-type* bar make-bar + bar? this-bar + (baz bar-baz (thunked))) + + ;; Nest records and test the two self references. + (let* ((x (foo (thing (bar (baz (list this-bar this-foo)))))) + (y (foo-thing x))) + (match (bar-baz y) + ((first second) + (and (eq? second x) + (bar? first) + (eq? first y))))))) + (test-assert "define-record-type* & delayed" (begin (define-record-type* foo make-foo -- cgit v1.2.3