Add applicable records
Fixes #267 (closed)
Merge request reports
Activity
added 2 commits
added 2 commits
added 2 commits
assigned to @wingo
- Resolved by David Thompson
- Resolved by David Thompson
- Resolved by David Thompson
added 10 commits
-
75419b80...27e8f942 - 8 commits from branch
main
- 4bb9a49f - Fix procedure-name.
- 20dcbb43 - Add applicable records.
-
75419b80...27e8f942 - 8 commits from branch
1902 Note that @code{<counter>} objects are recognized as both counters 1903 @emph{and} procedures! 1904 1905 @defvr {Variable} <applicable-record> 1906 The record type descriptor for applicable records. 1907 @end defvr 1908 1909 @deffn {Procedure} applicable-record? obj 1910 Return @code{#t} if @var{obj} is an applicable record. 1911 @end deffn 1912 1913 @deffn {Procedure} applicable-record-procedure obj 1914 Return the procedure stored within the applicable record @var{obj}. 1915 @end deffn 1916 1917 @deffn {Procedure} set-applicable-record-procedure! obj proc This field should be immutable. Read this rationale and think about it and it’ll be clear why
I sympathize with the desire to make things immutable, but we have use cases where it would be beneficial to change the procedure. I've been thinking of applicable records as a layer of indirection but I'd be curious if @wingo thinks there is much to gain from compiler optimization of known applicable record calls.
Edited by David ThompsonThen do something like this:
(define-record-type <my-applicable-thing> #:parent <applicable-record> (%make-applicable-thing base-proc real-proc blah) (real-proc applicable-thing-real-proc applicable-thing-real-proc-set!) (blah-field applicable-thing-blah applicable-thing-blah-set!)) (define (make-applicable-thing proc blah) (letrec ((thing (make-applicable-thing (lambda args (apply (applicable-thing-real-proc thing) args)) proc blah))) thing))
Then you can use
apply-applicable-thing-real-proc-set!
to change the behaviour when called.Making the standard applicable record field mutable, so that anyone who has an applicable record of any subtype can call
set-applicable-record-procedure!
on it and break the contract between the procedure and the fields of the record, sacrifices security and optimizability for everyone for the sake of the cases that need something different, even though this way shows it is possible even without making that sacrifice. With this way, you can control who is allowed to change the procedure by controlling the scopes in which theapply-applicable-thing-real-proc-set!
identifier is available.Edited by Daphne Preston-Kendalchanged this line in version 21 of the diff
I didn't really want to force another layer of indirection. Either way, I don't love exposing the field setter and it seems we don't need the setter right now for porting Goblins to Hoot so I'm going to leave it out. I'm still unsure if applicable records should be made via subtyping or just using a flag like we already have with
#:extensible?
and#:opaque?
so I commented out the docs so we don't advertise an API we haven't settled on yet.
added goblins label
added 6 commits
-
f389546d...41bb9ebd - 4 commits from branch
main
- f74a8c69 - Fix procedure-name.
- f147a1e2 - Add applicable records.
-
f389546d...41bb9ebd - 4 commits from branch
added 5 commits
-
f147a1e2...527492f9 - 3 commits from branch
main
- 9b832ee3 - Fix procedure-name.
- 177ae3f1 - Add applicable records.
-
f147a1e2...527492f9 - 3 commits from branch
added 8 commits
-
177ae3f1...107ce7e1 - 6 commits from branch
main
- c9928e9a - Fix procedure-name.
- f47f53dd - Add applicable records.
-
177ae3f1...107ce7e1 - 6 commits from branch
added 12 commits
-
f47f53dd...61c07243 - 10 commits from branch
main
- 60624735 - Fix procedure-name.
- 0463c949 - Add applicable records.
-
f47f53dd...61c07243 - 10 commits from branch
added 6 commits
-
0463c949...799bf3b0 - 4 commits from branch
main
- e7000a62 - Fix procedure-name.
- 56eb9cc1 - Add applicable records.
-
0463c949...799bf3b0 - 4 commits from branch
added 2 commits
added 5 commits
-
fd0a529c...dcc0bd46 - 4 commits from branch
main
- 6dba04a2 - Add applicable records.
-
fd0a529c...dcc0bd46 - 4 commits from branch
mentioned in commit 4f7a07c1