-
Notifications
You must be signed in to change notification settings - Fork 0
/
concrete-domain.rkt
114 lines (109 loc) · 3.72 KB
/
concrete-domain.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
; MIT License
;
; Copyright (c) 2016 Vincent Nys
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
; furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
#lang at-exp racket
(require racket/serialize
racket/struct
scribble/srcdoc)
(require (for-doc scribble/manual))
(serializable-struct
variable (name)
#:methods
gen:equal+hash
[(define (equal-proc v1 v2 equal?-recur)
(equal?-recur (variable-name v1) (variable-name v2)))
(define (hash-proc my-variable hash-recur)
(hash-recur (variable-name my-variable)))
(define (hash2-proc my-variable hash2-recur)
(hash2-recur (variable-name my-variable)))]
#:methods
gen:custom-write
[(define write-proc
(make-constructor-style-printer
(λ (obj) 'variable)
(λ (obj) (list (variable-name obj)))))])
(provide
(struct*-doc
variable
([name symbol?])
@{A variable in the concrete domain.}))
(serializable-struct
function (functor args)
#:methods
gen:equal+hash
[(define (equal-proc f1 f2 equal?-recur)
(and (equal?-recur (function-functor f1) (function-functor f2))
(equal?-recur (function-args f1) (function-args f2))))
(define (hash-proc my-function hash-recur)
(+ (hash-recur (function-functor my-function))
(* 3 (hash-recur (function-args my-function)))))
(define (hash2-proc my-function hash2-recur)
(+ (hash2-recur (function-functor my-function))
(hash2-recur (function-args my-function))))]
#:methods
gen:custom-write
[(define write-proc
(make-constructor-style-printer
(λ (obj) 'function)
(λ (obj) (list (function-functor obj)
(function-args obj)))))])
(provide
(struct*-doc
function
([functor symbol?] [args (listof term?)])
@{A function in the concrete domain.}))
(define (term? t)
(or (variable? t) (function? t)))
(provide term?)
(serializable-struct
atom (symbol args)
#:methods
gen:equal+hash
[(define (equal-proc a1 a2 equal?-recur)
(and (equal?-recur (atom-symbol a1) (atom-symbol a2))
(equal?-recur (atom-args a1) (atom-args a2))))
(define (hash-proc my-atom hash-recur)
(+ (hash-recur (atom-symbol my-atom))
(* 3 (hash-recur (atom-args my-atom)))))
(define (hash2-proc my-atom hash2-recur)
(+ (hash2-recur (atom-symbol my-atom))
(hash2-recur (atom-args my-atom))))]
#:methods
gen:custom-write
[(define write-proc
(make-constructor-style-printer
(λ (obj) 'atom)
(λ (obj) (list (atom-symbol obj) (atom-args obj)))))])
(provide
(struct*-doc
atom
([symbol symbol?] [args (listof term?)])
@{An atom in the concrete domain.}))
(define (concrete-domain-elem? elem)
(or (term? elem)
(atom? elem)
((listof atom?) elem)))
(provide
(proc-doc/names
concrete-domain-elem?
(-> any/c boolean?)
(val)
@{Test whether @racket[val] is an element of the concrete domain.}))