aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/domain.spad.pamphlet
blob: 4d0cb784e3df7040a9b35038b37e8da022ed455d (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
\documentclass{article}
\usepackage{axiom}

\author{Gabriel Dos~Reis}

\begin{document}

\begin{abstract}
\end{abstract}

\tableofcontents
\eject

\section{The Constructor domain}

<<domain CTORKIND ConstructorKinid>>=
)abbrev domain CTORKIND ConstructorKind
++ Author: Gabriel Dos Reis
++ Date Create: October 07, 2008.
++ Date Last Updated: October 07, 2008.
++ Related Constructors: 
++ Description:
++   This domain enumerates the three kinds of constructors
++   available in OpenAxiom: category constructors, domain
++   constructors, and package constructors.
ConstructorKind(): Public == Private where
  Public == SetCategory with
    category: % ++ `category' is the kind of category constructors
    domain: %   ++ `domain' is the kind of domain constructors
    package: %  ++ `package' is the kind of package constructors.
  Private == add
    category == 'category : %
    domain == 'domain : %
    package == 'package : %
    k1 = k2 == EQ(k1,k2)$Lisp
    coerce(k: %): OutputForm == k : OutputForm
@

<<category CTORCAT ConstructorCategory>>=
import ConstructorKind
)abbrev category CTORCAT ConstructorCategory
++ Author: Gabriel Dos Reis
++ Date Create: December 17, 2008.
++ Date Last Updated: December 21, 2008.
++ Basic Operations: name, kind, arity.
++ Description:
++   This category declares basic operations on all constructors.
ConstructorCategory(): Category == OperatorCategory Identifier with
     kind: % -> ConstructorKind
       ++ kind(ctor) returns the kind of the constructor `ctor'.
     dualSignature: % -> List Boolean
       ++ dualSignature(c) returns a list l of Boolean values with 
       ++ the following meaning: 
       ++   l.(i+1) holds when the constructor takes a domain object
       ++           as the `i'th argument.  Otherwise the argument
       ++           must be a non-domain object.
  add
    kind x == getConstructorKind(x)$Lisp
    arity x == getConstructorArity(x)$Lisp
    dualSignature x == getDualSignatureFromDB(x)$Lisp
@


<<domain CTOR Constructor>>=
)abbrev domain CTOR Constructor
++ Author: Gabriel Dos Reis
++ Date Create: October 07, 2008.
++ Date Last Updated: December 17, 2008.
++ Related Constructors: Domain, Category
++ Basic Operations: name, kind, arity.
++ Description:
++   This domain provides implementations for constructors.
Constructor(): ConstructorCategory with
     findConstructor: Symbol -> Maybe %
       ++ \spad{findConstructor(s)} attempts to find a constructor
       ++ named \spad{s}.  If successful, returns that constructor;
       ++ otherwise, returns \spad{nothing}.
  == add
    Rep == Identifier
    name x == rep x
    kind x == getConstructorKind(x)$Lisp
    arity x == getConstructorArity(x)$Lisp
    findConstructor s ==
      isConstructorName(s)$Lisp => just per(s pretend Identifier)
      nothing
@


\section{domain ConstructorCall}

<<domain CTORCALL ConstructorCall>>=
import SetCategory
import Symbol
import List Syntax
)abbrev domain CTORCALL ConstructorCall
++ Author: Gabriel Dos Reis
++ Date Created: January 19, 2008
++ Date Last Updated: July 03, 2008
++ Description: This domains represents a syntax object that
++ designates a category, domain, or a package.
++ See Also: Syntax, Domain
ConstructorCall(): Public == Private where
  Public == SetCategory with
    constructor: % -> Constructor
      ++ constructor(t) returns the name of the constructor used
      ++ to make the call.
    arguments: % -> List Syntax
      ++ arguments(t) returns the list of syntax objects for the
      ++ arguments used to invoke the constructor.

  Private == add
    constructor x ==
      CAR(x)$Lisp

    arguments x ==
      CDR(x)$Lisp

    x = y ==
      EQUAL(x,y)$Lisp

    coerce(x: %): OutputForm ==
      outputDomainConstructor(x)$Lisp
@


<<domain CATCTOR CategoryConstructor>>=
)abbrev domain CATCTOR CategoryConstructor
++ Author: Gabriel Dos Reis
++ Date Create: December 17, 2008.
++ Date Last Updated: December 20, 2008.
++ Related Constructors: Domain, Category
++ Description:
++   This domain provides representations for category constructors.
CategoryConstructor(): Public == Private where
  Public == Join(ConstructorCategory, CoercibleTo Constructor)
  Private == Constructor add
    coerce(x: %): Constructor == rep x

@

<<domain DOMCTOR DomainConstructor>>=
)abbrev domain DOMCTOR DomainConstructor
++ Author: Gabriel Dos Reis
++ Date Create: December 17, 2008.
++ Date Last Updated: December 20, 2008.
++ Related Constructors: Domain, Category
++ Description:
++   This domain provides representations for domains constructors.
DomainConstructor(): Public == Private where
  Public == Join(ConstructorCategory, CoercibleTo Constructor)
  Private == Constructor add
    coerce(x: %): Constructor == rep x

@

\section{The Signature domain}

<<domain SIG Signature>>=
import List
import Syntax
)abbrev domain SIG Signature
++ Author: Gabriel Dos Reis
++ Date Created: January 10, 2008
++ Date Last Updated: December 20, 2008
++ Description: This is the datatype for operation signatures as
++   used by the compiler and the interpreter.  Note that this domain
++   differs from SignatureAst.
++ See also: ConstructorCall, Domain.
Signature(): Public == Private where
  Public == SetCategory with
    signature: (List Syntax,Syntax) -> %
      ++ signature(s,t) constructs a Signature object with parameter
      ++ types indicaded by `s', and return type indicated by `t'.
    target: % -> Syntax
      ++ target(s) returns the target type of the signature `s'.
    source: % -> List Syntax
      ++ source(s) returns the list of parameter types of `s'.
  Private == add
    Rep == List Syntax
    signature(s,t) == per cons(t,s)
    target x == first rep x
    source x == rest rep x
    x = y == rep x = rep y
    printType(x: Syntax): OutputForm ==
      x::InputForm::OutputForm
    coerce(x: %): OutputForm ==
      #source x = 1 =>
        rarrow(printType first source x, printType target x)
      rarrow(paren [printType s for s in source x],
         printType target x)$OutputForm
@

\section{A domain for operator signatures}

<<domain OPSIG OperatorSignature>>=
)abbrev domain OPSIG OperatorSignature
++ Author: Gabriel Dos Reis
++ Date Created: December 20, 2008
++ Date Last Modified: December 20, 2008
++ Description:
++   This the datatype for an operator-signature pair.
OperatorSignature(): Public == Private where
  Public == OperatorCategory Identifier with
    signature: % -> Signature
      ++ signature(x) returns the signature of `x'.
    construct: (Identifier,Signature) -> %
      ++ construct(op,sig) construct a signature-operator with
      ++ operator name `op', and signature `sig'.
  Private == add
    construct(o,s) == LIST(o,s)$Lisp
    name x == CAR(x)$Lisp
    signature x == CADR(x)$Lisp
    x = y == EQUAL(x,y)$Lisp
    arity x == (#source signature x)::Arity
    coerce(x: %): OutputForm ==
      infix('_:::OutputForm, name(x)::OutputForm, 
              signature(x)::OutputForm)

@

\section{The SystemPredicate domain}

<<domain SYSPRED SystemPredicate>>=
)abbrev domain SYSPRED SystemPredicate
SystemPredicate(): Public == Private where
  Public == SetCategory
  Private == add
    x = y == EQUAL(x,y)$Lisp
    coerce(x: %): OutputForm ==
      NOT(x)$Lisp => '_false::OutputForm
      EQ(x,'T)$Lisp => '_true::OutputForm
      EQCAR(x,'NOT)$Lisp => not(CADR(x)$Lisp : % :: OutputForm)
@


\section{domain Category}
<<domain CATEGORY Category>>=
import CoercibleTo OutputForm
import CategoryConstructor
)abbrev domain CATEGORY Category
++ Author: Gabriel Dos Reis
++ Date Create: December 20, 2008.
++ Date Last Updated: February 16, 2008.
++ Basic Operations: coerce
++ Related Constructors: 
++ Also See: Type
Category(): Public == Private where
  Public == CoercibleTo OutputForm with
    constructor: % -> CategoryConstructor
      ++ constructor(c) returns the category constructor used to 
      ++ instantiate the category object `c'.
    exportedOperators: % -> List OperatorSignature
      ++ exportedOperators(c) returns the list of all operator signatures
      ++ exported by the category `c', along with their predicates.
    principalAncestors: % -> List ConstructorCall
      ++ principalAncestors(c) returns the list of all category
      ++ forms that are principal ancestors of the the category `c'.
    parents: % -> List ConstructorCall
      ++ parents(c) returns the list of all category forms directly
      ++ extended by the category `c'.
  Private == add
    constructor x ==
      CAR(devaluate(x)$Lisp)$Lisp

    exportedOperators c ==
      [CAR(x)$Lisp@OperatorSignature 
         for x in getCategoryExports(c)$Lisp@List(Syntax)]
    
    principalAncestors c == 
      getCategoryPrincipalAncestors(c)$Lisp

    parents c ==
      [CAR(x)$Lisp@ConstructorCall
         for x in getCategoryParents(c)$Lisp@List(Syntax)]

    coerce x ==
      outputDomainConstructor(x)$Lisp
@

\section{domain Domain}
<<domain DOMAIN Domain>>=
import Void
import ConstructorCall
import DomainConstructor
)abbrev domain DOMAIN Domain
++ Author: Gabriel Dos Reis
++ Date Create: October 18, 2007.
++ Date Last Updated: December 20, 2008.
++ Basic Operations: coerce, reify
++ Related Constructors: Type, Syntax, OutputForm
++ Also See: Type, ConstructorCall
Domain(): Public == Private where
  Public == SetCategory with
    constructor: % -> DomainConstructor
      ++ constructor(d) returns the domain constructor that is
      ++ instantiated to the domain object `d'.
    reify: % -> ConstructorCall
      ++ reify(d) returns the abstract syntax for the domain `x'.

    reflect: ConstructorCall -> %
      ++ reflect cc returns the domain object designated by the
      ++ ConstructorCall syntax `cc'.  The constructor implied 
      ++ by `cc' must be known to the system since it is instantiated.
   
    showSummary: % -> Void
      ++ showSummary(d) prints out implementation detail information
      ++ of domain `d'.

  Private == add
    constructor x ==
      CAR(devaluate(x)$Lisp)$Lisp

    coerce x ==
      outputDomainConstructor(x)$Lisp

    reify x ==
      devaluate(x)$Lisp @ ConstructorCall

    reflect cc ==
      evalDomain(cc)$Lisp @ %

    x = y ==
      reify x = reify y

    showSummary x ==
      showSummary(x)$Lisp

@


\section{License}
<<license>>=
--Copyright (C) 2007-2008, Gabriel Dos Reis.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical Algorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@


<<*>>=
<<license>>

<<domain CTORKIND ConstructorKinid>>
<<category CTORCAT ConstructorCategory>>
<<domain CTOR Constructor>>
<<domain CTORCALL ConstructorCall>>
<<domain CATCTOR CategoryConstructor>>
<<domain DOMCTOR DomainConstructor>>

<<domain SIG Signature>>
<<domain OPSIG OperatorSignature>>

<<domain CATEGORY Category>>
<<domain DOMAIN Domain>>
@