source: trunk/abcl/doc/manual/abcl.tex @ 15122

Last change on this file since 15122 was 15122, checked in by Mark Evenson, 5 years ago

Update metadata for asdf version

File size: 66.7 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.6.0-dev\\
13\smallskip
14June 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\subsection{Compiler Diagnostics}
905
906By default, the interface to the compiler does not signal warnings
907that result in its invocation, outputing diagnostics to the standard
908reporting stream.  The generalized boolean
909\code{JVM:*RESIGNAL-COMPILER-WARNINGS*} provides the interface to
910enabling the compiler to signal all warnings.
911
912
913\section{Pathname}
914
915We implement an extension to the \code{CL:PATHNAME} that allows for
916the description and retrieval of resources named in a
917\textsc{URI} \footnote{A \textsc{URI} is essentially a superset of
918  what is commonly understood as a \textsc{URL} We sometime suse the
919  term URL as shorthand in describing the URL Pathnames, even though
920  the corresponding encoding is more akin to a URI as described in
921  RFC3986 \cite{rfc3986}.}  scheme that the \textsc{JVM}
922``understands''.  By definition, support is built-in into the JVM to
923access the ``http'' and ``https'' schemes but additional protocol
924handlers may be installed at runtime by having \textsc{JVM} symbols
925present in the \code{sun.net.protocol.dynamic} package. See
926\cite{maso2000} for more details.
927
928\textsc{ABCL} has created specializations of the ANSI
929\code{CL:PATHNAME} object to enable to use of \textsc{URI}s to address
930dynamically loaded resources for the JVM.  The \code{EXT:URL-PATHNAME}
931specialization has a corresponding \textsc{URI} whose canonical
932representation is defined to be the \code{NAMESTRING} of the
933\code{CL:PATHNAME}. The \code{EXT:JAR-PATHNAME} extension further
934specializes the the \code{EXT:URL-PATHNAME} to provide access to
935components of zip archives. 
936
937% RDF description of type hierarchy
938% TODO Render via some LaTeX mode for graphviz?
939\begin{verbatim}
940  @prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
941  @prefix ext:   <http://abcl.org/cl/package/extensions/> .
942  @prefix cl:    <http://abcl.org/cl/package/common-lisp/> .
943 
944  <ext:jar-pathname>    rdfs:subClassOf <ext:url-pathname> .
945  <ext:url-pathname>    rdfs:subClassOf <cl:pathname> .
946  <cl:logical-pathname> rdfs:subClassOf <cl:pathname> .
947\end{verbatim}
948
949\label{EXTENSIONS:URL-PATHNAME}
950\index{URL-PATHNAME}
951
952\label{EXTENSIONS:JAR-PATHNAME}
953\index{JAR-PATHNAME}
954
955Both the \code{EXT:URL-PATHNAME} and \code{EXT:JAR-PATHNAME} objects
956may be used anywhere a \code{CL:PATHNAME} is accepted with the
957following caveats:
958
959\begin{itemize}
960
961\item A stream obtained via \code{CL:OPEN} on a \code{CL:URL-PATHNAME}
962  cannot be the target of write operations.
963
964\index{URI}
965\item Any results of canonicalization procedures performed on the
966  \textsc{URI} via local or network resolutions are discarded between
967  attempts (i.e. the implementation does not attempt to cache the
968  results of current name resolution of the URI for underlying
969  resource unless it is requested to be resolved.)  Upon resolution,
970  any canonicalization procedures followed in resolving the resource
971  (e.g. following redirects) are discarded.  Users may programatically
972  initiate a new, local computation of the resolution of the resource
973  by applying the \code{CL:TRUENAME} function to a
974  \code{EXT:URL-PATHNAME} object.  Depending on the reliability and
975  properties of your local \textsc{REST} infrastructure, these results
976  may not necessarily be idempotent over time\footnote {See
977    \cite{uri-pathname} for the design and implementation notes for
978    the technical details}.  A future implementation may attempt to
979  expose an API to observer/customize the content negotiation
980  initiated during retrieval of the representation of a given
981  resource, which is currently handled at the application level.
982
983\end{itemize}
984
985The implementation of \code{EXT:URL-PATHNAME} allows the \textsc{ABCL}
986user to dynamically load code from the network.  For example,
987\textsc{Quicklisp} (\cite{quicklisp}) may be completely installed from
988the \textsc{REPL} as the single form:
989
990\begin{listing-lisp}
991  CL-USER> (load "http://beta.quicklisp.org/quicklisp.lisp")
992\end{listing-lisp}
993
994will load and execute the Quicklisp setup code.
995
996The implementation currently breaks \textsc{ANSI} conformance by allowing the
997types able to be \code{CL:READ} for the \code{DEVICE} to return a possible \code{CONS} of
998\code{CL:PATHNAME} objects.  %% citation from CLHS needed.
999
1000In order to ``smooth over'' the bit about types being \code{CL:READ}
1001from \code{CL:PATHNAME} components, we extend the semantics for the
1002usual PATHNAME merge semantics when \code{*DEFAULT-PATHNAME-DEFAULTS*}
1003contains a \code{EXT:JAR-PATHNAME} with the ``do what I mean''
1004algorithm described in \ref{section:conformance} on page
1005\pageref{section:conformance}.
1006
1007%See \ref{_:quicklisp} on page \pageref{_:quicklisp}.
1008
1009\subsubsection{Implementation}
1010
1011The implementation of these extensions stores all the additional
1012information in the \code{CL:PATHNAME} object itself in ways that while strictly
1013speaking are conformant, nonetheless may trip up libraries that don't
1014expect the following:
1015
1016\begin{itemize}
1017\item \code{DEVICE} can be either a string denoting a drive letter
1018  under \textsc{DOS} or a list of exactly one or two elements.  If
1019  \code{DEVICE} is a list, it denotes a \code{EXT:JAR-PATHNAME}, with
1020  the entries containing \code{CL:PATHNAME} objects which describe the
1021  outer and (possibly inner) locations of the jar
1022  archive \footnote{The case of inner and outer
1023    \code{EXT:JAR-PATHNAME} \ref{EXT:JAR-PATHNAME} arises when zip
1024    archives themselves contain zip archives which is the case when
1025    the ABCL fasl is included in the abcl.jar zip archive.}.
1026
1027\item A \code{EXT:URL-PATHNAME} always has a \code{HOST} component that is a
1028  property list.  The values of the \code{HOST} property list are
1029  always character strings.  The allowed keys have the following meanings:
1030  \begin{description}
1031  \item[:SCHEME] Scheme of URI ("http", "ftp", "bundle", etc.)
1032  \item[:AUTHORITY] Valid authority according to the URI scheme.  For
1033    "http" this could be "example.org:8080".
1034  \item[:QUERY] The query of the \textsc{URI} 
1035  \item[:FRAGMENT] The fragment portion of the \textsc{URI}
1036  \end{description}
1037
1038\item In order to encapsulate the implementation decisions for these
1039  meanings, the following functions provide a SETF-able API for
1040  reading and writing such values: \code{URL-PATHNAME-QUERY},
1041  \code{URL-PATHNAME-FRAGMENT}, \code{URL-PATHNAME-AUTHORITY}, and
1042  \code{URL-PATHNAME-SCHEME}.  The specific subtype of a Pathname may
1043  be determined with the predicates \code{PATHNAME-URL-P} and
1044  \code{PATHNAME-JAR-P}.
1045
1046\label{EXTENSIONS:URL-PATHNAME-SCHEME}
1047\index{URL-PATHNAME-SCHEME}
1048
1049\label{EXTENSIONS:URL-PATHNAME-FRAGMENT}
1050\index{URL-PATHNAME-FRAGMENT}
1051
1052\label{EXTENSIONS:URL-PATHNAME-AUTHORITY}
1053\index{URL-PATHNAME-AUTHORITY}
1054
1055\label{EXTENSIONS:PATHNAME-URL-P}
1056\index{PATHNAME-URL-P}
1057
1058\label{EXTENSIONS:URL-PATHNAME-QUERY}
1059\index{URL-PATHNAME-QUERY}
1060
1061\end{itemize}
1062
1063\section{Package-Local Nicknames}
1064\label{sec:pack-local-nickn}
1065
1066ABCL allows giving packages local nicknames: they allow short and
1067easy-to-use names to be used without fear of name conflict associated
1068with normal nicknames.\footnote{Package-local nicknames were originally
1069developed in SBCL.}
1070
1071A local nickname is valid only when inside the package for which it
1072has been specified. Different packages can use same local nickname for
1073different global names, or different local nickname for same global
1074name.
1075
1076Symbol \code{:package-local-nicknames} in \code{*features*} denotes the
1077support for this feature.
1078
1079\index{DEFPACKAGE}
1080The options to \code{defpackage} are extended with a new option
1081\code{:local-nicknames (local-nickname actual-package-name)*}.
1082
1083The new package has the specified local nicknames for the corresponding
1084actual packages.
1085
1086Example:
1087\begin{listing-lisp}
1088(defpackage :bar (:intern "X"))
1089(defpackage :foo (:intern "X"))
1090(defpackage :quux (:use :cl)
1091  (:local-nicknames (:bar :foo) (:foo :bar)))
1092(find-symbol "X" :foo) ; => FOO::X
1093(find-symbol "X" :bar) ; => BAR::X
1094(let ((*package* (find-package :quux)))
1095  (find-symbol "X" :foo))               ; => BAR::X
1096(let ((*package* (find-package :quux)))
1097  (find-symbol "X" :bar))               ; => FOO::X
1098\end{listing-lisp}
1099
1100\index{PACKAGE-LOCAL-NICKNAMES}
1101--- Function: \textbf{package-local-nicknames} [\textbf{ext}] \textit{package-designator}
1102
1103\begin{adjustwidth}{5em}{5em}
1104  Returns an ALIST of \code{(local-nickname . actual-package)}
1105  describing the nicknames local to the designated package.
1106
1107  When in the designated package, calls to \code{find-package} with any
1108  of the local-nicknames will return the corresponding actual-package
1109  instead. This also affects all implied calls to \code{find-package},
1110  including those performed by the reader.
1111
1112  When printing a package prefix for a symbol with a package local
1113  nickname, the local nickname is used instead of the real name in order
1114  to preserve print-read consistency.
1115\end{adjustwidth}
1116
1117\index{PACKAGE-LOCALLY-NICKNAMED-BY-LIST}
1118--- Function: \textbf{package-locally-nicknamed-by-list} [\textbf{ext}] \textit{package-designator}
1119
1120\begin{adjustwidth}{5em}{5em}
1121Returns a list of packages which have a local nickname for the
1122designated package.
1123\end{adjustwidth}
1124
1125\index{ADD-PACKAGE-LOCAL-NICKNAME}
1126--- Function: \textbf{add-package-local-nickname} [\textbf{ext}] \textit{local-nickname actual-package \&optional package-designator}
1127
1128\begin{adjustwidth}{5em}{5em}
1129  Adds \code{local-nickname} for \code{actual-package} in the designated
1130  package, defaulting to current package. \code{local-nickname} must be
1131  a string designator, and \code{actual-package} must be a package
1132  designator.
1133
1134  Returns the designated package.
1135
1136  Signals an error if \code{local-nickname} is already a package local
1137  nickname for a different package, or if \code{local-nickname} is one
1138  of "CL", "COMMON-LISP", or, "KEYWORD", or if \code{local-nickname} is
1139  a global name or nickname for the package to which the nickname would
1140  be added.
1141
1142  When in the designated package, calls to \code{find-package} with the
1143  \code{local-nickname} will return the package the designated
1144  \code{actual-package} instead. This also affects all implied calls to
1145  \code{find-package}, including those performed by the reader.
1146
1147  When printing a package prefix for a symbol with a package local
1148  nickname, local nickname is used instead of the real name in order to
1149  preserve print-read consistency.
1150\end{adjustwidth}
1151
1152\index{REMOVE-PACKAGE-LOCAL-NICKNAME}
1153--- Function: \textbf{remove-package-local-nickname} [\textbf{ext}] \textit{old-nickname \&optional package-designator}
1154
1155\begin{adjustwidth}{5em}{5em}
1156  If the designated package had \code{old-nickname} as a local nickname
1157  for another package, it is removed. Returns true if the nickname
1158  existed and was removed, and \code{nil} otherwise.
1159\end{adjustwidth}
1160
1161
1162         
1163\section{Extensible Sequences}
1164
1165The SEQUENCE package fully implements Christopher Rhodes' proposal for
1166extensible sequences.  These user extensible sequences are used
1167directly in \code{java-collections.lisp} provide these CLOS
1168abstractions on the standard Java collection classes as defined by the
1169\code{java.util.List} contract.
1170
1171
1172%% an Example of using java.util.Lisp in Lisp would be nice
1173
1174This extension is not automatically loaded by the implementation.   It
1175may be loaded via:
1176
1177\begin{listing-lisp}
1178CL-USER> (require :java-collections)
1179\end{listing-lisp}
1180
1181if both extensible sequences and their application to Java collections
1182is required, or
1183
1184\begin{listing-lisp}
1185CL-USER> (require :extensible-sequences)
1186\end{listing-lisp}
1187
1188if only the extensible sequences API as specified in \cite{RHODES2007} is
1189required.
1190
1191Note that \code{(require :java-collections)} must be issued before
1192\code{java.util.List} or any subclass is used as a specializer in a \textsc{CLOS}
1193method definition (see the section below).
1194
1195See Rhodes2007 \cite{RHODES2007} for the an overview of the
1196abstractions of the \code{java.util.collection} package afforded by
1197\code{JAVA-COLLECTIONS}.
1198
1199\section{Extensions to CLOS}
1200
1201\subsection{Metaobject Protocol}
1202
1203\textsc{ABCL} implements the metaobject protocol for \textsc{CLOS} as
1204specified in \textsc{(A)MOP}.  The symbols are exported from the
1205package \code{MOP}.
1206
1207Contrary to the AMOP specification and following \textsc{SBCL}'s lead,
1208the metaclass \code{funcallable-standard-object} has
1209\code{funcallable-standard-class} as metaclass instead of
1210\code{standard-class}.
1211
1212\textsc{ABCL}'s fidelity to the AMOP specification is codified as part
1213of Pascal Costanza's \code{closer-mop} \ref{closer-mop} \cite{closer-mop}.
1214
1215\subsection{Specializing on Java classes}
1216
1217There is an additional syntax for specializing the parameter of a
1218generic function on a java class, viz. \code{(java:jclass CLASS-STRING)}
1219where \code{CLASS-STRING} is a string naming a Java class in dotted package
1220form.
1221
1222For instance the following specialization would perhaps allow one to
1223print more information about the contents of a \code{java.util.Collection}
1224object
1225
1226\begin{listing-lisp}
1227(defmethod print-object ((coll (java:jclass "java.util.Collection"))
1228                         stream)
1229  ;;; ...
1230)
1231\end{listing-lisp}
1232
1233If the class had been loaded via a classloader other than the original
1234the class you wish to specialize on, one needs to specify the
1235classloader as an optional third argument.
1236
1237\begin{listing-lisp}
1238
1239(defparameter *other-classloader*
1240  (jcall "getBaseLoader" cl-user::*classpath-manager*))
1241 
1242(defmethod print-object
1243   ((device-id (java:jclass "dto.nbi.service.hdm.alcatel.com.NBIDeviceID"
1244                            *other-classloader*))
1245    stream)
1246  ;;; ...
1247)
1248\end{listing-lisp}
1249
1250\section{Extensions to the Reader}
1251
1252We implement a special hexadecimal escape sequence for specifying 32
1253bit characters to the Lisp reader\footnote{This represents a
1254  compromise with contemporary in 2011 32bit hosting architecures for
1255  which we wish to make text processing efficient.  Should the User
1256  require more control over \textsc{UNICODE} processing we recommend Edi Weisz'
1257  excellent work with \textsc|{FLEXI-STREAMS}  which we fully support}, namely we
1258allow a sequences of the form \verb~#\U~\emph{\texttt{xxxx}} to be processed
1259by the reader as character whose code is specified by the hexadecimal
1260digits \emph{\texttt{xxxx}}.  The hexadecimal sequence may be one to four digits
1261long.
1262
1263% Why doesn't ALEXANDRIA work?  Good question: Alexandria from
1264% Quicklisp 2010-10-07 fails a number of tests:
1265%% Form: (ALEXANDRIA.0.DEV:TYPE= 'LIST '(OR NULL CONS))
1266%% Expected values: T
1267%%                  T
1268%% Actual values: NIL
1269%%                T.
1270%% Test ALEXANDRIA-TESTS::TYPE=.3 failed
1271%% Form: (ALEXANDRIA.0.DEV:TYPE= 'NULL '(AND SYMBOL LIST))
1272%% Expected values: T
1273%%                  T
1274%% Actual values: NIL
1275%%                NIL.
1276
1277
1278Note that this sequence is never output by the implementation.  Instead,
1279the corresponding Unicode character is output for characters whose
1280code is greater than 0x00ff.
1281
1282\section{Overloading of the CL:REQUIRE Mechanism}
1283
1284The \code{CL:REQUIRE} mechanism is overloaded by attaching these
1285semantics to the execution of \code{REQUIRE} on the following symbols:
1286
1287\begin{description}
1288
1289  \item{\code{ASDF}} 
1290    Loads the \textsc{ASDF} implementation shipped
1291    with the implementation.  After \textsc{ASDF} has been loaded in
1292    this manner, symbols passed to \code{CL:REQUIRE} which are
1293    otherwise unresolved, are passed to ASDF for a chance for
1294    resolution.  This means, for instance if \code{CL-PPCRE} can be
1295    located as a loadable \textsc{ASDF} system \code{(require
1296      :cl-ppcre)} is equivalent to \code{(asdf:load-system
1297      :cl-ppcre)}.
1298
1299  \item{\code{ABCL-CONTRIB}} 
1300    Locates and pushes the toplevel contents of
1301    ``abcl-contrib.jar'' into the \textsc{ASDF} central registry. 
1302
1303    \begin{enumerate}
1304      \item \code{abcl-asdf} 
1305        Functions for loading JVM artifacts
1306        dynamically, hooking into ASDF 3 objects where possible.
1307      \item \code{asdf-jar} 
1308        Package addressable JVM artifacts via
1309        \code{abcl-asdf} descriptions as a single binary artifact
1310        including recursive dependencies.
1311      \item \code{mvn} 
1312        These systems name common JVM artifacts from
1313        the distributed pom.xml graph of Maven Aether:
1314        \begin{enumerate}
1315          \item \code{jna} 
1316            Dynamically load 'jna.jar' version 4.2.2
1317            from the network \footnote{This loading can be inhibited
1318              if, at runtime, the Java class corresponding
1319              ``:classname'' clause of the system defition is present.}
1320        \end{enumerate}
1321      \item \code{quicklisp-abcl} Boot a local Quicklisp installation
1322        via the ASDF:IRI type introduced via ABCL-ASDF.
1323
1324      \item \code{jfli} A descendent of Rich Hickey's pre-Clojure work
1325        on the JVM.
1326      \item \code{jss} Introduces dynamic inspection of present
1327        symbols via the \code{SHARPSIGN-QUOTATION\_MARK} macros as Java Syntax
1328        Sucks
1329      \item \code{abcl-introspect} Provides a framework for
1330        introspecting runtime Java and Lisp object values.
1331      \item \code{abcl-build} Provides a toolkit for building ABCL
1332        from source, as well as installing the necessary tools for
1333        such builds.
1334       
1335\end{enumerate}
1336
1337\end{description}
1338
1339The user may extend the \code{CL:REQUIRE} mechanism by pushing
1340function hooks into \code{SYSTEM:*MODULE-PROVIDER-FUNCTIONS*}.  Each
1341such hook function takes a single argument containing the symbol
1342passed to \code{CL:REQUIRE} and returns a non-\code{NIL} value if it
1343can successful resolve the symbol.
1344
1345\section{JSS extension of the Reader by SHARPSIGN-DOUBLE-QUOTE}
1346
1347The JSS contrib consitutes an additional, optional extension to the
1348reader in the definition of the \code{SHARPSIGN-DOUBLE-QUOTE}
1349(``\#\"'') reader macro.  See section \ref{section:jss} on page
1350\pageref{section:jss} for more information.
1351
1352\section{ASDF}
1353
1354asdf-3.2.2 (see \cite{asdf}) is packaged as core component of \textsc{ABCL},
1355but not initialized by default, as it relies on the \textsc{CLOS} subsystem
1356which can take a bit of time to start \footnote{While this time is
1357  ``merely'' on the order of seconds for contemporary 2011 machines,
1358  for applications that need to initialize quickly, for example a web
1359  server, this time might be unnecessarily long}.  The packaged \textsc{ASDF}
1360may be loaded by the \textsc{ANSI} \code{REQUIRE} mechanism as
1361follows:
1362
1363\begin{listing-lisp}
1364CL-USER> (require :asdf)
1365\end{listing-lisp}
1366
1367\chapter{Contrib}
1368
1369The \textsc{ABCL} contrib is packaged as a separate jar archive usually named
1370\code{abcl-contrib.jar} or possibly something like
1371\code{abcl-contrib-1.5.0.jar}.  The contrib jar is not loaded by the
1372implementation by default, and must be first intialized by the
1373\code{REQUIRE} mechanism before using any specific contrib:
1374
1375\begin{listing-lisp}
1376CL-USER> (require :abcl-contrib)
1377\end{listing-lisp}
1378
1379\section{abcl-asdf}
1380
1381This contrib enables an additional syntax for \textsc{ASDF} system
1382definition which dynamically loads \textsc{JVM} artifacts such as jar
1383archives via encapsulation of the Maven build tool.  The Maven Aether
1384component can also be directly manipulated by the function associated
1385with the \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} symbol.
1386
1387%ABCL specific contributions to ASDF system definition mainly
1388%concerned with finding JVM artifacts such as jar archives to be
1389%dynamically loaded.
1390
1391
1392When loaded, abcl-asdf adds the following objects to \textsc{ASDF}:
1393\code{JAR-FILE}, \code{JAR-DIRECTORY}, \code{CLASS-FILE-DIRECTORY} and
1394\code{MVN}, exporting them (and others) as public symbols.
1395
1396\subsection{Referencing Maven Artifacts via ASDF}
1397
1398Maven artifacts may be referenced within \textsc{ASDF} system
1399definitions, as the following example references the
1400\code{log4j-1.4.9.jar} JVM artifact which provides a widely-used
1401abstraction for handling logging systems:
1402
1403\begin{listing-lisp}
1404  ;;;; -*- Mode: LISP -*-
1405  (require :asdf)
1406  (in-package :cl-user)
1407
1408  (asdf:defsystem :log4j
1409     :defsystem-depends-on (abcl-asdf)
1410     :components ((:mvn "log4j/log4j" :version "1.4.9")))
1411\end{listing-lisp}
1412
1413\subsection{API}
1414
1415We define an API for \textsc{ABCL-ASDF} as consisting of the following
1416ASDF classes:
1417
1418\code{JAR-DIRECTORY}, \code{JAR-FILE}, and
1419\code{CLASS-FILE-DIRECTORY} for JVM artifacts that have a currently
1420valid pathname representation.
1421
1422Both the \code{MVN} and \code{IRI} classes descend from
1423\code{ASDF-COMPONENT}, but do not directly have a filesystem location.
1424
1425For use outside of ASDF system definitions, we currently define one
1426method, \code{ABCL-ASDF:RESOLVE-DEPENDENCIES} which locates,
1427downloads, caches, and then loads into the currently executing JVM
1428process all recursive dependencies annotated in the Maven pom.xml
1429graph.
1430
1431\subsection{Directly Instructing Maven to Download JVM Artifacts}
1432
1433Bypassing \textsc{ASDF}, one can directly issue requests for the Maven
1434artifacts to be downloaded
1435
1436\begin{listing-lisp}
1437CL-USER> (abcl-asdf:resolve-dependencies "com.google.gwt"
1438                                         "gwt-user")
1439WARNING: Using LATEST for unspecified version.
1440"/Users/evenson/.m2/repository/com/google/gwt/gwt-user/2.4.0-rc1
1441/gwt-user-2.4.0-rc1.jar:/Users/evenson/.m2/repository/javax/vali
1442dation/validation-api/1.0.0.GA/validation-api-1.0.0.GA.jar:/User
1443s/evenson/.m2/repository/javax/validation/validation-api/1.0.0.G
1444A/validation-api-1.0.0.GA-sources.jar"
1445\end{listing-lisp}
1446
1447To actually load the dependency, use the \code{JAVA:ADD-TO-CLASSPATH} generic
1448function:
1449
1450\begin{listing-lisp}
1451CL-USER> (java:add-to-classpath
1452          (abcl-asdf:resolve-dependencies "com.google.gwt"
1453                                          "gwt-user"))
1454\end{listing-lisp}
1455
1456Notice that all recursive dependencies have been located and installed
1457locally from the network as well.
1458
1459More extensive documentations and examples can be found at
1460\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-asdf/README.markdown}.
1461
1462\section{asdf-jar}
1463
1464The asdf-jar contrib provides a system for packaging \textsc{ASDF}
1465systems into jar archives for \textsc{ABCL}.  Given a running
1466\textsc{ABCL} image with loadable \textsc{ASDF} systems the code in
1467this package will recursively package all the required source and
1468fasls in a jar archive.
1469
1470The documentation for this contrib can be found at
1471\url{http://abcl.org/svn/tags/1.5.0/contrib/asdf-jar/README.markdown}.
1472
1473\section{jss}
1474\label{section:jss}
1475
1476To one used to the more universal syntax of Lisp pairs upon which the
1477definition of read and compile time macros is quite
1478natural \footnote{See Graham's ``On Lisp''
1479  http://lib.store.yahoo.net/lib/paulgraham/onlisp.pdf.}, the Java
1480syntax available to the Java programmer may be said to suck.  To
1481alleviate this situation, the JSS contrib introduces the
1482\code{SHARPSIGN-DOUBLE-QUOTE} (\code{\#"}) reader macro, which allows
1483the the specification of the name of invoking function as the first
1484element of the relevant s-expr which tends to be more congruent to how
1485Lisp programmers seem to be wired to think.
1486
1487While quite useful, we don't expect that the JSS contrib will be the
1488last experiment in wrangling Java from Common Lisp.
1489
1490\subsection{JSS usage}
1491
1492Example:
1493
1494\begin{listing-lisp}
1495CL-USER> (require :abcl-contrib)
1496==> ("ABCL-CONTRIB")
1497CL-USER> (require :jss)
1498==> ("JSS")
1499CL-USER) (#"getProperties" 'java.lang.System)
1500==> #<java.util.Properties {java.runtime.name=Java.... {2FA21ACF}>
1501CL-USER) (#"propertyNames" (#"getProperties" 'java.lang.System))
1502==> #<java.util.Hashtable$Enumerator java.util.Has.... {36B4361A}>
1503\end{listing-lisp} %$ <-- un-confuse Emacs font-lock
1504
1505Some more information on jss can be found in its documentation at
1506\url{http://abcl.org/svn/tags/1.5.0/contrib/jss/README.markdown}
1507
1508\section{jfli}
1509\label{section:jfli}
1510
1511The contrib contains a pure-Java version of JFLI.
1512
1513\url{http://abcl.org/svn/tags/1.5.0/contrib/jfli/README}.
1514
1515\section{abcl-introspect}
1516
1517\textsc{ABCL-INTROSPECT} offers more extensive systems for inspecting the state
1518of the implementation, most notably in integration with SLIME, where
1519the backtrace mechanism is augmented to the poiont that local
1520variables are inspectable.
1521
1522A compiled function is an instance of a class - This class has
1523multiple instances if it represents a closure, or a single instance if
1524it represents a non-closed-over function.
1525
1526The \textsc{ABCL} compiler stores constants that are used in function
1527execution as private java fields. This includes symbols used to invoke
1528function, locally-defined functions (such as via \code{LABEL} or
1529\code{flet}) and string and other literal objects.
1530\textsc{ABCL-INTROSPECT} implements a ``do what I mean'' API for
1531introspecting these constants.
1532
1533ABCL-INTROSPECT provides access to those internal values, and
1534uses them in at least two ways. First, to annotate locally defined
1535functions with the top-level function they are defined within, and
1536second to search for callers of a give function \footnote{ Since java
1537  functions are strings, local fields also have these strings. In the
1538  context of looking for callers of a function you can also give a
1539  string that names a java method. Same caveat re: false positives.}
1540. This may yield some false positives, such as when a symbol that
1541names a function is also used for some other purpose. It can also have
1542false negatives, as when a function is inlined. Still, it's pretty
1543useful. The second use to to find source locations for frames in the
1544debugger. If the source location for a local function is asked for the
1545location of its 'owner' is instead returns.
1546
1547In order to record information about local functions, ABCL defines a
1548function-plist, which is for the most part unused, but is used here
1549with set of keys indicating where the local function was defined and
1550in what manner, i.e. as normal local function, as a method function,
1551or as an initarg function. There may be other places functions are
1552stashed away (defstructs come to mind) and this file should be added
1553to to take them into account as they are discovered.
1554
1555ABCL-INTROSPECT does not depend on jss, but provides a bit of
1556jss-specific functionality if jss *is* loaded.
1557
1558\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-introspect/}.
1559
1560\section{abcl-build}
1561
1562\textsc{ABCL-BUILD} constitutes a new implementation for the original
1563Lisp-hosted ABCL build system API in the package \code{ABCL-BUILD}
1564that uses the same build artifacts as all of the other current builds.
1565
1566\subsection{Utilities}
1567
1568\textsc{ABCL-BUILD} consolidates various utilities that are useful
1569for system construction, namely
1570\begin{itemize}
1571
1572\item The ability to introspect the invocation of given executable in
1573  the current implementation process PATH.
1574
1575\item Downloading and unpackages selected JVM artifacts, namely the
1576  Ant and Maven build tools.  The \code{ABCL-BUILD:WITH-ANT} and
1577  \code{ABCL-BUILD:WITH-MVN} macros abstracts this installation
1578  procedure conveniently away from the User.
1579
1580\item The beginings of a generic framework to download arbitrary
1581    archives from the network.
1582\end{itemize}
1583
1584\url{http://abcl.org/svn/tags/1.5.0/contrib/abcl-build/}.
1585
1586\section{named-readtables}
1587
1588\code{NAMED-READTABLES} is a library that provides a namespace for
1589readtables akin to the already-existing namespace of packages.
1590
1591\url{https://github.com/melisgl/named-readtables/}.
1592\url{http://abcl.org/svn/tags/1.5.0/contrib/named-readtables/}.
1593
1594\chapter{History}
1595\index{History}
1596
1597\textsc{ABCL} was originally the extension language for the J editor, which was
1598started in 1998 by Peter Graves.  Sometime in 2003, a whole lot of
1599code that had previously not been released publically was suddenly
1600committed that enabled ABCL to be plausibly termed an emergent ANSI
1601Common Lisp implementation candidate.
1602
1603From 2006 to 2008, Peter manned the development lists, incorporating
1604patches as made sense.  After a suitable search, Peter nominated Erik
1605H\"{u}lsmann to take over the project.
1606
1607In 2008, the implementation was transferred to the current
1608maintainers, who have strived to improve its usability as a
1609contemporary Common Lisp implementation.
1610
1611On October 22, 2011, with the publication of this Manual explicitly
1612stating the conformance of Armed Bear Common Lisp to \textsc{ANSI}, we
1613released abcl-1.0.0.  We released abcl-1.0.1 as a maintainence release
1614on January 10, 2012.
1615
1616In December 2012, we revised the implementation by adding
1617\textsc{(A)MOP} with the release of abcl-1.1.0.  We released
1618abcl-1.1.1 as a maintainence release on Feburary 14, 2013.
1619
1620At the beginning of June 2013, we enhanced the stability of the
1621implementation with the release of abcl-1.2.1.
1622
1623In March 2014, we introduced the Fourth Edition of the implementation
1624with abcl-1.3.0.  At the end of April 2014, we released abcl-1.3.1 as
1625a maintainence release.
1626
1627In October 2016 we blessed the current \textsc{svn} trunk
1628\url{http://abcl.org/svn/trunk/} as 1.4.0, which includes the
1629community contributions from Vihbu, Olof, Pipping, and Cyrus.  We
1630gingerly stepped into current century by establishing \textsc{git}
1631bridges to the source repository at
1632\url{https://github.com/easye/abcl/} and
1633\url{https://gitlab.common-lisp.net/abcl/abcl/} so that pull
1634requests for enhancements to the implementation many be more easily
1635facilitated.
1636
1637In June 2017, we released ABCL 1.5.0 which dropped support for running
1638upon Java 5.
1639
1640\appendix 
1641
1642\chapter{The MOP Dictionary}
1643
1644\include{mop}
1645
1646\chapter{The SYSTEM Dictionary}
1647
1648The public interfaces in this package are subject to change with
1649\textsc{ABCL} 1.7.
1650
1651\include{system}
1652
1653\chapter{The JSS Dictionary}
1654
1655These public interfaces are provided by the JSS contrib.
1656
1657\include{jss}
1658
1659\bibliography{abcl}
1660\bibliographystyle{alpha}
1661
1662\printindex
1663
1664\end{document}
Note: See TracBrowser for help on using the repository browser.