source: tags/1.5.0/doc/manual/abcl.tex

Last change on this file was 15074, checked in by Mark Evenson, 7 years ago

Release as 1.5.0

File size: 66.4 KB
Line 
1% -*- mode: latex; -*-
2% http://en.wikibooks.org/wiki/LaTeX/
3\documentclass[10pt]{book}
4% also need to have cm-super installed for high quality rendering
5\usepackage[T1]{fontenc}
6\usepackage{abcl}
7
8\usepackage{hyperref} % Put this one last, it redefines lots of internals
9
10\begin{document}
11\title{Armed Bear Common Lisp User Manual}
12\date{Version 1.5.0\\
13\smallskip
14June 11, 2017}
15\author{Mark Evenson \and Erik H\"{u}lsmann \and Rudolf Schlatte \and
16  Alessio Stalla \and Ville Voutilainen}
17
18\maketitle
19
20\tableofcontents
21%%Preface to the Sixth edition, abcl-1.5.0
22\subsection{Preface to the Sixth Edition}
23
24With the sixth major release of the implementation, we make the
25following explicit revision of our compatibility to the underlying
26JVM.  Since we are an open source implementation, we insist on
27possible open access to the sources from with an JDK may both be built
28and run upon.  This requirement is no longer met by Java 5, so
29henceforth with the release of \textsc{ABCL} 1.5, we will support
30Java 6, Java 7 and Java 8 runtimes.
31
32%% We should probably not release a 1.5.0, go straight for abcl-1.6.0?
33%% Not worth the effort: Java 9 is the current abcl-1.6.0 release driver.
34
35%%Preface to the Fifth edition, abcl-1.4.0
36\subsection{Preface to the Fifth Edition}
37
38\textsc{ABCL} 1.4 consolidates eighteen months of production bugfixes,
39and substantially improves the support for invoking external
40processes via \code{SYS:RUN-PROGRAM}.
41
42%%Preface to the Fourth edition, abcl-1.3.
43\subsection{Preface to the Fourth Edition}
44
45\textsc{ABCL} 1.3 now implements an optimized implementation of the
46\code{org.armedbear.lisp.LispStack} abstraction thanks to Dmitry
47Nadezhin which runs on ORCL JVMs from 1.[5-8] conformantly.
48
49%%Preface to the Third edition, abcl-1.2.
50\subsection{Preface to the Third Edition}
51The implementation now contains a performant and conformant
52implementation of (A)MOP to the point of inclusion in CLOSER-MOP's
53test suite.
54
55%%Preface to the second edition, abcl-1.1.
56
57\subsection{Preface to the Second Edition}
58
59\textsc{ABCL} 1.1 now contains \textsc{(A)MOP}.  We hope you enjoy!  --The Mgmt.
60
61\chapter{Introduction}
62
63Armed Bear Common Lisp (\textsc{ABCL}) is an implementation of
64\textsc{Common Lisp} that runs on the Java Virtual Machine
65(\textsc{JVM}).  \textsc{ABCL} compiles \textsc{Common Lisp} to
66\textsc{Java} bytecode\footnote{The class file version is ``49.0''.},
67with an efficiency that varies on the hosting JVM implementation.
68\textsc{ABCL} supports running on the Java 6, Java 7, and Java 8
69\textsc{JVM} implementations.
70
71Armed Bear provides the following integration methods for interfacing
72with Java code and libraries:
73\begin{itemize}
74\item Lisp code can create Java objects and call their methods (see
75  Section~\ref{sec:lisp-java}, page~\pageref{sec:lisp-java}).
76\item Java code can call Lisp functions and generic functions, either
77  directly (Section~\ref{sec:calling-lisp-from-java},
78  page~\pageref{sec:calling-lisp-from-java}) or via \texttt{JSR-223}
79  (Section~\ref{sec:java-scripting-api},
80  page~\pageref{sec:java-scripting-api}).
81\item \code{jinterface-implementation} creates Lisp-side implementations
82  of Java interfaces that can be used as listeners for Swing classes and
83  similar.
84\item \code{java:jnew-runtime-class} can inject fully synthetic Java
85  classes--and their objects-- into the current JVM process whose
86  behavior is specified via closures expressed in \textsc{Common
87    Lisp}. \footnote{Parts of the current implementation are not fully
88    finished, so the status of some interfaces here should be treated
89    with skepticism if you run into problems.}
90
91\end{itemize}
92\textsc{ABCL} is supported by the Lisp library manager
93\textsc{QuickLisp}\footnote{\url{http://quicklisp.org/}} and can run many of the
94programs and libraries provided therein out-of-the-box.
95
96\section{Conformance}
97\label{section:conformance}
98
99\subsection{ANSI Common Lisp}
100\textsc{ABCL} is currently a (non)-conforming \textsc{ANSI} Common Lisp
101implementation due to the following known issues:
102
103\begin{itemize}
104\item The generic function signatures of the \code{CL:DOCUMENTATION} symbol
105  do not match the specification.
106\item The \code{CL:TIME} form does not return a proper \code{CL:VALUES}
107  environment to its caller.
108\item When merging pathnames and the defaults point to a \code{EXT:JAR-PATHNAME},
109  we set the \code{DEVICE} of the result to \code{:UNSPECIFIC} if the pathname to be
110  be merged does not contain a specified \code{DEVICE}, does not contain a
111  specified \code{HOST}, does contain a relative \code{DIRECTORY}, and we are
112  not running on a \textsc{MSFT} Windows platform.\footnote{The intent of this
113    rather arcane sounding deviation from conformance is so that the
114    result of a merge won't fill in a \code{DEVICE} with the wrong "default
115    device for the host" in the sense of the fourth paragraph in the
116    \textsc{CLHS} description of MERGE-PATHNAMES (see in \cite{CLHS} the paragraph beginning
117    "If the PATHNAME explicitly specifies a host and not a device
").
118    A future version of the implementation may return to conformance
119    by using the \code{HOST} value to reflect the type explicitly.
120  }
121
122\end{itemize}
123
124Somewhat confusingly, this statement of non-conformance in the
125accompanying user documentation fulfills the requirements that
126\textsc{ABCL} is a conforming ANSI Common Lisp implementation according
127to the Common Lisp HyperSpec~\cite{CLHS}.  Clarifications to this point
128are solicited.
129
130\textsc{ABCL} aims to be be a fully conforming \textsc{ANSI} Common Lisp implementation.
131Any other behavior should be reported as a bug.
132
133\subsection{Contemporary Common Lisp}
134In addition to \textsc{ANSI} conformance, \textsc{ABCL} strives to implement
135features expected of a contemporary \textsc{Common Lisp}, i.e. a Lisp of the
136post-2005 Renaissance.
137
138The following known problems detract from \textsc{ABCL} being a proper
139contemporary Common Lisp.
140\begin{itemize}
141\item An incomplete implementation of interactive debugging
142  mechanisms, namely a no-op version of \code{STEP}\footnote{Somewhat
143    surprisingly allowed by \textsc{ANSI}}, the inability to inspect
144  local variables in a given call frame, and the inability to resume a
145  halted computation at an arbitrarily selected call frame.
146\item Incomplete streams abstraction, in that \textsc{ABCL} needs a
147  suitable abstraction between \textsc{ANSI} and \textsc{Gray streams}
148  with a runtime switch for the beyond conforming
149  behavior\footnote{The streams could be optimized to the
150    \textsc{JVM} NIO \cite{nio} abstractions at great profit for
151    binary byte-level manipulations.}.
152\item Incomplete documentation: source code is missing docstrings from
153  all exported symbols from the \code{EXTENSIONS}, \code{SYSTEM},
154  \code{JAVA}, \code{MOP}, and \code{THREADS} packages.  This user
155  manual is currently in draft status.
156\end{itemize}
157
158
159
160\section{License}
161
162\textsc{ABCL} is licensed under the terms of the \textsc{GPL} v2 of
163June 1991 with an added ``classpath-exception'' clause (see the file
164\texttt{COPYING} in the source distribution\footnote{See
165  \url{http://abcl.org/svn/trunk/tags/1.5.0/COPYING}} for the license,
166term 13 in the same file for the classpath exception).  This license
167broadly means that you must distribute the sources to \textsc{ABCL},
168including any changes you make, together with a program that includes
169\textsc{ABCL}, but that you are not required to distribute the sources
170of the whole program.  Submitting your changes upstream to the \textsc{ABCL}
171development team is actively encouraged and very much appreciated, of
172course.
173
174\section{Contributors}
175
176\begin{itemize}
177\item Philipp Marek \texttt{Thanks for the markup, and review of the Manual}
178\item Douglas Miles \texttt{Thanks for the whacky IKVM stuff and keeping the flame alive
179  in the dark years.}
180\item Alan Ruttenberg \texttt{Thanks for JSS.}
181\item Olof-Joachim Frahm 
182\item piso
183\item and of course \emph{Peter Graves}
184\end{itemize}
185
186
187\chapter{Running ABCL}
188
189
190\textsc{ABCL} is packaged as a single jar file usually named either
191\texttt{abcl.jar} or possibly something like \texttt{abcl-1.5.0.jar} if
192using a versioned package on the local filesystem from your system
193vendor.  This jar file can be executed from the command line to obtain a
194\textsc{REPL}\footnote{Read-Eval Print Loop, a Lisp command-line}, viz:
195
196\index{REPL}
197
198\begin{listing-shell}
199  cmd$ java -jar abcl.jar
200\end{listing-shell} %$ unconfuse Emacs syntax highlighting
201
202\emph{N.b.} for the proceeding command to work, the \texttt{java}
203executable needs to be in your path.
204
205To facilitate the use of ABCL in tool chains such as SLIME~\cite{slime}
206(the Superior Lisp Interaction Mode for Emacs), we provide both a Bourne
207shell script and a \textsc{DOS} batch file.  If you or your
208administrator adjusted the path properly, ABCL may be executed simply
209as:
210
211\begin{listing-shell}
212  cmd$ abcl
213\end{listing-shell}%$
214
215Probably the easiest way of setting up an editing environment using the
216\textsc{Emacs} editor is to use \textsc{Quicklisp} and follow the instructions at
217\url{http://www.quicklisp.org/beta/#slime}.
218
219\section{Options}
220
221ABCL supports the following command line options:
222
223\index{Command Line Options}
224
225\begin{description}
226\item[\texttt{  --help}] displays a help message.
227\item[\texttt{  --noinform}] Suppresses the printing of startup information and banner.
228\item[\texttt{  --noinit}] suppresses the loading of the \verb+~/.abclrc+ startup file.
229\item[\texttt{  --nosystem}] suppresses loading the \texttt{system.lisp} customization file.
230\item[\texttt{  --eval FORM}] evaluates FORM before initializing the REPL.
231\item[\texttt{  --load FILE}] loads the file FILE before initializing the REPL.
232\item[\texttt{  --load-system-file FILE}] loads the system file FILE before initializing the REPL.
233\item[\texttt{  --batch}] evaluates forms specified by arguments and in
234  the initialization file \verb+~/.abclrc+, and then exits without
235  starting a \textsc{REPL}.
236\end{description}
237
238All of the command line arguments following the occurrence of \verb+--+
239are passed unprocessed into a list of strings accessible via the
240variable \code{EXT:*COMMAND-LINE-ARGUMENT-LIST*} from within ABCL.
241
242\section{Initialization}
243
244If the \textsc{ABCL} process is started without the \code{--noinit}
245flag, it attempts to load a file named \code{.abclrc} in the user's home
246directory and then interpret its contents.
247
248The user's home directory is determined by the value of the JVM system
249property \texttt{user.home}.  This value may or may not correspond
250to the value of the \texttt{HOME} system environment variable, at the
251discretion of the JVM implementation that \textsc{ABCL} finds itself
252hosted upon.
253
254\chapter{Interaction with the Hosting JVM}
255
256%  Plan of Attack
257%
258% describe calling Java from Lisp, and calling Lisp from Java,
259% probably in two separate sections.  Presumably, we can partition our
260% audience into those who are more comfortable with Java, and those
261% that are more comforable with Lisp
262
263The Armed Bear Common Lisp implementation is hosted on a Java Virtual
264Machine.  This chapter describes the mechanisms by which the
265implementation interacts with that hosting mechanism.
266
267\section{Lisp to Java}
268\label{sec:lisp-java}
269
270\textsc{ABCL} offers a number of mechanisms to interact with Java from its
271Lisp environment. It allows calling both instance and static methods
272of Java objects, manipulation of instance and static fields on Java
273objects, and construction of new Java objects.
274
275When calling Java routines, some values will automatically be
276converted by the FFI\footnote{Foreign Function Interface, is the term
277  of art for the part of a \textsc{Lisp} implementation which implements
278  calling code written in other languages, typically normalized to the
279  local C compiler calling conventions.}  from \textsc{Lisp} values to Java
280values. These conversions typically apply to strings, integers and
281floats. Other values need to be converted to their \textsc{Java} equivalents by
282the programmer before calling the Java object method. Java values
283returned to \textsc{Lisp} are also generally converted back to their Lisp
284counterparts. Some operators make an exception to this rule and do not
285perform any conversion; those are the ``raw'' counterparts of certain
286FFI functions and are recognizable by their name ending with
287\code{-RAW}.
288
289\subsection{Low-level Java API}
290
291This subsection covers the low-level API available after evaluating
292\code{(require :java)}.  A higher level \textsc{Java} API, developed by Alan
293Ruttenberg, is available in the \code{contrib/} directory and described
294later in this document, see Section~\ref{section:jss} on page
295\pageref{section:jss}.
296
297\subsubsection{Calling Java Object Methods}
298
299There are two ways to call a Java object method in the low-level (basic) API:
300
301\begin{itemize}
302\item Call a specific method reference (which was previously acquired)
303\item Dynamic dispatch using the method name and the call-specific
304  arguments provided by finding the best match (see
305  Section~\ref{sec:param-matching-for-ffi}).
306\end{itemize}
307
308\code{JAVA:JMETHOD} is used to acquire a specific method reference.  The
309function takes two or more arguments. The first is a Java class
310designator (a \code{JAVA:JAVA-CLASS} object returned by
311\code{JAVA:JCLASS} or a string naming a Java class). The second is a
312string naming the method.
313
314Any arguments beyond the first two should be strings naming Java
315classes, with one exception as listed in the next paragraph. These
316classes specify the types of the arguments for the method.
317
318When \code{JAVA:JMETHOD} is called with three parameters and the last
319parameter is an integer, the first method by that name and matching
320number of parameters is returned.
321
322Once a method reference has been acquired, it can be invoked using
323\code{JAVA:JCALL}, which takes the method as the first argument. The
324second argument is the object instance to call the method on, or
325\code{NIL} in case of a static method.  Any remaining parameters are
326used as the remaining arguments for the call.
327
328\subsubsection{Calling Java object methods: dynamic dispatch}
329
330The second way of calling Java object methods is by using dynamic dispatch.
331In this case \code{JAVA:JCALL} is used directly without acquiring a method
332reference first. In this case, the first argument provided to \code{JAVA:JCALL}
333is a string naming the method to be called. The second argument is the instance
334on which the method should be called and any further arguments are used to
335select the best matching method and dispatch the call.
336
337\subsubsection{Dynamic dispatch: Caveats}
338
339Dynamic dispatch is performed by using the Java reflection
340API\footnote{The Java reflection API is found in the
341  \code{java.lang.reflect} package}. Generally the dispatch works
342fine, but there are corner cases where the API does not correctly
343reflect all the details involved in calling a Java method. An example
344is the following Java code:
345
346\begin{listing-java}
347ZipFile jar = new ZipFile("/path/to/some.jar");
348Object els = jar.entries();
349Method method = els.getClass().getMethod("hasMoreElements");
350method.invoke(els);
351\end{listing-java}
352
353Even though the method \code{hasMoreElements()} is public in
354\code{Enumeration}, the above code fails with
355
356\begin{listing-java}
357java.lang.IllegalAccessException: Class ... can
358not access a member of class java.util.zip.ZipFile\$2 with modifiers
359"public"
360       at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
361       at java.lang.reflect.Method.invoke(Method.java:583)
362       at ...
363\end{listing-java}
364
365This is because the method has been overridden by a non-public class and
366the reflection API, unlike \texttt{javac}, is not able to handle such a case.
367
368While code like that is uncommon in Java, it is typical of ABCL's FFI
369calls. The code above corresponds to the following Lisp code:
370
371\begin{listing-lisp}
372(let ((jar (jnew "java.util.zip.ZipFile" "/path/to/some.jar")))
373  (let ((els (jcall "entries" jar)))
374    (jcall "hasMoreElements" els)))
375\end{listing-lisp}
376
377except that the dynamic dispatch part is not shown.
378
379To avoid such pitfalls, all Java objects in \textsc{ABCL} carry an extra
380field representing the ``intended class'' of the object. That class is
381used first by \code{JAVA:JCALL} and similar to resolve methods; the
382actual class of the object is only tried if the method is not found in
383the intended class. Of course, the intended class is always a
384super-class of the actual class -- in the worst case, they coincide. The
385intended class is deduced by the return type of the method that
386originally returned the Java object; in the case above, the intended
387class of \code{ELS} is \code{java.util.Enumeration} because that is the
388return type of the \code{entries} method.
389
390While this strategy is generally effective, there are cases where the
391intended class becomes too broad to be useful. The typical example
392is the extraction of an element from a collection, since methods in
393the collection API erase all types to \code{Object}. The user can
394always force a more specific intended class by using the \code{JAVA:JCOERCE}
395operator.
396
397% \begin{itemize}
398% \item Java values are accessible as objects of type JAVA:JAVA-OBJECT.
399% \item The Java FFI presents a Lisp package (JAVA) with many useful
400%   symbols for manipulating the artifacts of expectation on the JVM,
401%   including creation of new objects \ref{JAVA:JNEW}, \ref{JAVA:JMETHOD}), the
402%   introspection of values \ref{JAVA:JFIELD}, the execution of methods
403%   (\ref{JAVA:JCALL}, \ref{JAVA:JCALL-RAW}, \ref{JAVA:JSTATIC})
404% \item The JSS package (\ref{JSS}) in contrib introduces a convenient macro
405%   syntax \ref{JSS:SHARPSIGN_DOUBLEQUOTE_MACRO} for accessing Java
406%   methods, and additional convenience functions.
407% \item Java classes and libraries may be dynamically added to the
408%   classpath at runtime (JAVA:ADD-TO-CLASSPATH).
409% \end{itemize}
410
411\subsubsection{Calling Java class static methods}
412
413Like non-static methods, references to static methods can be acquired by
414using the \code{JAVA:JMETHOD} primitive. Static methods are called with
415\code{JAVA:JSTATIC} instead of \code{JAVA:JCALL}.
416
417Like \code{JAVA:JCALL}, \code{JAVA:JSTATIC} supports dynamic dispatch by
418passing the name of the method as a string instead of passing a method reference.
419The parameters should be values to pass in the function call instead of
420a specification of classes for each parameter.
421
422\subsubsection{Parameter matching for FFI dynamic dispatch}
423\label{sec:param-matching-for-ffi}
424
425The algorithm used to resolve the best matching method given the name
426and the arguments' types is the same as described in the Java Language
427Specification. Any deviation should be reported as a bug.
428
429% ###TODO reference to correct JLS section
430
431\subsubsection{Instantiating Java objects}
432
433\textsc{Java} objects can be instantiated (created) from \textsc{Lisp} by calling
434a constructor from the class of the object to be created. The
435\code{JAVA:JCONSTRUCTOR} primitive is used to acquire a constructor
436reference. Its arguments specify the types of arguments of the constructor
437method the same way as with \code{JAVA:JMETHOD}.
438
439The obtained constructor is passed as an argument to \code{JAVA:JNEW},
440together with any arguments.  \code{JAVA:JNEW} can also be invoked with
441a string naming the class as its first argument.
442
443\subsubsection{Accessing Java object and class fields}
444
445Fields in Java objects can be accessed using the getter and setter
446functions \code{JAVA:JFIELD} and \code{(SETF JAVA:JFIELD)}.  Static
447(class) fields are accessed the same way, but with a class object or
448string naming a class as first argument.
449
450Like \code{JAVA:JCALL} and friends, values returned from these accessors carry
451an intended class around, and values which can be converted to Lisp values will
452be converted.
453
454\section{Java to Lisp}
455
456This section describes the various ways that one interacts with \textsc{Lisp}
457from \textsc{Java} code.  In order to access the \textsc{Lisp} world from \textsc{Java}, one needs
458to be aware of a few things, the most important ones being listed below:
459
460\begin{itemize}
461\item All Lisp values are descendants of \code{LispObject}.
462\item Lisp symbols are accessible either via static members of the
463  \code{Symbol} class, or by dynamically introspecting a \code{Package}
464  object.
465\item The Lisp dynamic environment may be saved via
466  \code{LispThread.bindSpecial(Binding)} and restored via
467  \code{LispThread.resetSpecialBindings(Mark)}.
468\item Functions can be executed by invoking \code{LispObject.execute(args
469    [...])}
470\end{itemize}
471
472\subsection{Calling Lisp from Java}
473\label{sec:calling-lisp-from-java}
474
475Note: the entire \textsc{ABCL} \textsc{Lisp} system implementation in
476\textsc{Java} is resident in the \texttt{org.armedbear.lisp} package,
477but the following code snippets do not show the relevant import
478statements in the interest of brevity.  An example of the import
479statement would be
480\begin{listing-java}
481  import org.armedbear.lisp.*;
482\end{listing-java}
483to potentially import all the JVM symbol from the \code{org.armedbear.lisp}
484namespace.
485
486There can only ever be a single Lisp interpreter per \textsc{JVM} instance.  A
487reference to this interpreter is obtained by calling the static method
488\code{Interpreter.createInstance()}.
489
490\begin{listing-java}
491  Interpreter interpreter = Interpreter.createInstance();
492\end{listing-java}
493
494If this method has already been invoked in the lifetime of the current
495Java process it will return \texttt{null}, so if you are writing \textsc{Java}
496whose life-cycle is a bit out of your control (like in a \textsc{Java} servlet),
497a safer invocation pattern might be:
498
499\begin{listing-java}
500  Interpreter interpreter = Interpreter.getInstance();
501  if (interpreter == null) {
502    interpreter = Interpreter.createInstance();
503  }
504\end{listing-java}
505
506
507The Lisp \code{eval} primitive may simply be passed strings for evaluation:
508
509\begin{listing-java}
510  String line = "(load \"file.lisp\")";
511  LispObject result = interpreter.eval(line);
512\end{listing-java}
513
514Notice that all possible return values from an arbitrary Lisp
515computation are collapsed into a single return value.  Doing useful
516further computation on the \code{LispObject} depends on knowing what the
517result of the computation might be.  This usually involves some amount
518of \code{instanceof} introspection, and forms a whole topic to itself
519(see Section~\ref{topic:Introspecting a LispObject},
520page~\pageref{topic:Introspecting a LispObject}).
521
522Using \code{eval} involves the Lisp interpreter.  Lisp functions may
523also be directly invoked by Java method calls as follows.  One simply
524locates the package containing the symbol, obtains a reference to the
525symbol, and then invokes the \code{execute()} method with the desired
526parameters.
527
528\begin{listing-java}
529  interpreter.eval("(defun foo (msg)" +
530    "(format nil \"You told me '~A'~%\" msg))");
531  Package pkg = Packages.findPackage("CL-USER");
532  Symbol foo = pkg.findAccessibleSymbol("FOO");
533  Function fooFunction = (Function)foo.getSymbolFunction();
534  JavaObject parameter = new JavaObject("Lisp is fun!");
535  LispObject result = fooFunction.execute(parameter);
536  // How to get the "naked string value"?
537  System.out.println("The result was " + result.writeToString());
538\end{listing-java}
539
540If one is calling a function in the CL package, the syntax can become
541considerably simpler.  If we can locate the instance of definition in
542the ABCL Java source, we can invoke the symbol directly.  For instance,
543to tell if a \code{LispObject} is (Lisp) \texttt{NIL}, we can invoke the
544CL function \code{NULL} in the following way:
545
546
547\begin{listing-java}
548  boolean nullp(LispObject object) {
549    LispObject result = Primitives.NULL.execute(object);
550    if (result == NIL) { 
551      return false;
552    }
553    return true;
554 }
555\end{listing-java}
556
557Note, that the symbol \code{nil} is explicitly named in the
558\textsc{Java} namespace as \code{Symbol.NIL} but is always present in
559the local namespace in its unadorned form for the convenience of the
560User.
561
562\subsubsection{Multiple Values}
563
564After a call to a function that returns Lisp multiple values, the
565values are associated with the executing \code{LispThread} until the
566next call into Lisp.  One may access the values object as a list of
567\code{LispObject} instances via a call to \code{getValues()} on that
568thread reference
569as evidenced by the following code:
570
571\begin{listing-java}
572
573  org.armedbear.lisp.Package cl = Packages.findPackage("CL");
574  Symbol valuesSymbol = cl.findAccessibleSymbol("VALUES");
575  LispObject[] valuesArgs = {
576    LispInteger.getInstance(1), LispInteger.getInstance(2)
577  };
578  // equivalent to ``(values 1 2)''
579  LispObject result = valuesSymbol.execute(valuesArgs);
580  LispObject[] values = LispThread.currentThread().getValues();
581  for (LispObject value: values) {
582    System.out.println("value ==> " + value.printObject());
583  }
584\end{listing-java}
585
586\subsubsection{Introspecting a LispObject}
587\label{topic:Introspecting a LispObject}
588
589We present various patterns for introspecting an arbitrary
590\code{LispObject} which can hold the result of every Lisp evaluation
591into semantics that Java can meaningfully deal with.
592
593\paragraph{LispObject as \code{boolean}}
594
595If the \code{LispObject} is to be interpreted as a generalized boolean
596value, one can use \code{getBooleanValue()} to convert to Java:
597
598\begin{listing-java}
599   LispObject object = Symbol.NIL;
600   boolean javaValue = object.getBooleanValue();
601\end{listing-java}
602
603Since in Lisp any value other than \code{NIL} means "true", Java
604equality can also be used, which is a bit easier to type and better in
605terms of information it conveys to the compiler:
606
607\begin{listing-java}
608    boolean javaValue = (object != Symbol.NIL);
609\end{listing-java}
610
611\paragraph{LispObject as a list}
612
613If \code{LispObject} is a list, it will have the type \code{Cons}.  One
614can then use the \code{copyToArray} method to make things a bit more
615suitable for Java iteration.
616
617\begin{listing-java}
618  LispObject result = interpreter.eval("'(1 2 4 5)");
619  if (result instanceof Cons) {
620    LispObject array[] = ((Cons)result.copyToArray());
621    ...
622  }
623\end{listing-java}
624
625A more Lispy way to iterate down a list is to use the `cdr()` access
626function just as like one would traverse a list in Lisp:;
627
628\begin{listing-java}
629  LispObject result = interpreter.eval("'(1 2 4 5)");
630  while (result != Symbol.NIL) {
631    doSomething(result.car());
632    result = result.cdr();
633  }
634\end{listing-java}
635
636\section{Java Scripting API (JSR-223)}
637\label{sec:java-scripting-api}
638
639ABCL can be built with support for JSR-223~\cite{jsr-223}, which offers
640a language-agnostic API to invoke other languages from Java. The binary
641distribution download-able from ABCL's homepage is built with JSR-223
642support. If you're building ABCL from source on a pre-1.6 JVM, you need
643to have a JSR-223 implementation in your classpath (such as Apache
644Commons BSF 3.x or greater) in order to build ABCL with JSR-223 support;
645otherwise, this feature will not be built.
646
647This section describes the design decisions behind the ABCL JSR-223
648support. It is not a description of what JSR-223 is or a tutorial on
649how to use it. See
650\url{http://abcl.org/trac/browser/trunk/abcl/examples/jsr-223}
651for example usage.
652
653\subsection{Conversions}
654
655In general, ABCL's implementation of the JSR-223 API performs implicit
656conversion from Java objects to Lisp objects when invoking Lisp from
657Java, and the opposite when returning values from Java to Lisp. This
658potentially reduces coupling between user code and ABCL. To avoid such
659conversions, wrap the relevant objects in \code{JavaObject} instances.
660
661\subsection{Implemented JSR-223 interfaces}
662
663JSR-223 defines three main interfaces, of which two (\code{Invocable}
664and \code{Compilable}) are optional. ABCL implements all the three
665interfaces - \code{ScriptEngine} and the two optional ones - almost
666completely. While the JSR-223 API is not specific to a single scripting
667language, it was designed with languages with a more or less Java-like
668object model in mind: languages such as Javascript, Python, Ruby, which
669have a concept of "class" or "object" with "fields" and "methods". Lisp
670is a bit different, so certain adaptations were made, and in one case a
671method has been left unimplemented since it does not map at all to Lisp.
672
673\subsubsection{The ScriptEngine}
674
675The main interface defined by JSR-223, \code{javax.script.ScriptEngine},
676is implemented by the class
677\code{org.armedbear.lisp.scripting.AbclScriptEngine}. \code{AbclScriptEngine}
678is a singleton, reflecting the fact that ABCL is a singleton as
679well. You can obtain an instance of \code{AbclScriptEngine} using the
680\code{AbclScriptEngineFactory} or by using the service provider
681mechanism through \code{ScriptEngineManager} (refer to the
682\texttt{javax.script} documentation).
683
684\subsection{Start-up and configuration file}
685
686At start-up (i.e. when its constructor is invoked, as part of the
687static initialization phase of \code{AbclScriptEngineFactory}) the ABCL
688script engine attempts to load an "init file" from the classpath
689(\texttt{/abcl-script-config.lisp}). If present, this file can be used to
690customize the behavior of the engine, by setting a number of
691variables in the \code{ABCL-SCRIPT} package. Here is a list of the available
692variables:
693
694\begin{description}
695\item[\texttt{*use-throwing-debugger*}] controls whether ABCL uses a
696  non-standard debugging hook function to throw a Java exception
697  instead of dropping into the debugger in case of unhandled error
698  conditions.
699  \begin{itemize}
700  \item Default value: \texttt{T}
701  \item Rationale: it is more convenient for Java programmers using
702    Lisp as a scripting language to have it return exceptions to Java
703    instead of handling them in the Lisp world.
704  \item Known Issues: the non-standard debugger hook has been reported
705    to misbehave in certain circumstances, so consider disabling it if
706    it doesn't work for you.
707  \end{itemize}
708\item[\texttt{*launch-swank-at-startup*}] If true, Swank will be launched at
709  startup. See \texttt{*swank-dir*} and \texttt{*swank-port*}.
710  \begin{itemize}
711  \item Default value: \texttt{NIL}
712  \end{itemize}
713\item[\texttt{*swank-dir*}] The directory where Swank is installed. Must be set
714  if \texttt{*launch-swank-at-startup*} is true.
715\item[\texttt{*swank-port*}] The port where Swank will listen for
716  connections. Must be set if \texttt{*launch-swank-at-startup*} is
717  true.
718  \begin{itemize}
719  \item Default value: 4005
720  \end{itemize}
721\end{description}
722
723Additionally, at startup the AbclScriptEngine will \code{(require
724  'asdf)} - in fact, it uses asdf to load Swank.
725
726\subsection{Evaluation}
727
728Code is read and evaluated in the package \code{ABCL-SCRIPT-USER}. This
729packages \texttt{USE}s the \code{COMMON-LISP}, \code{JAVA} and
730\code{ABCL-SCRIPT} packages. Future versions of the script engine might
731make this default package configurable. The \code{CL:LOAD} function is
732used under the hood for evaluating code, and thus the behavior of
733\code{LOAD} is guaranteed. This allows, among other things,
734\code{IN-PACKAGE} forms to change the package in which the loaded code
735is read.
736
737It is possible to evaluate code in what JSR-223 calls a
738``ScriptContext'' (basically a flat environment of name$\rightarrow$value
739pairs). This context is used to establish special bindings for all the
740variables defined in it; since variable names are strings from Java's
741point of view, they are first interned using \code{READ-FROM-STRING} with, as
742usual, \code{ABCL-SCRIPT-USER} as the default package. Variables are declared
743special because CL's \code{LOAD}, \code{EVAL} and \code{COMPILE}
744functions work in a null lexical environment and would ignore
745non-special bindings.
746
747Contrary to what the function \code{LOAD} does, evaluation of a series
748of forms returns the value of the last form instead of T, so the
749evaluation of short scripts does the Right Thing.
750
751\subsection{Compilation}
752
753\code{AbclScriptEngine} implements the \code{javax.script.Compilable}
754interface. Currently it only supports compilation using temporary
755files. Compiled code, returned as an instance of
756\texttt{javax.script.CompiledScript}, is read, compiled and executed
757by default in the \code{abcl-script-user} package, just like evaluated
758code.  In contrast to evaluated code, though, due to the way the
759\textsc{ABCL} compiler works, compiled code contains no reference to
760top-level self-evaluating objects (like numbers or strings). Thus,
761when evaluated, a piece of compiled code will return the value of the
762last non-self-evaluating form: for example the code
763``\code{(do-something) 42}'' will return 42 when interpreted, but will
764return the result of (do-something) when compiled and later
765evaluated. To ensure consistency of behavior between interpreted and
766compiled code, make sure the last form is always a compound form - at
767least \code{(identity some-literal-object)}. Note that this issue
768should not matter in real code, where it is unlikely that a top-level
769self-evaluating form will appear as the last form in a file (in fact,
770the Common Lisp load function always returns \code{t} upon success;
771with \textsc{JSR-223} this policy has been changed to make evaluation
772of small code snippets work as intended).
773
774\subsection{Invocation of functions and methods}
775
776AbclScriptEngine implements the \code{javax.script.Invocable}
777interface, which allows to directly call Lisp functions and methods,
778and to obtain Lisp implementations of Java interfaces. This is only
779partially possible with Lisp since it has functions, but not methods -
780not in the traditional OO sense, at least, since Lisp methods are not
781attached to objects but belong to generic functions. Thus, the method
782\code{invokeMethod()} is not implemented and throws an
783\texttt{UnsupportedOperationException} when called. The \code{invokeFunction()}
784method should be used to call both regular and generic functions.
785
786\subsection{Implementation of Java interfaces in Lisp}
787
788ABCL can use the Java reflection-based proxy feature to implement Java
789interfaces in Lisp. It has several built-in ways to implement an
790interface, and supports definition of new ones. The
791\code{JAVA:JMAKE-PROXY} generic function is used to make such
792proxies. It has the following signature:
793
794\code{jmake-proxy interface implementation \&optional lisp-this ==> proxy}
795
796\code{interface} is a Java interface metaobject (e.g. obtained by
797invoking \code{jclass}) or a string naming a Java
798interface. \code{implementation} is the object used to implement the
799interface - several built-in methods of jmake-proxy exist for various
800types of implementations. \code{lisp-this} is an object passed to the
801closures implementing the Lisp "methods" of the interface, and
802defaults to \code{NIL}.
803
804The returned proxy is an instance of the interface, with methods
805implemented with Lisp functions.
806
807Built-in interface-implementation types include:
808
809\begin{itemize}
810\item a single Lisp function which, upon invocation of any method in
811  the interface, will be passed the method name, the Lisp-this object,
812  and all the parameters. Useful for interfaces with a single method,
813  or to implement custom interface-implementation strategies.
814\item a hash-map of method-name $\rightarrow$ Lisp function mappings. Function
815  signature is \code{(lisp-this \&rest args)}.
816\item a Lisp package. The name of the Java method to invoke is first
817  transformed in an idiomatic Lisp name (\code{javaMethodName} becomes
818  \code{JAVA-METHOD-NAME}) and a symbol with that name is searched in
819  the package. If it exists and is fbound, the corresponding function
820  will be called. Function signature is as the hash-table case.
821\end{itemize}
822
823This functionality is exposed by the class \code{AbclScriptEngine} via
824the two methods \code{getInterface(Class)} and
825\code{getInterface(Object, Class)}. The former returns an interface
826implemented with the current Lisp package, the latter allows the
827programmer to pass an interface-implementation object which will in turn
828be passed to the \code{jmake-proxy} generic function.
829
830\subsection{Implementation of Java classes in Lisp}
831
832See \code{JAVA:JNEW-RUNTIME-CLASS} in \ref{JAVA:JNEW-RUNTIME-CLASS}.
833
834
835\chapter{Implementation Dependent Extensions}
836
837As outlined by the \textsc{CLHS} \textsc{ANSI} conformance guidelines,
838we document the extensions to the Armed Bear Common Lisp implementation made
839accessible to the user by virtue of being an exported symbol in the
840\code{java}, \code{threads}, or \code{extensions} packages.
841
842\section{JAVA}
843
844\subsection{Modifying the JVM CLASSPATH}
845
846The \code{JAVA:ADD-TO-CLASSPATH} generic functions allows one to add the
847specified pathname or list of pathnames to the current classpath
848used by \textsc{ABCL}, allowing the dynamic loading of \textsc{JVM} objects:
849
850\begin{listing-lisp}
851CL-USER> (add-to-classpath "/path/to/some.jar")
852\end{listing-lisp}
853
854N.b \code{ADD-TO-CLASSPATH} only affects the classloader used by \textsc{ABCL}
855(the value of the special variable \code{JAVA:*CLASSLOADER*}. It has
856no effect on \textsc{Java} code outside \textsc{ABCL}.
857
858\subsection{Creating a synthetic Java Class at Runtime}
859
860See \code{JAVA:JNEW-RUNTIME-CLASS} on \ref{JAVA:JNEW-RUNTIME-CLASS}.
861
862% include autogen docs for the JAVA package.
863\include{java}
864
865\section{THREADS}
866
867The extensions for handling multithreaded execution are collected in
868the \code{THREADS} package.  Most of the abstractions in Doug Lea's
869excellent \code{java.util.concurrent} packages may be manipulated
870directly via the JSS contrib to great effect \cite{lea-1998}
871
872% include autogen docs for the THREADS package.
873\include{threads}
874
875\section{EXTENSIONS}
876
877The symbols in the \code{extensions} package (often referenced by its
878shorter nickname \code{ext}) constitutes extensions to the
879\textsc{ANSI} standard that are potentially useful to the user.  They
880include functions for manipulating network sockets, running external
881programs, registering object finalizers, constructing reference weakly
882held by the garbage collector and others.
883
884See \cite{RHODES2007} for a generic function interface to the native
885\textsc{JVM} contract for \code{java.util.List}.
886
887% include autogen docs for the EXTENSIONS package.
888\include{extensions}
889
890\chapter{Beyond ANSI}
891
892Naturally, in striving to be a useful contemporary \textsc{Common Lisp}
893implementation, \textsc{ABCL} endeavors to include extensions beyond the ANSI
894specification which are either widely adopted or are especially useful
895in working with the hosting \textsc{JVM}.
896
897\section{Compiler to Java 5 Bytecode}
898
899The \code{CL:COMPILE-FILE} interface emits a packed fasl format whose
900Pathname has the type  ``abcl''.  These fasls are operating system neutral
901byte archives packaged by the zip compression format which contain
902artifacts whose loading \code{CL:LOAD} understands.
903
904\section{Pathname}
905
906We implement an extension to the \code{CL:PATHNAME} that allows for
907the description and retrieval of resources named in a
908\textsc{URI} \footnote{A \textsc{URI} is essentially a superset of
909  what is commonly understood as a \textsc{URL} We sometime suse the
910  term URL as shorthand in describing the URL Pathnames, even though
911  the corresponding encoding is more akin to a URI as described in
912  RFC3986 \cite{rfc3986}.}  scheme that the \textsc{JVM}
913``understands''.  By definition, support is built-in into the JVM to
914access the ``http'' and ``https'' schemes but additional protocol
915handlers may be installed at runtime by having \textsc{JVM} symbols
916present in the \code{sun.net.protocol.dynamic} package. See
917\cite{maso2000} for more details.
918
919\textsc{ABCL} has created specializations of the ANSI
920\code{CL:PATHNAME} object to enable to use of \textsc{URI}s to address
921dynamically loaded resources for the JVM.  The \code{EXT:URL-PATHNAME}
922specialization has a corresponding \textsc{URI} whose canonical
923representation is defined to be the \code{NAMESTRING} of the
924\code{CL:PATHNAME}. The \code{EXT:JAR-PATHNAME} extension further
925specializes the the \code{EXT:URL-PATHNAME} to provide access to
926components of zip archives. 
927
928% RDF description of type hierarchy
929% TODO Render via some LaTeX mode for graphviz?
930\begin{verbatim}
931  @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
932  @prefix ext:   <http://abcl.org/cl/package/extensions/> .
933  @prefix cl:    <http://abcl.org/cl/package/common-lisp/> .
934 
935  <ext:jar-pathname>    rdfs:subClassOf <ext:url-pathname> .
936  <ext:url-pathname>    rdfs:subClassOf <cl:pathname> .
937  <cl:logical-pathname> rdfs:subClassOf <cl:pathname> .
938\end{verbatim}
939
940\label{EXTENSIONS:URL-PATHNAME}
941\index{URL-PATHNAME}
942
943\label{EXTENSIONS:JAR-PATHNAME}
944\index{JAR-PATHNAME}
945
946Both the \code{EXT:URL-PATHNAME} and \code{EXT:JAR-PATHNAME} objects
947may be used anywhere a \code{CL:PATHNAME} is accepted with the
948following caveats:
949
950\begin{itemize}
951
952\item A stream obtained via \code{CL:OPEN} on a \code{CL:URL-PATHNAME}
953  cannot be the target of write operations.
954
955\index{URI}
956\item Any results of canonicalization procedures performed on the
957  \textsc{URI} via local or network resolutions are discarded between
958  attempts (i.e. the implementation does not attempt to cache the
959  results of current name resolution of the URI for underlying
960  resource unless it is requested to be resolved.)  Upon resolution,
961  any canonicalization procedures followed in resolving the resource
962  (e.g. following redirects) are discarded.  Users may programatically
963  initiate a new, local computation of the resolution of the resource
964  by applying the \code{CL:TRUENAME} function to a
965  \code{EXT:URL-PATHNAME} object.  Depending on the reliability and
966  properties of your local \textsc{REST} infrastructure, these results
967  may not necessarily be idempotent over time\footnote {See
968    \cite{uri-pathname} for the design and implementation notes for
969    the technical details}.  A future implementation may attempt to
970  expose an API to observer/customize the content negotiation
971  initiated during retrieval of the representation of a given
972  resource, which is currently handled at the application level.
973
974\end{itemize}
975
976The implementation of \code{EXT:URL-PATHNAME} allows the \textsc{ABCL}
977user to dynamically load code from the network.  For example,
978\textsc{Quicklisp} (\cite{quicklisp}) may be completely installed from
979the \textsc{REPL} as the single form:
980
981\begin{listing-lisp}
982  CL-USER> (load "http://beta.quicklisp.org/quicklisp.lisp")
983\end{listing-lisp}
984
985will load and execute the Quicklisp setup code.
986
987The implementation currently breaks \textsc{ANSI} conformance by allowing the
988types able to be \code{CL:READ} for the \code{DEVICE} to return a possible \code{CONS} of
989\code{CL:PATHNAME} objects.  %% citation from CLHS needed.
990
991In order to ``smooth over'' the bit about types being \code{CL:READ}
992from \code{CL:PATHNAME} components, we extend the semantics for the
993usual PATHNAME merge semantics when \code{*DEFAULT-PATHNAME-DEFAULTS*}
994contains a \code{EXT:JAR-PATHNAME} with the ``do what I mean''
995algorithm described in \ref{section:conformance} on page
996\pageref{section:conformance}.
997
998%See \ref{_:quicklisp} on page \pageref{_:quicklisp}.
999
1000\subsubsection{Implementation}
1001
1002The implementation of these extensions stores all the additional
1003information in the \code{CL:PATHNAME} object itself in ways that while strictly
1004speaking are conformant, nonetheless may trip up libraries that don't
1005expect the following:
1006
1007\begin{itemize}
1008\item \code{DEVICE} can be either a string denoting a drive letter
1009  under \textsc{DOS} or a list of exactly one or two elements.  If
1010  \code{DEVICE} is a list, it denotes a \code{EXT:JAR-PATHNAME}, with
1011  the entries containing \code{CL:PATHNAME} objects which describe the
1012  outer and (possibly inner) locations of the jar
1013  archive \footnote{The case of inner and outer
1014    \code{EXT:JAR-PATHNAME} \ref{EXT:JAR-PATHNAME} arises when zip
1015    archives themselves contain zip archives which is the case when
1016    the ABCL fasl is included in the abcl.jar zip archive.}.
1017
1018\item A \code{EXT:URL-PATHNAME} always has a \code{HOST} component that is a
1019  property list.  The values of the \code{HOST} property list are
1020  always character strings.  The allowed keys have the following meanings:
1021  \begin{description}
1022  \item[:SCHEME] Scheme of URI ("http", "ftp", "bundle", etc.)
1023  \item[:AUTHORITY] Valid authority according to the URI scheme.  For
1024    "http" this could be "example.org:8080".
1025  \item[:QUERY] The query of the \textsc{URI} 
1026  \item[:FRAGMENT] The fragment portion of the \textsc{URI}
1027  \end{description}
1028
1029\item In order to encapsulate the implementation decisions for these
1030  meanings, the following functions provide a SETF-able API for
1031  reading and writing such values: \code{URL-PATHNAME-QUERY},
1032  \code{URL-PATHNAME-FRAGMENT}, \code{URL-PATHNAME-AUTHORITY}, and
1033  \code{URL-PATHNAME-SCHEME}.  The specific subtype of a Pathname may
1034  be determined with the predicates \code{PATHNAME-URL-P} and
1035  \code{PATHNAME-JAR-P}.
1036
1037\label{EXTENSIONS:URL-PATHNAME-SCHEME}
1038\index{URL-PATHNAME-SCHEME}
1039
1040\label{EXTENSIONS:URL-PATHNAME-FRAGMENT}
1041\index{URL-PATHNAME-FRAGMENT}
1042
1043\label{EXTENSIONS:URL-PATHNAME-AUTHORITY}
1044\index{URL-PATHNAME-AUTHORITY}
1045
1046\label{EXTENSIONS:PATHNAME-URL-P}
1047\index{PATHNAME-URL-P}
1048
1049\label{EXTENSIONS:URL-PATHNAME-QUERY}
1050\index{URL-PATHNAME-QUERY}
1051
1052\end{itemize}
1053
1054\section{Package-Local Nicknames}
1055\label{sec:pack-local-nickn}
1056
1057ABCL allows giving packages local nicknames: they allow short and
1058easy-to-use names to be used without fear of name conflict associated
1059with normal nicknames.\footnote{Package-local nicknames were originally
1060developed in SBCL.}
1061
1062A local nickname is valid only when inside the package for which it
1063has been specified. Different packages can use same local nickname for
1064different global names, or different local nickname for same global
1065name.
1066
1067Symbol \code{:package-local-nicknames} in \code{*features*} denotes the
1068support for this feature.
1069
1070\index{DEFPACKAGE}
1071The options to \code{defpackage} are extended with a new option
1072\code{:local-nicknames (local-nickname actual-package-name)*}.
1073
1074The new package has the specified local nicknames for the corresponding
1075actual packages.
1076
1077Example:
1078\begin{listing-lisp}
1079(defpackage :bar (:intern "X"))
1080(defpackage :foo (:intern "X"))
1081(defpackage :quux (:use :cl)
1082  (:local-nicknames (:bar :foo) (:foo :bar)))
1083(find-symbol "X" :foo) ; => FOO::X
1084(find-symbol "X" :bar) ; => BAR::X
1085(let ((*package* (find-package :quux)))
1086  (find-symbol "X" :foo))               ; => BAR::X
1087(let ((*package* (find-package :quux)))
1088  (find-symbol "X" :bar))               ; => FOO::X
1089\end{listing-lisp}
1090
1091\index{PACKAGE-LOCAL-NICKNAMES}
1092--- Function: \textbf{package-local-nicknames} [\textbf{ext}] \textit{package-designator}
1093
1094\begin{adjustwidth}{5em}{5em}
1095  Returns an ALIST of \code{(local-nickname . actual-package)}
1096  describing the nicknames local to the designated package.
1097
1098  When in the designated package, calls to \code{find-package} with any
1099  of the local-nicknames will return the corresponding actual-package
1100  instead. This also affects all implied calls to \code{find-package},
1101  including those performed by the reader.
1102
1103  When printing a package prefix for a symbol with a package local
1104  nickname, the local nickname is used instead of the real name in order
1105  to preserve print-read consistency.
1106\end{adjustwidth}
1107
1108\index{PACKAGE-LOCALLY-NICKNAMED-BY-LIST}
1109--- Function: \textbf{package-locally-nicknamed-by-list} [\textbf{ext}] \textit{package-designator}
1110
1111\begin{adjustwidth}{5em}{5em}
1112Returns a list of packages which have a local nickname for the
1113designated package.
1114\end{adjustwidth}
1115
1116\index{ADD-PACKAGE-LOCAL-NICKNAME}
1117--- Function: \textbf{add-package-local-nickname} [\textbf{ext}] \textit{local-nickname actual-package \&optional package-designator}
1118
1119\begin{adjustwidth}{5em}{5em}
1120  Adds \code{local-nickname} for \code{actual-package} in the designated
1121  package, defaulting to current package. \code{local-nickname} must be
1122  a string designator, and \code{actual-package} must be a package
1123  designator.
1124
1125  Returns the designated package.
1126
1127  Signals an error if \code{local-nickname} is already a package local
1128  nickname for a different package, or if \code{local-nickname} is one
1129  of "CL", "COMMON-LISP", or, "KEYWORD", or if \code{local-nickname} is
1130  a global name or nickname for the package to which the nickname would
1131  be added.
1132
1133  When in the designated package, calls to \code{find-package} with the
1134  \code{local-nickname} will return the package the designated
1135  \code{actual-package} instead. This also affects all implied calls to
1136  \code{find-package}, including those performed by the reader.
1137
1138  When printing a package prefix for a symbol with a package local
1139  nickname, local nickname is used instead of the real name in order to
1140  preserve print-read consistency.
1141\end{adjustwidth}
1142
1143\index{REMOVE-PACKAGE-LOCAL-NICKNAME}
1144--- Function: \textbf{remove-package-local-nickname} [\textbf{ext}] \textit{old-nickname \&optional package-designator}
1145
1146\begin{adjustwidth}{5em}{5em}
1147  If the designated package had \code{old-nickname} as a local nickname
1148  for another package, it is removed. Returns true if the nickname
1149  existed and was removed, and \code{nil} otherwise.
1150\end{adjustwidth}
1151
1152
1153         
1154\section{Extensible Sequences}
1155
1156The SEQUENCE package fully implements Christopher Rhodes' proposal for
1157extensible sequences.  These user extensible sequences are used
1158directly in \code{java-collections.lisp} provide these CLOS
1159abstractions on the standard Java collection classes as defined by the
1160\code{java.util.List} contract.
1161
1162
1163%% an Example of using java.util.Lisp in Lisp would be nice
1164
1165This extension is not automatically loaded by the implementation.   It
1166may be loaded via:
1167
1168\begin{listing-lisp}
1169CL-USER> (require :java-collections)
1170\end{listing-lisp}
1171
1172if both extensible sequences and their application to Java collections
1173is required, or
1174
1175\begin{listing-lisp}
1176CL-USER> (require :extensible-sequences)
1177\end{listing-lisp}
1178
1179if only the extensible sequences API as specified in \cite{RHODES2007} is
1180required.
1181
1182Note that \code{(require :java-collections)} must be issued before
1183\code{java.util.List} or any subclass is used as a specializer in a \textsc{CLOS}
1184method definition (see the section below).
1185
1186See Rhodes2007 \cite{RHODES2007} for the an overview of the
1187abstractions of the \code{java.util.collection} package afforded by
1188\code{JAVA-COLLECTIONS}.
1189
1190\section{Extensions to CLOS}
1191
1192\subsection{Metaobject Protocol}
1193
1194\textsc{ABCL} implements the metaobject protocol for \textsc{CLOS} as
1195specified in \textsc{(A)MOP}.  The symbols are exported from the
1196package \code{MOP}.
1197
1198Contrary to the AMOP specification and following \textsc{SBCL}'s lead,
1199the metaclass \code{funcallable-standard-object} has
1200\code{funcallable-standard-class} as metaclass instead of
1201\code{standard-class}.
1202
1203\textsc{ABCL}'s fidelity to the AMOP specification is codified as part
1204of Pascal Costanza's \code{closer-mop} \ref{closer-mop} \cite{closer-mop}.
1205
1206\subsection{Specializing on Java classes}
1207
1208There is an additional syntax for specializing the parameter of a
1209generic function on a java class, viz. \code{(java:jclass CLASS-STRING)}
1210where \code{CLASS-STRING} is a string naming a Java class in dotted package
1211form.
1212
1213For instance the following specialization would perhaps allow one to
1214print more information about the contents of a \code{java.util.Collection}
1215object
1216
1217\begin{listing-lisp}
1218(defmethod print-object ((coll (java:jclass "java.util.Collection"))
1219                         stream)
1220  ;;; ...
1221)
1222\end{listing-lisp}
1223
1224If the class had been loaded via a classloader other than the original
1225the class you wish to specialize on, one needs to specify the
1226classloader as an optional third argument.
1227
1228\begin{listing-lisp}
1229
1230(defparameter *other-classloader*
1231  (jcall "getBaseLoader" cl-user::*classpath-manager*))
1232 
1233(defmethod print-object
1234   ((device-id (java:jclass "dto.nbi.service.hdm.alcatel.com.NBIDeviceID"
1235                            *other-classloader*))
1236    stream)
1237  ;;; ...
1238)
1239\end{listing-lisp}
1240
1241\section{Extensions to the Reader}
1242
1243We implement a special hexadecimal escape sequence for specifying 32
1244bit characters to the Lisp reader\footnote{This represents a
1245  compromise with contemporary in 2011 32bit hosting architecures for
1246  which we wish to make text processing efficient.  Should the User
1247  require more control over \textsc{UNICODE} processing we recommend Edi Weisz'
1248  excellent work with \textsc|{FLEXI-STREAMS}  which we fully support}, namely we
1249allow a sequences of the form \verb~#\U~\emph{\texttt{xxxx}} to be processed
1250by the reader as character whose code is specified by the hexadecimal
1251digits \emph{\texttt{xxxx}}.  The hexadecimal sequence may be one to four digits
1252long.
1253
1254% Why doesn't ALEXANDRIA work?  Good question: Alexandria from
1255% Quicklisp 2010-10-07 fails a number of tests:
1256%% Form: (ALEXANDRIA.0.DEV:TYPE= 'LIST '(OR NULL CONS))
1257%% Expected values: T
1258%%                  T
1259%% Actual values: NIL
1260%%                T.
1261%% Test ALEXANDRIA-TESTS::TYPE=.3 failed
1262%% Form: (ALEXANDRIA.0.DEV:TYPE= 'NULL '(AND SYMBOL LIST))
1263%% Expected values: T
1264%%                  T
1265%% Actual values: NIL
1266%%                NIL.
1267
1268
1269Note that this sequence is never output by the implementation.  Instead,
1270the corresponding Unicode character is output for characters whose
1271code is greater than 0x00ff.
1272
1273\section{Overloading of the CL:REQUIRE Mechanism}
1274
1275The \code{CL:REQUIRE} mechanism is overloaded by attaching these
1276semantics to the execution of \code{REQUIRE} on the following symbols:
1277
1278\begin{description}
1279
1280  \item{\code{ASDF}} 
1281    Loads the \textsc{ASDF} implementation shipped
1282    with the implementation.  After \textsc{ASDF} has been loaded in
1283    this manner, symbols passed to \code{CL:REQUIRE} which are
1284    otherwise unresolved, are passed to ASDF for a chance for
1285    resolution.  This means, for instance if \code{CL-PPCRE} can be
1286    located as a loadable \textsc{ASDF} system \code{(require
1287      :cl-ppcre)} is equivalent to \code{(asdf:load-system
1288      :cl-ppcre)}.
1289
1290  \item{\code{ABCL-CONTRIB}} 
1291    Locates and pushes the toplevel contents of
1292    ``abcl-contrib.jar'' into the \textsc{ASDF} central registry. 
1293
1294    \begin{enumerate}
1295      \item \code{abcl-asdf} 
1296        Functions for loading JVM artifacts
1297        dynamically, hooking into ASDF 3 objects where possible.
1298      \item \code{asdf-jar} 
1299        Package addressable JVM artifacts via
1300        \code{abcl-asdf} descriptions as a single binary artifact
1301        including recursive dependencies.
1302      \item \code{mvn} 
1303        These systems name common JVM artifacts from
1304        the distributed pom.xml graph of Maven Aether:
1305        \begin{enumerate}
1306          \item \code{jna} 
1307            Dynamically load 'jna.jar' version 4.2.2
1308            from the network \footnote{This loading can be inhibited
1309              if, at runtime, the Java class corresponding
1310              ``:classname'' clause of the system defition is present.}
1311        \end{enumerate}
1312      \item \code{quicklisp-abcl} Boot a local Quicklisp installation
1313        via the ASDF:IRI type introduced via ABCL-ASDF.
1314
1315      \item \code{jfli} A descendent of Rich Hickey's pre-Clojure work
1316        on the JVM.
1317      \item \code{jss} Introduces dynamic inspection of present
1318        symbols via the \code{SHARPSIGN-QUOTATION\_MARK} macros as Java Syntax
1319        Sucks
1320      \item \code{abcl-introspect} Provides a framework for
1321        introspecting runtime Java and Lisp object values.
1322      \item \code{abcl-build} Provides a toolkit for building ABCL
1323        from source, as well as installing the necessary tools for
1324        such builds.
1325       
1326\end{enumerate}
1327
1328\end{description}
1329
1330The user may extend the \code{CL:REQUIRE} mechanism by pushing
1331function hooks into \code{SYSTEM:*MODULE-PROVIDER-FUNCTIONS*}.  Each
1332such hook function takes a single argument containing the symbol
1333passed to \code{CL:REQUIRE} and returns a non-\code{NIL} value if it
1334can successful resolve the symbol.
1335
1336\section{JSS extension of the Reader by SHARPSIGN-DOUBLE-QUOTE}
1337
1338The JSS contrib consitutes an additional, optional extension to the
1339reader in the definition of the \code{SHARPSIGN-DOUBLE-QUOTE}
1340(``\#\"'') reader macro.  See section \ref{section:jss} on page
1341\pageref{section:jss} for more information.
1342
1343\section{ASDF}
1344
1345asdf-3.2.1 (see \cite{asdf}) is packaged as core component of \textsc{ABCL},
1346but not initialized by default, as it relies on the \textsc{CLOS} subsystem
1347which can take a bit of time to start \footnote{While this time is
1348  ``merely'' on the order of seconds for contemporary 2011 machines,
1349  for applications that need to initialize quickly, for example a web
1350  server, this time might be unnecessarily long}.  The packaged \textsc{ASDF}
1351may be loaded by the \textsc{ANSI} \code{REQUIRE} mechanism as
1352follows:
1353
1354\begin{listing-lisp}
1355CL-USER> (require :asdf)
1356\end{listing-lisp}
1357
1358\chapter{Contrib}
1359
1360The \textsc{ABCL} contrib is packaged as a separate jar archive usually named
1361\code{abcl-contrib.jar} or possibly something like
1362\code{abcl-contrib-1.5.0.jar}.  The contrib jar is not loaded by the
1363implementation by default, and must be first intialized by the
1364\code{REQUIRE} mechanism before using any specific contrib:
1365
1366\begin{listing-lisp}
1367CL-USER> (require :abcl-contrib)
1368\end{listing-lisp}
1369
1370\section{abcl-asdf}
1371
1372This contrib enables an additional syntax for \textsc{ASDF} system
1373definition which dynamically loads \textsc{JVM} artifacts such as jar
1374archives via encapsulation of the Maven build tool.  The Maven Aether
1375component can also be directly manipulated by the function associated
1376with the \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} symbol.
1377
1378%ABCL specific contributions to ASDF system definition mainly
1379%concerned with finding JVM artifacts such as jar archives to be
1380%dynamically loaded.
1381
1382
1383When loaded, abcl-asdf adds the following objects to \textsc{ASDF}:
1384\code{JAR-FILE}, \code{JAR-DIRECTORY}, \code{CLASS-FILE-DIRECTORY} and
1385\code{MVN}, exporting them (and others) as public symbols.
1386
1387\subsection{Referencing Maven Artifacts via ASDF}
1388
1389Maven artifacts may be referenced within \textsc{ASDF} system
1390definitions, as the following example references the
1391\code{log4j-1.4.9.jar} JVM artifact which provides a widely-used
1392abstraction for handling logging systems:
1393
1394\begin{listing-lisp}
1395  ;;;; -*- Mode: LISP -*-
1396  (require :asdf)
1397  (in-package :cl-user)
1398
1399  (asdf:defsystem :log4j
1400     :defsystem-depends-on (abcl-asdf)
1401     :components ((:mvn "log4j/log4j" :version "1.4.9")))
1402\end{listing-lisp}
1403
1404\subsection{API}
1405
1406We define an API for \textsc{ABCL-ASDF} as consisting of the following
1407ASDF classes:
1408
1409\code{JAR-DIRECTORY}, \code{JAR-FILE}, and
1410\code{CLASS-FILE-DIRECTORY} for JVM artifacts that have a currently
1411valid pathname representation.
1412
1413Both the \code{MVN} and \code{IRI} classes descend from
1414\code{ASDF-COMPONENT}, but do not directly have a filesystem location.
1415
1416For use outside of ASDF system definitions, we currently define one
1417method, \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} which locates,
1418downloads, caches, and then loads into the currently executing JVM
1419process all recursive dependencies annotated in the Maven pom.xml
1420graph.
1421
1422\subsection{Directly Instructing Maven to Download JVM Artifacts}
1423
1424Bypassing \textsc{ASDF}, one can directly issue requests for the Maven
1425artifacts to be downloaded
1426
1427\begin{listing-lisp}
1428CL-USER> (abcl-asdf:resolve-dependencies "com.google.gwt"
1429                                         "gwt-user")
1430WARNING: Using LATEST for unspecified version.
1431"/Users/evenson/.m2/repository/com/google/gwt/gwt-user/2.4.0-rc1
1432/gwt-user-2.4.0-rc1.jar:/Users/evenson/.m2/repository/javax/vali
1433dation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/User
1434s/evenson/.m2/repository/javax/validation/validation-api/1.0.0.G
1435A/validation-api-1.0.0.GA-sources.jar"
1436\end{listing-lisp}
1437
1438To actually load the dependency, use the \code{JAVA:ADD-TO-CLASSPATH} generic
1439function:
1440
1441\begin{listing-lisp}
1442CL-USER> (java:add-to-classpath
1443          (abcl-asdf:resolve-dependencies "com.google.gwt"
1444                                          "gwt-user"))
1445\end{listing-lisp}
1446
1447Notice that all recursive dependencies have been located and installed
1448locally from the network as well.
1449
1450More extensive documentations and examples can be found at
1451\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-asdf/README.markdown}.
1452
1453\section{asdf-jar}
1454
1455The asdf-jar contrib provides a system for packaging \textsc{ASDF}
1456systems into jar archives for \textsc{ABCL}.  Given a running
1457\textsc{ABCL} image with loadable \textsc{ASDF} systems the code in
1458this package will recursively package all the required source and
1459fasls in a jar archive.
1460
1461The documentation for this contrib can be found at
1462\url{http://abcl.org/svn/tags/1.5.0/contrib/asdf-jar/README.markdown}.
1463
1464\section{jss}
1465\label{section:jss}
1466
1467To one used to the more universal syntax of Lisp pairs upon which the
1468definition of read and compile time macros is quite
1469natural \footnote{See Graham's ``On Lisp''
1470  http://lib.store.yahoo.net/lib/paulgraham/onlisp.pdf.}, the Java
1471syntax available to the Java programmer may be said to suck.  To
1472alleviate this situation, the JSS contrib introduces the
1473\code{SHARPSIGN-DOUBLE-QUOTE} (\code{\#"}) reader macro, which allows
1474the the specification of the name of invoking function as the first
1475element of the relevant s-expr which tends to be more congruent to how
1476Lisp programmers seem to be wired to think.
1477
1478While quite useful, we don't expect that the JSS contrib will be the
1479last experiment in wrangling Java from Common Lisp.
1480
1481\subsection{JSS usage}
1482
1483Example:
1484
1485\begin{listing-lisp}
1486CL-USER> (require :abcl-contrib)
1487==> ("ABCL-CONTRIB")
1488CL-USER> (require :jss)
1489==> ("JSS")
1490CL-USER) (#"getProperties" 'java.lang.System)
1491==> #<java.util.Properties {java.runtime.name=Java.... {2FA21ACF}>
1492CL-USER) (#"propertyNames" (#"getProperties" 'java.lang.System))
1493==> #<java.util.Hashtable$Enumerator java.util.Has.... {36B4361A}>
1494\end{listing-lisp} %$ <-- un-confuse Emacs font-lock
1495
1496Some more information on jss can be found in its documentation at
1497\url{http://abcl.org/svn/tags/1.5.0/contrib/jss/README.markdown}
1498
1499\section{jfli}
1500\label{section:jfli}
1501
1502The contrib contains a pure-Java version of JFLI.
1503
1504\url{http://abcl.org/svn/tags/1.5.0/contrib/jfli/README}.
1505
1506\section{abcl-introspect}
1507
1508\textsc{ABCL-INTROSPECT} offers more extensive systems for inspecting the state
1509of the implementation, most notably in integration with SLIME, where
1510the backtrace mechanism is augmented to the poiont that local
1511variables are inspectable.
1512
1513A compiled function is an instance of a class - This class has
1514multiple instances if it represents a closure, or a single instance if
1515it represents a non-closed-over function.
1516
1517The \textsc{ABCL} compiler stores constants that are used in function
1518execution as private java fields. This includes symbols used to invoke
1519function, locally-defined functions (such as via \code{LABEL} or
1520\code{flet}) and string and other literal objects.
1521\textsc{ABCL-INTROSPECT} implements a ``do what I mean'' API for
1522introspecting these constants.
1523
1524ABCL-INTROSPECT provides access to those internal values, and
1525uses them in at least two ways. First, to annotate locally defined
1526functions with the top-level function they are defined within, and
1527second to search for callers of a give function \footnote{ Since java
1528  functions are strings, local fields also have these strings. In the
1529  context of looking for callers of a function you can also give a
1530  string that names a java method. Same caveat re: false positives.}
1531. This may yield some false positives, such as when a symbol that
1532names a function is also used for some other purpose. It can also have
1533false negatives, as when a function is inlined. Still, it's pretty
1534useful. The second use to to find source locations for frames in the
1535debugger. If the source location for a local function is asked for the
1536location of its 'owner' is instead returns.
1537
1538In order to record information about local functions, ABCL defines a
1539function-plist, which is for the most part unused, but is used here
1540with set of keys indicating where the local function was defined and
1541in what manner, i.e. as normal local function, as a method function,
1542or as an initarg function. There may be other places functions are
1543stashed away (defstructs come to mind) and this file should be added
1544to to take them into account as they are discovered.
1545
1546ABCL-INTROSPECT does not depend on jss, but provides a bit of
1547jss-specific functionality if jss *is* loaded.
1548
1549\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-introspect/}.
1550
1551\section{abcl-build}
1552
1553\textsc{ABCL-BUILD} constitutes a new implementation for the original
1554Lisp-hosted ABCL build system API in the package \code{ABCL-BUILD}
1555that uses the same build artifacts as all of the other current builds.
1556
1557\subsection{Utilities}
1558
1559\textsc{ABCL-BUILD} consolidates various utilities that are useful
1560for system construction, namely
1561\begin{itemize}
1562
1563\item The ability to introspect the invocation of given executable in
1564  the current implementation process PATH.
1565
1566\item Downloading and unpackages selected JVM artifacts, namely the
1567  Ant and Maven build tools.  The \code{ABCL-BUILD:WITH-ANT} and
1568  \code{ABCL-BUILD:WITH-MVN} macros abstracts this installation
1569  procedure conveniently away from the User.
1570
1571\item The beginings of a generic framework to download arbitrary
1572    archives from the network.
1573\end{itemize}
1574
1575\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-build/}.
1576
1577\section{named-readtables}
1578
1579\code{NAMED-READTABLES} is a library that provides a namespace for
1580readtables akin to the already-existing namespace of packages.
1581
1582\url{https://github.com/melisgl/named-readtables/}.
1583\url{http://abcl.org/svn/tags/1.5.0/contrib/named-readtables/}.
1584
1585\chapter{History}
1586\index{History}
1587
1588\textsc{ABCL} was originally the extension language for the J editor, which was
1589started in 1998 by Peter Graves.  Sometime in 2003, a whole lot of
1590code that had previously not been released publically was suddenly
1591committed that enabled ABCL to be plausibly termed an emergent ANSI
1592Common Lisp implementation candidate.
1593
1594From 2006 to 2008, Peter manned the development lists, incorporating
1595patches as made sense.  After a suitable search, Peter nominated Erik
1596H\"{u}lsmann to take over the project.
1597
1598In 2008, the implementation was transferred to the current
1599maintainers, who have strived to improve its usability as a
1600contemporary Common Lisp implementation.
1601
1602On October 22, 2011, with the publication of this Manual explicitly
1603stating the conformance of Armed Bear Common Lisp to \textsc{ANSI}, we
1604released abcl-1.0.0.  We released abcl-1.0.1 as a maintainence release
1605on January 10, 2012.
1606
1607In December 2012, we revised the implementation by adding
1608\textsc{(A)MOP} with the release of abcl-1.1.0.  We released
1609abcl-1.1.1 as a maintainence release on Feburary 14, 2013.
1610
1611At the beginning of June 2013, we enhanced the stability of the
1612implementation with the release of abcl-1.2.1.
1613
1614In March 2014, we introduced the Fourth Edition of the implementation
1615with abcl-1.3.0.  At the end of April 2014, we released abcl-1.3.1 as
1616a maintainence release.
1617
1618In October 2016 we blessed the current \textsc{svn} trunk
1619\url{http://abcl.org/svn/trunk/} as 1.4.0, which includes the
1620community contributions from Vihbu, Olof, Pipping, and Cyrus.  We
1621gingerly stepped into current century by establishing \textsc{git}
1622bridges to the source repository at
1623\url{https://github.com/easye/abcl/} and
1624\url{https://gitlab.common-lisp.net/abcl/abcl/} so that pull
1625requests for enhancements to the implementation many be more easily
1626facilitated.
1627
1628In June 2017, we released ABCL 1.5.0 which dropped support for running
1629upon Java 5.
1630
1631\appendix 
1632
1633\chapter{The MOP Dictionary}
1634
1635\include{mop}
1636
1637\chapter{The SYSTEM Dictionary}
1638
1639The public interfaces in this package are subject to change with
1640\textsc{ABCL} 1.6.
1641
1642\include{system}
1643
1644\chapter{The JSS Dictionary}
1645
1646These public interfaces are provided by the JSS contrib.
1647
1648\include{jss}
1649
1650\bibliography{abcl}
1651\bibliographystyle{alpha}
1652
1653\printindex
1654
1655\end{document}
Note: See TracBrowser for help on using the repository browser.