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