Commit 755db3ce authored by Dave Cooper's avatar Dave Cooper
Browse files

continuing to build up the new tutorial manual

parent d53e5d63
......@@ -128,16 +128,34 @@
\newlabel{subsec:symbols}{{4.2.3}{23}{Symbols\relax }{subsection.4.2.3}{}}
\@writefile{toc}{\contentsline {subsection}{\numberline {4.2.4}Lists}{24}{subsection.4.2.4}}
\newlabel{subsec:lists}{{4.2.4}{24}{Lists\relax }{subsection.4.2.4}{}}
\@writefile{toc}{\contentsline {chapter}{\numberline {5}Understanding Gendl}{25}{chapter.5}}
\@writefile{toc}{\contentsline {chapter}{\numberline {5}Understanding Gendl --- Core GDL Syntax}{25}{chapter.5}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\newlabel{chap:understandinggendl}{{5}{25}{Understanding Gendl\relax }{chapter.5}{}}
\@writefile{toc}{\contentsline {chapter}{\numberline {6}More Common Lisp for Gendl}{27}{chapter.6}}
\newlabel{chap:understandinggendl---coregdlsyntax}{{5}{25}{Understanding Gendl --- Core GDL Syntax\relax }{chapter.5}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.1}Defining a Working Package}{25}{section.5.1}}
\newlabel{sec:definingaworkingpackage}{{5.1}{25}{Defining a Working Package\relax }{section.5.1}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.2}Define-Object}{26}{section.5.2}}
\newlabel{sec:define-object}{{5.2}{26}{Define-Object\relax }{section.5.2}{}}
\@writefile{lof}{\contentsline {figure}{\numberline {5.1}{\ignorespaces Example of Simple Object Definition}}{27}{figure.5.1}}
\newlabel{fig:object-hello}{{5.1}{27}{Example of Simple Object Definition\relax }{figure.5.1}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.3}Making Instances and Sending Messages}{27}{section.5.3}}
\newlabel{sec:makinginstancesandsendingmessages}{{5.3}{27}{Making Instances and Sending Messages\relax }{section.5.3}{}}
\@writefile{lof}{\contentsline {figure}{\numberline {5.2}{\ignorespaces Object Containing Child Objects}}{28}{figure.5.2}}
\newlabel{fig:object-city}{{5.2}{28}{Object Containing Child Objects\relax }{figure.5.2}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.4}Objects}{28}{section.5.4}}
\newlabel{sec:objects}{{5.4}{28}{Objects\relax }{section.5.4}{}}
\@writefile{lof}{\contentsline {figure}{\numberline {5.3}{\ignorespaces Sample Data and Object Definition to Contain U.S. Presidents}}{29}{figure.5.3}}
\newlabel{fig:object-presidents-container}{{5.3}{29}{Sample Data and Object Definition to Contain U.S. Presidents\relax }{figure.5.3}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.5}Sequences of Objects and Input-slots with a Default Expression}{29}{section.5.5}}
\newlabel{sec:sequencesofobjectsandinput-slotswithadefaultexpression}{{5.5}{29}{Sequences of Objects and Input-slots with a Default Expression\relax }{section.5.5}{}}
\@writefile{toc}{\contentsline {section}{\numberline {5.6}Summary}{30}{section.5.6}}
\newlabel{sec:summary}{{5.6}{30}{Summary\relax }{section.5.6}{}}
\@writefile{toc}{\contentsline {chapter}{\numberline {6}More Common Lisp for Gendl}{31}{chapter.6}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\newlabel{chap:morecommonlispforgendl}{{6}{27}{More Common Lisp for Gendl\relax }{chapter.6}{}}
\@writefile{toc}{\contentsline {chapter}{\numberline {7}Advanced Gendl}{29}{chapter.7}}
\newlabel{chap:morecommonlispforgendl}{{6}{31}{More Common Lisp for Gendl\relax }{chapter.6}{}}
\@writefile{toc}{\contentsline {chapter}{\numberline {7}Advanced Gendl}{33}{chapter.7}}
\@writefile{lof}{\addvspace {10\p@ }}
\@writefile{lot}{\addvspace {10\p@ }}
\newlabel{chap:advancedgendl}{{7}{29}{Advanced Gendl\relax }{chapter.7}{}}
\newlabel{chap:upgradenotes}{{7}{31}{Upgrade Notes\relax }{chapter*.5}{}}
\newlabel{chap:advancedgendl}{{7}{33}{Advanced Gendl\relax }{chapter.7}{}}
\newlabel{chap:upgradenotes}{{7}{35}{Upgrade Notes\relax }{chapter*.5}{}}
......@@ -13,3 +13,25 @@
\indexentry{gdl-user(1): |hyperpage}{9}
\indexentry{*slime-repl...*|hyperpage}{9}
\indexentry{regression tests|hyperpage}{11}
\indexentry{objects!defining|hyperpage}{26}
\indexentry{Define-object|hyperpage}{26}
\indexentry{mixin-list|hyperpage}{26}
\indexentry{specification-plist|hyperpage}{26}
\indexentry{input-slots|hyperpage}{26}
\indexentry{computed-slots|hyperpage}{26}
\indexentry{objects|hyperpage}{26}
\indexentry{functions|hyperpage}{26}
\indexentry{the|hyperpage}{27}
\indexentry{make-object|hyperpage}{27}
\indexentry{make-instance|hyperpage}{27}
\indexentry{the-object|hyperpage}{27}
\indexentry{self|hyperpage}{27}
\indexentry{objects|hyperpage}{28}
\indexentry{containment!object|hyperpage}{28}
\indexentry{objects!child|hyperpage}{28}
\indexentry{objects!contained|hyperpage}{28}
\indexentry{reference chains|hyperpage}{28}
\indexentry{Objects!sequenced|hyperpage}{29}
\indexentry{sequences|hyperpage}{29}
\indexentry{object sequences|hyperpage}{29}
\indexentry{:size|hyperpage}{29}
This is makeindex, version 2.15 [TeX Live 2012] (kpathsea + Thai support).
Scanning input file tutorial.idx....done (15 entries accepted, 0 rejected).
Sorting entries....done (70 comparisons).
Generating output file tutorial.ind....done (49 lines written, 0 warnings).
Scanning input file tutorial.idx....done (37 entries accepted, 0 rejected).
Sorting entries....done (208 comparisons).
Generating output file tutorial.ind....done (81 lines written, 0 warnings).
Output written in tutorial.ind.
Transcript written in tutorial.ilg.
\begin{theindex}
\item *slime-repl...*, \hyperpage{9}
\item :size, \hyperpage{29}
\indexspace
......@@ -12,20 +13,29 @@
\item Common Lisp, \hyperpage{2}
\item compiled language
\subitem benefits of, \hyperpage{2}
\item computed-slots, \hyperpage{26}
\item containment
\subitem object, \hyperpage{28}
\indexspace
\item declarative, \hyperpage{2}
\item Define-object, \hyperpage{26}
\item Dependency tracking, \hyperpage{1}
\indexspace
\item functions, \hyperpage{26}
\indexspace
\item gdl-user(1): , \hyperpage{9}
\item Genworks Gendl Console, \hyperpage{7}
\indexspace
\item Ignorance-based Engineering, \hyperpage{1}
\item input-slots, \hyperpage{26}
\indexspace
......@@ -35,15 +45,37 @@
\item macros
\subitem code-expanding, \hyperpage{2}
\item make-instance, \hyperpage{27}
\item make-object, \hyperpage{27}
\item mixin-list, \hyperpage{26}
\indexspace
\item object sequences, \hyperpage{29}
\item object-orientation
\subitem generic-function, \hyperpage{2}
\subitem message-passing, \hyperpage{2}
\item Objects
\subitem sequenced, \hyperpage{29}
\item objects, \hyperpage{26}, \hyperpage{28}
\subitem child, \hyperpage{28}
\subitem contained, \hyperpage{28}
\subitem defining, \hyperpage{26}
\indexspace
\item reference chains, \hyperpage{28}
\item regression tests, \hyperpage{11}
\indexspace
\item self, \hyperpage{27}
\item sequences, \hyperpage{29}
\item specification-plist, \hyperpage{26}
\indexspace
\item the, \hyperpage{27}
\item the-object, \hyperpage{27}
\end{theindex}
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/MacPorts 2012_1) (format=pdflatex 2012.8.4) 20 NOV 2012 18:49
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/MacPorts 2012_1) (format=pdflatex 2012.8.4) 21 NOV 2012 12:14
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
......@@ -386,7 +386,7 @@ Chapter 1.
]
Chapter 2.
<../images/gendl-installation.png, id=289, 127.40933pt x 70.12866pt>
<../images/gendl-installation.png, id=319, 127.40933pt x 70.12866pt>
File: ../images/gendl-installation.png Graphic file (type png)
<use ../images/gendl-installation.png>
......@@ -400,14 +400,14 @@ man-ager, right-mouse on the \OT1/cmtt/m/n/10.95 run-gdl.bat
[]
[6 <../images/gendl-installation.png>]
<../images/mini-buffer.png, id=318, 687.56876pt x 613.29124pt>
<../images/mini-buffer.png, id=348, 687.56876pt x 613.29124pt>
File: ../images/mini-buffer.png Graphic file (type png)
<use ../images/mini-buffer.png>
Package pdftex.def Info: ../images/mini-buffer.png used on input line 401.
(pdftex.def) Requested size: 216.80562pt x 216.8075pt.
<../images/genworks-gendl-console.png, id=320, 318.52333pt x 212.52733pt>
<../images/genworks-gendl-console.png, id=350, 318.52333pt x 212.52733pt>
File: ../images/genworks-gendl-console.png Graphic file (type png)
<use ../images/genworks-gendl-console.png>
......@@ -426,14 +426,14 @@ Overfull \hbox (16.66708pt too wide) in paragraph at lines 457--458
ys-tem, type: \OT1/cmtt/m/n/10.95 (ql:quickload :genworks-gdl)
[]
<../images/tasty-robot.png, id=340, 542.29266pt x 441.11467pt>
<../images/tasty-robot.png, id=370, 542.29266pt x 441.11467pt>
File: ../images/tasty-robot.png Graphic file (type png)
<use ../images/tasty-robot.png>
Package pdftex.def Info: ../images/tasty-robot.png used on input line 494.
(pdftex.def) Requested size: 216.81392pt x 216.8077pt.
<../images/tasty-robot-x3dom.png, id=341, 543.36333pt x 440.044pt>
<../images/tasty-robot-x3dom.png, id=371, 543.36333pt x 440.044pt>
File: ../images/tasty-robot-x3dom.png Graphic file (type png)
<use ../images/tasty-robot-x3dom.png>
......@@ -533,23 +533,38 @@ Missing character: There is no
Chapter 5.
[25
] [26
]
Overfull \hbox (6.79999pt too wide) in paragraph at lines 1483--1484
[][]
[]
[26] [27]
Overfull \hbox (6.79999pt too wide) in paragraph at lines 1569--1570
[][]
[]
[28]
Overfull \hbox (6.79999pt too wide) in paragraph at lines 1619--1620
[][]
[]
[29] [30]
Chapter 6.
[27] [28
[31
] [32
]
Chapter 7.
[29] [30
[33] [34
]
LaTeX Warning: Reference `subsec:usingquicklisp' on page 31 undefined on input
line 1374.
LaTeX Warning: Reference `subsec:usingquicklisp' on page 35 undefined on input
line 1700.
! Undefined control sequence.
l.1385 \textt
l.1711 \textt
{"3rdpty/"} directory are no longer needed or available. Instea...
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
......@@ -558,22 +573,21 @@ spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
LaTeX Warning: Reference `subsec:usingquicklisp' on page 31 undefined on input
line 1387.
[31] [32] (./tutorial.ind [33
LaTeX Warning: Reference `subsec:usingquicklisp' on page 35 undefined on input
line 1713.
[35] [36] (./tutorial.ind [37
])
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 1427.
Package atveryend Info: Empty hook `AfterLastShipout' on input line 1427.
Package atveryend Info: Empty hook `BeforeClearDocument' on input line 1753.
Package atveryend Info: Empty hook `AfterLastShipout' on input line 1753.
(./tutorial.aux)
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 1427.
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 1427.
Package atveryend Info: Executing hook `AtVeryEndDocument' on input line 1753.
Package atveryend Info: Executing hook `AtEndAfterFileList' on input line 1753.
Package rerunfilecheck Info: File `tutorial.out' has not changed.
(rerunfilecheck) Checksum: DAC915B09C329CD8B950F8D61F0015D3;3251.
(rerunfilecheck) Checksum: 4777542610533A3AB54CD2C5CE0EDB42;3706.
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
......@@ -581,16 +595,16 @@ LaTeX Font Warning: Some font shapes were not available, defaults substituted.
LaTeX Warning: There were undefined references.
Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 1427.
Package atveryend Info: Empty hook `AtVeryVeryEnd' on input line 1753.
)
Here is how much of TeX's memory you used:
6065 strings out of 494751
91176 string characters out of 3171015
172166 words of memory out of 3000000
9054 multiletter control sequences out of 15000+200000
6094 strings out of 494751
91646 string characters out of 3171015
172722 words of memory out of 3000000
9069 multiletter control sequences out of 15000+200000
12647 words of font info for 44 fonts, out of 3000000 for 9000
142 hyphenation exceptions out of 8191
29i,8n,28p,395b,526s stack positions out of 5000i,500n,10000p,200000b,50000s
29i,8n,28p,455b,526s stack positions out of 5000i,500n,10000p,200000b,50000s
{/opt/local/share/texmf-texlive-dist/fonts/enc/dvips/cm-super/cm-super-ts1.en
c}</opt/local/share/texmf-texlive-dist/fonts/type1/public/amsfonts/cm/cmbx10.pf
b></opt/local/share/texmf-texlive-dist/fonts/type1/public/amsfonts/cm/cmbx12.pf
......@@ -608,10 +622,10 @@ ocal/share/texmf-texlive-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb></opt/l
ocal/share/texmf-texlive-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb></opt/lo
cal/share/texmf-texlive-dist/fonts/type1/public/cm-super/sfrm0900.pfb></opt/loc
al/share/texmf-texlive-dist/fonts/type1/public/cm-super/sfrm1095.pfb>
Output written on tutorial.pdf (37 pages, 437482 bytes).
Output written on tutorial.pdf (41 pages, 457341 bytes).
PDF statistics:
645 PDF objects out of 1000 (max. 8388607)
578 compressed objects within 6 object streams
178 named destinations out of 1000 (max. 500000)
386 words of extra memory for PDF output out of 10000 (max. 10000000)
725 PDF objects out of 1000 (max. 8388607)
653 compressed objects within 7 object streams
192 named destinations out of 1000 (max. 500000)
434 words of extra memory for PDF output out of 10000 (max. 10000000)
......@@ -40,6 +40,12 @@
\BOOKMARK [2][-]{subsection.4.2.2}{Strings}{section.4.2}% 40
\BOOKMARK [2][-]{subsection.4.2.3}{Symbols}{section.4.2}% 41
\BOOKMARK [2][-]{subsection.4.2.4}{Lists}{section.4.2}% 42
\BOOKMARK [0][-]{chapter.5}{Understanding Gendl}{}% 43
\BOOKMARK [0][-]{chapter.6}{More Common Lisp for Gendl}{}% 44
\BOOKMARK [0][-]{chapter.7}{Advanced Gendl}{}% 45
\BOOKMARK [0][-]{chapter.5}{Understanding Gendl \204 Core GDL Syntax}{}% 43
\BOOKMARK [1][-]{section.5.1}{Defining a Working Package}{chapter.5}% 44
\BOOKMARK [1][-]{section.5.2}{Define-Object}{chapter.5}% 45
\BOOKMARK [1][-]{section.5.3}{Making Instances and Sending Messages}{chapter.5}% 46
\BOOKMARK [1][-]{section.5.4}{Objects}{chapter.5}% 47
\BOOKMARK [1][-]{section.5.5}{Sequences of Objects and Input-slots with a Default Expression}{chapter.5}% 48
\BOOKMARK [1][-]{section.5.6}{Summary}{chapter.5}% 49
\BOOKMARK [0][-]{chapter.6}{More Common Lisp for Gendl}{}% 50
\BOOKMARK [0][-]{chapter.7}{Advanced Gendl}{}% 51
......@@ -1333,9 +1333,335 @@ call \texttt{(+ 2 2)} evaluates to the number 4.
\chapter{Understanding Gendl}
\chapter{Understanding Gendl --- Core GDL Syntax}
\label{chap:understandinggendl}
\label{chap:understandinggendl---coregdlsyntax}
Now that you have a basic grasp of Common Lisp syntax (or, more accurately, \emph{lack} of syntax), we will jump directly into the Gendl framework. By using Gendl you can formulate most of
your engineering and computing problems in a natural way, without becoming bogged down in the complexity of
the Common Lisp Object System (CLOS).
The Gendl product is a commercially available KBE system
dual-licensed under the Affero Gnu Public License and a Proprietary
license. The core GDL language is a proposed standard for a
vendor-neutral KBE language.
As we mentioned in the previous chapter, Gendl is based on
and is a superset of ANSI Common Lisp. Because ANSI CL is an
unencumbered, open standard with several commercial and free
implementations, it is a good bet that applications written in it will
continue to function 50, 100, or even hundreds of years from now.
Note that the historical name of Gendl was ``GDL,'' and this name persists throughout the product
for example for naming Common Lisp packages.
\section{Defining a Working Package}
\label{sec:definingaworkingpackage}
In Common Lisp, \emph{packages} are a mechanism to separate symbols into
namespaces. Using packages it is possible to avoid naming collisions
in large projects. Consider this analogy: in the United States,
telephone numbers consist of a three-digit area code and a seven-digit
number. The same seven-digit number can occur in two or more separate
area codes, without causing a conflict.
The macro \texttt{gdl:define-package}is used to set up a new working package in Gendl.
Example:
\begin{verbatim}(gdl:define-package :yoyodyne)
\end{verbatim} will establish a new package called \texttt{:yoyodyne} which has all the Gendl operators available.
The \texttt{:gdl-user} package is an empty, pre-defined package for your use if
you do not wish to make a new package just for scratch work.
For real projects it is recommended that you make and work in your own
Gendl package, defined as above with \texttt{gdl:define-package}.
\emph{Notes for advanced users:}Packages defined with \texttt{gdl:define-package} will implicitly \emph{use} the \texttt{:gdl} package and the \texttt{:common-lisp} package, so you will have access to all exported symbols
in these packages without prefixing them with their package name.
You may extend this behavior, by calling \texttt{gdl:define-package} and adding additional packages to use with \texttt{(:use ...)}. For example, if you want to work in a package with access to GDL operators,
Common Lisp operators, and symbols from the \texttt{:cl-json} package \footnote{CL-JSON is a free third-party library for handling JSON format, a common data format used
for Internet applications.}, you could set it up as follows:
\begin{verbatim} (ql:quickload :cl-json)
(gdl:define-package :yoyodyne (:use :cl-json))
\end{verbatim}. the first form ensures that the cl-json code module is actually fetched and loaded. The second form
defines a package with the \texttt{:cl-json} operators available to it.
\section{Define-Object}
\label{sec:define-object}
\index{objects!defining}\emph{\index{Define-object}Define-object} is the basic macro for defining objects in GDL. An object
definition maps directly into a Lisp (CLOS) class definition.
The \texttt{define-object} macro takes three basic arguments:
\begin{itemize}
\item a \emph{name}, which is a symbol;
\item a \emph{\index{mixin-list}mixin-list}, which is a list of symbols naming other objects from which the current object
will inherit characteristics;
\item a \emph{\index{specification-plist}specification-plist}, which is spliced in (i.e.\ doesn't have its own surrounding
parentheses) after the mixin-list, and describes
the object model by specifying properties of the object (messages, contained objects, etc.)
The specification-plist typically makes up the bulk of the object definition.
\end{itemize}
Here are descriptions of the most common keywords making up the specification-plist:
\begin{description}
\item [\index{input-slots}input-slots]
specify information to be passed into the object instance when it is created.
\item [\index{computed-slots}computed-slots]
are really cached methods, with expressions to compute and return a value.
\item [\index{objects}objects]
specify other instances to be ``contained'' within this instance.
\item [\index{functions}functions]
are (uncached) functions ``of'' the object, i.e.\ they are actually methods which
discriminate on their first argument, which is the object instance upon which they are operating.
GDL functions can also take other non-specialized arguments, just like a normal CL function.
\end{description}
Figure
\ref{fig:object-hello} shows a simple example, which contains two input-slots, \texttt{first-name} and \texttt{last-name}, and a single computed-slot, \texttt{greeting}.
\begin{figure}
\begin{lrbox}{\boxedverb}
\begin{minipage}{\linewidth}
\begin{verbatim}
(define-object hello ()
:input-slots (first-name last-name)
:computed-slots
((greeting (format nil "Hello, ~a ~a!!"
(the first-name)
(the last-name)))))
\end{verbatim}
\end{minipage}
\end{lrbox}
\fbox{\usebox{\boxedverb}}
\caption{Example of Simple Object Definition}
\label{fig:object-hello}
\end{figure}
As you can see, a GDL Object is analogous in some ways to a \texttt{defun}, where the input-slots are like arguments to the function, and the computed-slots
are like return-values. But seen another way, each attribute in a GDL object is like a function in its own right.
The referencing macro \texttt{\index{the}the} shadows CL's \texttt{the} (which is a seldom-used type declaration operator). \texttt{The} in GDL is a macro which is used to reference the value of other messages
within the same object or within contained objects. In the above example, we are using \texttt{the} to refer to the values of the messages (input-slots) named \texttt{first-name} and \texttt{last-name}.
Note that messages used with \texttt{the} are given as symbols. These symbols are unaffected by the current Lisp \texttt{*package*}, so they can be specified either as plain unquoted symbols or as keyword
symbols (i.e.\ preceded by a colon), and the \texttt{the} macro will process them appropriately.
\section{Making Instances and Sending Messages}
\label{sec:makinginstancesandsendingmessages}
Once we have defined an object such as the example above, we can use
the constructor function \texttt{\index{make-object}make-object} in order to create an \emph{instance} of it. This function is very similar to the CLOS \texttt{\index{make-instance}make-instance} function. Here we create an instance of \texttt{hello} with specified values for \texttt{first-name} and \texttt{last-name} (the required input-slots), and assign this instance as the value of the symbol \texttt{my-instance}:
\begin{verbatim}
GDL-USER(16): (setq my-instance
(make-object 'hello :first-name "John"
:last-name "Doe"))
#<HELLO @ #x218f39c2>
\end{verbatim}As you can see, keyword symbols are used to ``tag'' the input values, and the return value is an instance of class \texttt{hello}. Now that we have an instance, we can use the macro \texttt{\index{the-object}the-object} to send messages to this instance:
\begin{verbatim}
GDL-USER(17): (the-object my-instance greeting)
"Hello, John Doe!!"
\end{verbatim}\texttt{The-object} is similar to \texttt{the}, but as its first argument it takes an expression which evaluates to an
object instance. \texttt{The}, by contrast, assumes that the object instance is the lexical variable \texttt{\index{self}self}, which is automatically set within the lexical context of a \texttt{define-object}.
Like \texttt{the}, \texttt{the-object} evaluates all but the first of its arguments as package-immune symbols,
so although keyword symbols may be used, this is not a requirement, and plain,
unquoted symbols will work just fine.
For convenience, you can also set \texttt{self} manually at the CL Command Prompt, and use \texttt{the} instead of \texttt{the-object} for referencing:
\begin{verbatim}
GDL-USER(18): (setq self
(make-object 'hello :first-name "John"
:last-name "Doe"))
#<HELLO @ #x218f406a>
GDL-USER(19): (the greeting)
"Hello, John Doe!!"
\end{verbatim}In actual fact, \texttt{(the ...)} simply expands into \texttt{(the-object self ...)}.
\section{Objects}
\label{sec:objects}
\index{objects}\index{containment!object}\index{objects!child}\index{objects!contained}The \texttt{:objects} keyword specifies a list of ``contained'' instances,
where each instance is considered to be a ``child'' object of the current
object. Each child object is of a specified type, which itself must be defined
with \texttt{define-object} before the child object can be instantiated.
Inputs to each instance are specified as a plist of keywords and
value expressions, spliced in after the object's name and type
specification. These inputs must match the inputs protocol (i.e.\ the input-slots)
of the object being instantiated. Figure
\ref{fig:object-city} shows an example of an object which contains some child objects.
\begin{figure}
\begin{lrbox}{\boxedverb}
\begin{minipage}{\linewidth}
\begin{verbatim}
(define-object city ()
:computed-slots
((total-water-usage (+ (the hotel water-usage)
(the bank water-usage))))
:objects
((hotel :type 'hotel
:size :large)
(bank :type 'bank
:size :medium)))
\end{verbatim}
\end{minipage}
\end{lrbox}
\fbox{\usebox{\boxedverb}}
\caption{Object Containing Child Objects}
\label{fig:object-city}
\end{figure}
In this example, \texttt{hotel} and \texttt{bank} are presumed to be already (or soon to be) defined as objects themselves,
which each answer the \texttt{water-usage} message. The \emph{\index{reference chains}reference chains}:
\begin{verbatim}(the hotel water-usage)
\end{verbatim} and
\begin{verbatim}(the bank water-usage)
\end{verbatim} provide the mechanism to access messages within the child object instances.
These child objects become instantiated \emph{on demand}, meaning that the first time these instances or any of their messages
are referenced, the actual instance will be created \emph{and} cached for future reference.
\begin{figure}
\begin{lrbox}{\boxedverb}
\begin{minipage}{\linewidth}
\begin{verbatim}
(defparameter *presidents-data*
'((:name
"Carter"
:term 1976)
(:name "Reagan"
:term 1980)
(:name "Bush"
:term 1988)
(:name "Clinton"
:term 1992)))
(define-object presidents-container ()
:input-slots
((data *presidents-data*))
:objects
((presidents :type 'president
:sequence (:size (length (the data)))
:name (getf (nth (the-child index) (the data)) :name)
:term (getf (nth (the-child index) (the data)) :term))))
\end{verbatim}
\end{minipage}
\end{lrbox}