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

Last change on this file since 15354 was 15354, checked in by Mark Evenson, 3 years ago

manual: reverse order of prefaces

Fix some formatting and reference problems.

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