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

Last change on this file since 15196 was 15196, checked in by Mark Evenson, 4 years ago

1.6.0-rc-0: metadata updates for the release of the Seventh edition

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