source: branches/1.1.x/doc/manual/abcl.tex

Last change on this file was 14380, checked in by Mark Evenson, 11 years ago

1.1.1: update version artifacts.

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