login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Type-safe Objects in SPAD

spad
)abbrev domain OBJ Object
Object(C:Type): CoercibleTo(OutputForm) with Type : % -> C new : (SExpression, None) -> % dom : % -> SExpression obj : % -> None
if C has BasicType then BasicType if C has Ring then _+ : (%,%) -> %
== add
Rep := Record(dm: SExpression, ob: None) import Rep
dom(x:%):SExpression == (x pretend Rep).dm
obj(x:%):None == (x pretend Rep).ob
Type(x:%):C == dom(x) pretend C
if C has BasicType then _=(x:%,y:%):Boolean == xR := x pretend Rep yR := y pretend Rep if xR.dm = yR.dm then D:BasicType := xR.dm pretend BasicType X:D := (obj x) pretend D Y:D := (obj y) pretend D (X=Y)$D else false
if C has Ring then _+(x:%,y:%):% == xR := x pretend Rep yR := y pretend Rep if xR.dm = yR.dm then D:= xR.dm pretend Ring X:D := (obj x) pretend D Y:D := (obj y) pretend D Z:= (X+Y)$D new(xR.dm,Z pretend None) else error "not possible"
coerce(x):OutputForm == xR := x pretend Rep obj1 : OutputForm := spad2BootCoerce(xR.ob, xR.dm, list("OutputForm"::Symbol)$List(Symbol))$Lisp dom1 := p:Symbol := prefix2String(xR.dm)$Lisp atom?(p pretend SExpression) => list(p)$List(Symbol) list(p)$Symbol hconcat cons(obj1, cons(":"::OutputForm, [a::OutputForm for a in dom1]))
new(domain:SExpression, object:None):% == (isValidType(domain)$Lisp)@Boolean => construct(domain, object)$Rep pretend % domains := devaluate(domain)$Lisp (isValidType(domains)$Lisp)@Boolean => construct(domains, object)$Rep pretend % error "must have a valid domain as first argument"
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/2710714920993231977-25px001.spad
      using old system compiler.
   OBJ abbreviates domain Object 
------------------------------------------------------------------------
   initializing NRLIB OBJ for Object 
   compiling into NRLIB OBJ 
   importing Rep
   compiling exported dom : $ -> SExpression
      OBJ;dom;$Se;1 is replaced by QCAR 
Time: 0 SEC.
compiling exported obj : $ -> None OBJ;obj;$N;2 is replaced by QCDR Time: 0.01 SEC.
compiling exported Type : $ -> C Time: 0 SEC.
****** Domain: C already in scope augmenting C: (BasicType) compiling exported = : ($,$) -> Boolean Time: 0 SEC.
****** Domain: C already in scope augmenting C: (Ring) augmenting $: (SIGNATURE $ + ($ $ $)) compiling exported + : ($,$) -> $ Time: 0 SEC.
compiling exported coerce : $ -> OutputForm Time: 0.01 SEC.
compiling exported new : (SExpression,None) -> $ Time: 0 SEC.
****** Domain: C already in scope augmenting C: (BasicType) ****** Domain: C already in scope augmenting C: (Ring) augmenting $: (SIGNATURE $ + ($ $ $)) (time taken in buildFunctor: 0)
;;; *** |Object| REDEFINED
;;; *** |Object| REDEFINED Time: 0.01 SEC.
Semantic Errors: [1] =: pretend is not a known type [2] +: pretend is not a known type
Warnings: [1] dom: pretendRep -- should replace by @ [2] obj: pretendRep -- should replace by @ [3] =: pretendRep -- should replace by @ [4] +: pretendRep -- should replace by @ [5] coerce: pretendRep -- should replace by @ [6] new: pretend$ -- should replace by @
Cumulative Statistics for Constructor Object Time: 0.03 seconds
finalizing NRLIB OBJ Processing Object for Browser database: --->-->Object(constructor): Not documented!!!! --->-->Object(((Type) (C %))): Not documented!!!! --->-->Object((new (% (SExpression) (None)))): Not documented!!!! --->-->Object((dom ((SExpression) %))): Not documented!!!! --->-->Object((obj ((None) %))): Not documented!!!! --->-->Object((+ (% % %))): Not documented!!!! --->-->Object(): Missing Description ; compiling file "/var/aw/var/LatexWiki/OBJ.NRLIB/OBJ.lsp" (written 31 JUL 2013 05:20:55 PM):
; /var/aw/var/LatexWiki/OBJ.NRLIB/OBJ.fasl written ; compilation finished in 0:00:00.032 ------------------------------------------------------------------------ Object is now explicitly exposed in frame initial Object will be automatically loaded when needed from /var/aw/var/LatexWiki/OBJ.NRLIB/OBJ

spad
)abbrev package HAS Has
Has(C:Type,S:C): with coerce : S -> Object(C) avail : Object(C) -> Union(S, "failed") is? : Object(C) -> Boolean get : Object(C) -> S
== add
Sexpr:SExpression := devaluate(S)$Lisp
is?(a:Object(C)):Boolean == dom(a) = Sexpr
coerce(s:S):Object(C) == new(Sexpr, s pretend None)
avail(a:Object(C)):Union(S,"failed") == is? a => obj(a) pretend S "failed"
get(a:Object(C)):S == is? a => obj(a) pretend S error "Cannot retract value."
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/6566032851093813704-25px002.spad
      using old system compiler.
   HAS abbreviates package Has 
------------------------------------------------------------------------
   initializing NRLIB HAS for Has 
   compiling into NRLIB HAS 
****** Domain: C already in scope
   compiling exported is? : Object C -> Boolean
Time: 0 SEC.
compiling exported coerce : S -> Object C Time: 0 SEC.
compiling exported avail : Object C -> Union(S,failed) Time: 0 SEC.
compiling exported get : Object C -> S Time: 0 SEC.
(time taken in buildFunctor: 0)
;;; *** |Has| REDEFINED
;;; *** |Has| REDEFINED Time: 0 SEC.
Semantic Errors: [1] S is not a known type
Cumulative Statistics for Constructor Has Time: 0 seconds
finalizing NRLIB HAS Processing Has for Browser database: --->-->Has(constructor): Not documented!!!! --->-->Has((coerce ((Object C) S))): Not documented!!!! --->-->Has((avail ((Union S failed) (Object C)))): Not documented!!!! --->-->Has((is? ((Boolean) (Object C)))): Not documented!!!! --->-->Has((get (S (Object C)))): Not documented!!!! --->-->Has(): Missing Description ; compiling file "/var/aw/var/LatexWiki/HAS.NRLIB/HAS.lsp" (written 31 JUL 2013 05:20:55 PM):
; /var/aw/var/LatexWiki/HAS.NRLIB/HAS.fasl written ; compilation finished in 0:00:00.016 ------------------------------------------------------------------------ Has is now explicitly exposed in frame initial Has will be automatically loaded when needed from /var/aw/var/LatexWiki/HAS.NRLIB/HAS

fricas
)sh Object(SetCategory)
Object(SetCategory) is a domain constructor. Abbreviation for Object is OBJ This constructor is exposed in this frame. ------------------------------- Operations --------------------------------
?+? : (%,%) -> % ?=? : (%,%) -> Boolean Type : % -> SetCategory coerce : % -> OutputForm dom : % -> SExpression new : (SExpression,None) -> % obj : % -> None ?~=? : (%,%) -> Boolean
fricas
)sh Object(Ring)
Object(Ring) is a domain constructor. Abbreviation for Object is OBJ This constructor is exposed in this frame. ------------------------------- Operations --------------------------------
?+? : (%,%) -> % ?=? : (%,%) -> Boolean Type : % -> Ring coerce : % -> OutputForm dom : % -> SExpression new : (SExpression,None) -> % obj : % -> None ?~=? : (%,%) -> Boolean
fricas
)sh Has
Has(C: Type,S: C) is a package constructor Abbreviation for Has is HAS This constructor is exposed in this frame. ------------------------------- Operations -------------------------------- coerce : S -> Object(C) get : Object(C) -> S is? : Object(C) -> Boolean avail : Object(C) -> Union(S,"failed")
fricas
)sh Has(SetCategory,Integer)
Has(SetCategory,Integer) is a package constructor. Abbreviation for Has is HAS This constructor is exposed in this frame. ------------------------------- Operations --------------------------------
avail : Object(SetCategory) -> Union(Integer,"failed") coerce : Integer -> Object(SetCategory) get : Object(SetCategory) -> Integer is? : Object(SetCategory) -> Boolean

fricas
b:Object(BasicType):="abc"

\label{eq1}\mbox{\tt "abc"}: \hbox{\axiomType{String}\ }(1)
Type: Object(BasicType?)
fricas
a:=[1,"xxx",1.2]::List Object SetCategory

\label{eq2}\left[{1 : \hbox{\axiomType{PositiveInteger}\ }}, \:{\mbox{\tt "xxx"}: \hbox{\axiomType{String}\ }}, \:{{1.2}: \hbox{\axiomType{Float}\ }}\right](2)
Type: List(Object(SetCategory))
fricas
a.1

\label{eq3}1 : \hbox{\axiomType{PositiveInteger}\ }(3)
Type: Object(SetCategory)
fricas
a.2

\label{eq4}\mbox{\tt "xxx"}: \hbox{\axiomType{String}\ }(4)
Type: Object(SetCategory)
fricas
Type(a.2)

\label{eq5}\hbox{\axiomType{String}\ }(5)
fricas
(a.1 = a.2)$Object(SetCategory)
There are 2 exposed and 8 unexposed library operations named = having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op = to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named = with argument type(s) Object(SetCategory) Object(SetCategory)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need. is?(a.2)$Has(SetCategory,String)

\label{eq6} \mbox{\rm true} (6)
Type: Boolean
fricas
get(a.2)@String

\label{eq7}\mbox{\tt "xxx"}(7)
Type: String
fricas
avail(a.3)$Has(SetCategory,Float)

\label{eq8}1.2(8)
Type: Union(Float,...)
fricas
avail(a.2)$Has(SetCategory,Float)

\label{eq9}\mbox{\tt "failed"}(9)
Type: Union("failed",...)
fricas
avail(a.1)$Has(SetCategory,Float) case Float

\label{eq10} \mbox{\rm false} (10)
Type: Boolean

fricas
n:Object(Ring)
Type: Void
fricas
n:=coerce(1)$Has(Ring,Integer)

\label{eq11}1 : \hbox{\axiomType{Integer}\ }(11)
Type: Object(Ring)
fricas
m:Object(Ring):=coerce(2)$Has(Ring,Integer)

\label{eq12}2 : \hbox{\axiomType{Integer}\ }(12)
Type: Object(Ring)
fricas
n+m
There are 12 exposed and 8 unexposed library operations named + having 2 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op + to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation.
Cannot find a definition or applicable library operation named + with argument type(s) Object(Ring) Object(Ring)
Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: