-
Notifications
You must be signed in to change notification settings - Fork 3
/
identifiers.rkt
58 lines (46 loc) · 1.88 KB
/
identifiers.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#lang typed/racket
(require (for-syntax racket/syntax))
(define-syntax-rule (provide-id id)
(begin
(define-syntax (id stx)
(raise-syntax-error 'id
(format "Type expander form “~a” cannot be used as an expression"
'id)
stx))
(provide id)))
(define-syntax-rule (provide-ids id ...) (begin (provide-id id) ...))
(provide-ids Let Letrec Λ ...* No-Expand)
;; Define a mutable implementation for new-:, circumvent the fact that
;; typed/racket wraps macros with a contract.
;;
;; Technique from:
;;
;; https://github.com/racket/typed-racket/issues/329#issuecomment-205060192
(define-syntax (provide-mutable-id stx)
(syntax-case stx ()
[(_ short-id)
(with-syntax ([id (format-id #'short-id "new-~a" #'short-id)]
[id-set-impl (format-id #'short-id
"set-~a-impl!"
#'short-id)])
#'(begin
(provide id id-set-impl)
(define-for-syntax (id-impl-orig stx)
(raise-syntax-error ':
(format "Implementation for ~a was not loaded!"
'short-id)
stx))
(define-for-syntax id-impl (box id-impl-orig))
(define-syntax (id stx)
((unbox id-impl) stx))
(define-syntax-rule (id-set-impl impl)
(begin-for-syntax
(when (eq? (unbox id-impl) id-impl-orig)
(set-box! id-impl impl))))))]))
(define-syntax-rule (provide-mutable-ids id ...)
(begin (provide-mutable-id id) ...))
(provide-mutable-ids :
;; The class-related IDs need to also work as types.
;field
;super-new
)