Dan's Musings

Report on `short-site-name` and `long-site-name` in Common Lisp

The Environment Section

Easily one of my favorite sections of the Common Lisp HyperSpec (CLHS) is the Environment section. All my favorite functions are in there -- trace, functions for determining the lisp implementation type and version, kernel version and type, and so forth. I just barely also discovered dribble, which lets you record a REPL session.

No other section of the CLHS could be seen as more dated, though. Many functions, like dribble and ed, only make sense from an interactive, shell-based REPL session. I'm one of the few lispers who actually use such a session regularly, so I find them useful, but I don't know how useful they are from a SLIME session; in part because I don't generally use one (though I have used vlime in the past) and in part because they are so shell-centric.

Still, I have hooked up my ed function using trivial-ed-functions, though I don't use it much.

Other functions are useful in their own right, such as lisp-implementation-version, printing the name of the lisp version. Still others used to be used for one thing, but are still useful today. For example, software-type and software-version on my machine print out the OS type ("Linux") and kernel version.

The Site Name Functions

One set of functions in the "Environment" section caught my fancy, though: short-site-name and long-site-name. They are meant to print out information as to the actual room or physical location of the common lisp instance. Example return values given in the HyperSpec are "MIT AI Lab" for short-site-name and "MIT Artificial Intelligence Laboratory" for long-site-name. These functions are dated because most machines these days are small and portable, and don't really belong to any one physical location.

Still, they may have modern application: imagine short-site-name returning the AWS region wherein the machine resides, with long-site-name returning the long name of that region. Imagine setting them and using them in production for detecting where the machine is in space. Such a pair of functions could be useful.

I set out to figure out how different implementations allow the programmer to set the return values of these functions. All major implementations do have some mechanism for implementing these "Environment" functions after all, even if they are not useful to some, if only for the sake of compliance to the standard.

Setting the Site Name

With that in mind, here are the results of my inquiry. The results are strange. The implementations all take wildly different views of how these functions should be used.

SBCL and CCL both simply have a dynamic variable that can be set to the desired value. In SBCL, it is sb-ext:*short-site-name* and sb-ext:*long-site-name*, while in CCL it is ccl:*short-site-name* and ccl:*long-site-name*.

Lispworks has an unexported symbol, system::*short-site-name* and system::*long-site-name*, which can be set, but these are unexported :(

ECL feels like these names warrant some permanence: they have to be set BEFORE compiling ECL.

Finally, ABCL uses the host name of the machine for *-site-name, as does Allegro. (I even found (long-site-name) in some tests in the Allegro folder used as an explicit way to get the host name.)

This actually hilights another difference between implementations: Allegro uses (long-site-name) for hostname, but (machine-instance) prints out a 256-bit hex string. Meanwhile, SBCL, CCL, and others print out the hostname when running (machine-instance) and have a configurable value for site name. (Even ABCL and LispWorks uses machine-instance for hostname, Allegro seems to be alone in this odd behavior.)

Summary

So, if you want to use short-site-name and long-site-name, you must be aware of the implementation being used. For web apps this is probably fine, but these functions can't really be portably used from libraries with a few implementations using them for hostname and the others doing something else.

This schism has a further implication that most, but not all, implementations print out the hostname when running (machine-instance). Maybe someone should write a trivial-hostname library just to sort it out :P

The rich history of the Common Lisp language means that some functions exist but wane in popularity over the years, or even have their semantics differ wildly from implementation to implementation. How fun.