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

Last change on this file since 14637 was 14637, checked in by Mark Evenson, 10 years ago

1.3.0 metadata change before branch.

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