\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/algebra omdev.spad}
\author{Vilya Harvey}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{domain OMENC OpenMathEncoding}
<<domain OMENC OpenMathEncoding>>=
)abbrev domain OMENC OpenMathEncoding
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions: 
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++ \spadtype{OpenMathEncoding} is the set of valid OpenMath encodings.
OpenMathEncoding(): SetCategory with
  OMencodingUnknown : () -> %
  ++ OMencodingUnknown() is the constant for unknown encoding types. If this 
  ++ is used on an input device, the encoding will be autodetected.
  ++ It is invalid to use it on an output device.
  OMencodingXML     : () -> %
  ++ OMencodingXML() is the constant for the OpenMath XML encoding.
  OMencodingSGML    : () -> %
  ++ OMencodingSGML() is the constant for the deprecated OpenMath SGML encoding.
  OMencodingBinary  : () -> %
  ++ OMencodingBinary() is the constant for the OpenMath binary encoding.
 == add
  Rep := SingleInteger

  =(u,v) == (u=v)$Rep

  import Rep

  coerce(u) ==
    u::Rep = 0$Rep => "Unknown"::OutputForm
    u::Rep = 1$Rep => "Binary"::OutputForm
    u::Rep = 2::Rep => "XML"::OutputForm
    u::Rep = 3::Rep => "SGML"::OutputForm
    error "Bogus OpenMath Encoding Type"

  OMencodingUnknown(): % == 0::Rep
  OMencodingBinary(): % == 1::Rep
  OMencodingXML(): % == 2::Rep
  OMencodingSGML(): % == 3::Rep

@
\section{domain OMDEV OpenMathDevice}
<<domain OMDEV OpenMathDevice>>=
import Void
import String
import Integer
import DoubleFloat
import String
import Symbol
import OpenMathEncoding
)abbrev domain OMDEV OpenMathDevice
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathDevice} provides support for reading
++ and writing openMath objects to files, strings etc.  It also provides
++ access to low-level operations from within the interpreter.


OpenMathDevice(): with
  OMopenFile    : (String, String, OpenMathEncoding) -> %
  ++ OMopenFile(f,mode,enc) opens file \axiom{f} for reading or writing
  ++ OpenMath objects (depending on \axiom{mode} which can be "r", "w"
  ++ or "a" for read, write and append respectively), in the encoding
  ++ \axiom{enc}.
  OMopenString  : (String, OpenMathEncoding) -> %
  ++ OMopenString(s,mode) opens the string \axiom{s} for reading or writing 
  ++ OpenMath objects in encoding \axiom{enc}.
  OMclose       : % -> Void
  ++ OMclose(dev) closes \axiom{dev}, flushing output if necessary.
  OMsetEncoding : (%, OpenMathEncoding) -> Void
  ++ OMsetEncoding(dev,enc) sets the encoding used for reading or writing
  ++ OpenMath objects to or from \axiom{dev} to \axiom{enc}.
  OMputApp      : % -> Void
  ++ OMputApp(dev) writes a begin application token to \axiom{dev}.
  OMputAtp      : % -> Void
  ++ OMputAtp(dev) writes a begin attribute pair token to \axiom{dev}.
  OMputAttr     : % -> Void
  ++ OMputAttr(dev) writes a begin attribute token to \axiom{dev}.
  OMputBind     : % -> Void
  ++ OMputBind(dev) writes a begin binder token to \axiom{dev}.
  OMputBVar     : % -> Void
  ++ OMputBVar(dev) writes a begin bound variable list token to \axiom{dev}.
  OMputError    : % -> Void
  ++ OMputError(dev) writes a begin error token to \axiom{dev}.
  OMputObject   : % -> Void
  ++ OMputObject(dev) writes a begin object token to \axiom{dev}.
  OMputEndApp   : % -> Void
  ++ OMputEndApp(dev) writes an end application token to \axiom{dev}.
  OMputEndAtp   : % -> Void
  ++ OMputEndAtp(dev) writes an end attribute pair token to \axiom{dev}.
  OMputEndAttr  : % -> Void
  ++ OMputEndAttr(dev) writes an end attribute token to \axiom{dev}.
  OMputEndBind  : % -> Void
  ++ OMputEndBind(dev) writes an end binder token to \axiom{dev}.
  OMputEndBVar  : % -> Void
  ++ OMputEndBVar(dev) writes an end bound variable list token to \axiom{dev}.
  OMputEndError : % -> Void
  ++ OMputEndError(dev) writes an end error token to \axiom{dev}.
  OMputEndObject: % -> Void
  ++ OMputEndObject(dev) writes an end object token to \axiom{dev}.
  OMputInteger  : (%, Integer) -> Void
  ++ OMputInteger(dev,i) writes the integer \axiom{i} to \axiom{dev}.
  OMputFloat    : (%, DoubleFloat) -> Void
  ++ OMputFloat(dev,i) writes the float \axiom{i} to \axiom{dev}.
  OMputVariable : (%, Symbol) -> Void
  ++ OMputVariable(dev,i) writes the variable \axiom{i} to \axiom{dev}.
  OMputString   : (%, String) -> Void
  ++ OMputString(dev,i) writes the string \axiom{i} to \axiom{dev}.
  OMputSymbol   : (%, String, String) -> Void
  ++ OMputSymbol(dev,cd,s) writes the symbol \axiom{s} from CD \axiom{cd}
  ++ to \axiom{dev}.

  OMgetApp      : % -> Void
  ++ OMgetApp(dev) reads a begin application token from \axiom{dev}.
  OMgetAtp      : % -> Void
  ++ OMgetAtp(dev) reads a begin attribute pair token from \axiom{dev}.
  OMgetAttr     : % -> Void
  ++ OMgetAttr(dev) reads a begin attribute token from \axiom{dev}.
  OMgetBind     : % -> Void
  ++ OMgetBind(dev) reads a begin binder token from \axiom{dev}.
  OMgetBVar     : % -> Void
  ++ OMgetBVar(dev) reads a begin bound variable list token from \axiom{dev}.
  OMgetError    : % -> Void
  ++ OMgetError(dev) reads a begin error token from \axiom{dev}.
  OMgetObject   : % -> Void
  ++ OMgetObject(dev) reads a begin object token from \axiom{dev}.
  OMgetEndApp   : % -> Void
  ++ OMgetEndApp(dev) reads an end application token from \axiom{dev}.
  OMgetEndAtp   : % -> Void
  ++ OMgetEndAtp(dev) reads an end attribute pair token from \axiom{dev}.
  OMgetEndAttr  : % -> Void
  ++ OMgetEndAttr(dev) reads an end attribute token from \axiom{dev}.
  OMgetEndBind  : % -> Void
  ++ OMgetEndBind(dev) reads an end binder token from \axiom{dev}.
  OMgetEndBVar  : % -> Void
  ++ OMgetEndBVar(dev) reads an end bound variable list token from \axiom{dev}.
  OMgetEndError : % -> Void
  ++ OMgetEndError(dev) reads an end error token from \axiom{dev}.
  OMgetEndObject: % -> Void
  ++ OMgetEndObject(dev) reads an end object token from \axiom{dev}.
  OMgetInteger  : % -> Integer
  ++ OMgetInteger(dev) reads an integer from \axiom{dev}.
  OMgetFloat    : % -> DoubleFloat
  ++ OMgetFloat(dev) reads a float from \axiom{dev}.
  OMgetVariable : % -> Symbol
  ++ OMgetVariable(dev) reads a variable from \axiom{dev}.
  OMgetString   : % -> String
  ++ OMgetString(dev) reads a string from \axiom{dev}.
  OMgetSymbol   : % -> Record(cd:String, name:String)
  ++ OMgetSymbol(dev) reads a symbol from \axiom{dev}.

  OMgetType     : % -> Symbol
  ++ OMgetType(dev) returns the type of the next object on \axiom{dev}.
 == add
  OMopenFile(fname: String, fmode: String, enc: OpenMathEncoding): % ==
    OM_-OPENFILEDEV(fname, fmode, enc)$Lisp
  OMopenString(str: String, enc: OpenMathEncoding): % ==
    OM_-OPENSTRINGDEV(str, enc)$Lisp
  OMclose(dev: %): Void ==
    OM_-CLOSEDEV(dev)$Lisp
  OMsetEncoding(dev: %, enc: OpenMathEncoding): Void ==
    OM_-SETDEVENCODING(dev, enc)$Lisp

  OMputApp(dev: %): Void == OM_-PUTAPP(dev)$Lisp
  OMputAtp(dev: %): Void == OM_-PUTATP(dev)$Lisp
  OMputAttr(dev: %): Void == OM_-PUTATTR(dev)$Lisp
  OMputBind(dev: %): Void == OM_-PUTBIND(dev)$Lisp
  OMputBVar(dev: %): Void == OM_-PUTBVAR(dev)$Lisp
  OMputError(dev: %): Void == OM_-PUTERROR(dev)$Lisp
  OMputObject(dev: %): Void == OM_-PUTOBJECT(dev)$Lisp
  OMputEndApp(dev: %): Void == OM_-PUTENDAPP(dev)$Lisp
  OMputEndAtp(dev: %): Void == OM_-PUTENDATP(dev)$Lisp
  OMputEndAttr(dev: %): Void == OM_-PUTENDATTR(dev)$Lisp
  OMputEndBind(dev: %): Void == OM_-PUTENDBIND(dev)$Lisp
  OMputEndBVar(dev: %): Void == OM_-PUTENDBVAR(dev)$Lisp
  OMputEndError(dev: %): Void == OM_-PUTENDERROR(dev)$Lisp
  OMputEndObject(dev: %): Void == OM_-PUTENDOBJECT(dev)$Lisp
  OMputInteger(dev: %, i: Integer): Void == OM_-PUTINT(dev, i)$Lisp
  OMputFloat(dev: %, f: DoubleFloat): Void == OM_-PUTFLOAT(dev, f)$Lisp
  --OMputByteArray(dev: %, b: Array Byte): Void == OM_-PUTBYTEARRAY(dev, b)$Lisp
  OMputVariable(dev: %, v: Symbol): Void == OM_-PUTVAR(dev, v)$Lisp
  OMputString(dev: %, s: String): Void == OM_-PUTSTRING(dev, s)$Lisp
  OMputSymbol(dev: %, cd: String, nm: String): Void == OM_-PUTSYMBOL(dev, cd, nm)$Lisp

  OMgetApp(dev: %): Void == OM_-GETAPP(dev)$Lisp
  OMgetAtp(dev: %): Void == OM_-GETATP(dev)$Lisp
  OMgetAttr(dev: %): Void == OM_-GETATTR(dev)$Lisp
  OMgetBind(dev: %): Void == OM_-GETBIND(dev)$Lisp
  OMgetBVar(dev: %): Void == OM_-GETBVAR(dev)$Lisp
  OMgetError(dev: %): Void == OM_-GETERROR(dev)$Lisp
  OMgetObject(dev: %): Void == OM_-GETOBJECT(dev)$Lisp
  OMgetEndApp(dev: %): Void == OM_-GETENDAPP(dev)$Lisp
  OMgetEndAtp(dev: %): Void == OM_-GETENDATP(dev)$Lisp
  OMgetEndAttr(dev: %): Void == OM_-GETENDATTR(dev)$Lisp
  OMgetEndBind(dev: %): Void == OM_-GETENDBIND(dev)$Lisp
  OMgetEndBVar(dev: %): Void == OM_-GETENDBVAR(dev)$Lisp
  OMgetEndError(dev: %): Void == OM_-GETENDERROR(dev)$Lisp
  OMgetEndObject(dev: %): Void == OM_-GETENDOBJECT(dev)$Lisp
  OMgetInteger(dev: %): Integer == OM_-GETINT(dev)$Lisp
  OMgetFloat(dev: %): DoubleFloat == OM_-GETFLOAT(dev)$Lisp
  --OMgetByteArray(dev: %): Array Byte == OM_-GETBYTEARRAY(dev)$Lisp
  OMgetVariable(dev: %): Symbol == OM_-GETVAR(dev)$Lisp
  OMgetString(dev: %): String == OM_-GETSTRING(dev)$Lisp
  OMgetSymbol(dev: %): Record(cd:String, name:String) == OM_-GETSYMBOL(dev)$Lisp

  OMgetType(dev: %): Symbol == OM_-GETTYPE(dev)$Lisp

@
\section{domain OMCONN OpenMathConnection}
<<domain OMCONN OpenMathConnection>>=
import Void
import Boolean
import SingleInteger
import String
import OpenMathDevice
)abbrev domain OMCONN OpenMathConnection
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathConnection} provides low-level functions
++ for handling connections to and from \spadtype{OpenMathDevice}s.


OpenMathConnection(): with
  OMmakeConn    : SingleInteger -> % ++ \spad{OMmakeConn}
  OMcloseConn   : % -> Void ++ \spad{OMcloseConn}
  OMconnInDevice: %-> OpenMathDevice ++ \spad{OMconnInDevice:}
  OMconnOutDevice: %-> OpenMathDevice ++ \spad{OMconnOutDevice:}
  OMconnectTCP  : (%, String, SingleInteger) -> Boolean ++ \spad{OMconnectTCP}
  OMbindTCP     : (%, SingleInteger) -> Boolean ++ \spad{OMbindTCP}
 == add
  OMmakeConn(timeout: SingleInteger): % == OM_-MAKECONN(timeout)$Lisp
  OMcloseConn(conn: %): Void == OM_-CLOSECONN(conn)$Lisp

  OMconnInDevice(conn: %): OpenMathDevice ==
    OM_-GETCONNINDEV(conn)$Lisp
  OMconnOutDevice(conn: %): OpenMathDevice ==
    OM_-GETCONNOUTDEV(conn)$Lisp

  OMconnectTCP(conn: %, host: String, port: SingleInteger): Boolean ==
    OM_-CONNECTTCP(conn, host, port)$Lisp
  OMbindTCP(conn: %, port: SingleInteger): Boolean ==
    OM_-BINDTCP(conn, port)$Lisp

@
\section{package OMPKG OpenMathPackage}
<<package OMPKG OpenMathPackage>>=
)abbrev package OMPKG OpenMathPackage
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathPackage} provides some simple utilities 
++ to make reading OpenMath objects easier.

OpenMathPackage(): with
  OMread            : OpenMathDevice -> Any
  ++ OMread(dev) reads an OpenMath object from \axiom{dev} and passes it
  ++ to AXIOM.
  OMreadFile        : String -> Any
  ++ OMreadFile(f) reads an OpenMath object from \axiom{f} and passes it
  ++ to AXIOM.
  OMreadStr         : String -> Any
  ++ OMreadStr(f) reads an OpenMath object from \axiom{f} and passes it
  ++ to AXIOM.
  OMlistCDs         : () -> List(String)
  ++ OMlistCDs() lists all the CDs supported by AXIOM.
  OMlistSymbols     : String -> List(String)
  ++ OMlistSymbols(cd) lists all the symbols in \axiom{cd}.
  OMsupportsCD?      : String -> Boolean
  ++ OMsupportsCD?(cd) returns true if AXIOM supports \axiom{cd}, false 
  ++ otherwise.
  OMsupportsSymbol? : (String, String) -> Boolean
  ++ OMsupportsSymbol?(s,cd) returns true if AXIOM supports symbol \axiom{s}
  ++ from CD \axiom{cd}, false otherwise.
  OMunhandledSymbol : (String, String) -> Exit
  ++ OMunhandledSymbol(s,cd) raises an error if AXIOM reads a symbol which it
  ++ is unable to handle.  Note that this is different from an unexpected
  ++ symbol.
 == add
  import OpenMathEncoding
  import OpenMathDevice
  import String

  OMunhandledSymbol(u,v) ==
    error concat ["AXIOM is unable to process the symbol ",u," from CD ",v,"."]

  OMread(dev: OpenMathDevice): Any ==
    interpret(OM_-READ(dev)$Lisp :: InputForm)

  OMreadFile(filename: String): Any ==
    dev := OMopenFile(filename, "r", OMencodingUnknown())
    res: Any := interpret(OM_-READ(dev)$Lisp :: InputForm)
    OMclose(dev)
    res

  OMreadStr(str: String): Any ==
    strp := OM_-STRINGTOSTRINGPTR(str)$Lisp
    dev := OMopenString(strp pretend String, OMencodingUnknown())
    res: Any := interpret(OM_-READ(dev)$Lisp :: InputForm)
    OMclose(dev)
    res

  OMlistCDs(): List(String) ==
    OM_-LISTCDS()$Lisp pretend List(String)

  OMlistSymbols(cd: String): List(String) ==
    OM_-LISTSYMBOLS(cd)$Lisp pretend List(String)

  import SExpression

  OMsupportsCD?(cd: String): Boolean ==
    not null? OM_-SUPPORTSCD(cd)$Lisp 

  OMsupportsSymbol?(cd: String, name: String): Boolean ==
    not null? OM_-SUPPORTSSYMBOL(cd, name)$Lisp

@
\section{License}
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--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 OMENC OpenMathEncoding>>
<<domain OMDEV OpenMathDevice>>
<<domain OMCONN OpenMathConnection>>
<<package OMPKG OpenMathPackage>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}