Beruflich Dokumente
Kultur Dokumente
To load a le is to treat its contents as code and execute that code . The le may contain source 24.1.2.1.1 Examples of Feature Expressions
code or compiled code . For example, suppose that in implementation A, the features spice and perq are present , but the
A le containing source code is called a source le . Loading a source le is accomplished feature lispm is not present ; in implementation B, the feature lispm is present , but the features
spice and perq are not present ; and in implementation C, none of the features spice, lispm , or
essentially by sequentially reading 2 the forms in the le, evaluating each immediately after it is perq are present . Figure 24{1 shows some sample expressions , and how they would be read 2 in
read . these implementations .
A le containing compiled code is called a compiled le . Loading a compiled le is similar to
loading a source le , except that the le does not contain text but rather an implementation- (cons #+spice "Spice" #-spice "Lispm" x)
dependent representation of pre-digested expressions created by the compiler . Often, a compiled in implementation A ::: (CONS "Spice" X)
le can be loaded more quickly than a source le . See Section 3.2 (Compilation). in implementation B ::: (CONS "Lispm" X)
in implementation C ::: (CONS "Lispm" X)
The way in which a source le is distinguished from a compiled le is implementation-dependent . (cons #+spice "Spice" #+LispM "Lispm" x)
in implementation A ::: (CONS "Spice" X)
24.1.2 Features in implementation B ::: (CONS "Lispm" X)
A feature is an aspect or attribute of Common Lisp, of the implementation , or of the environ- in implementation C ::: (CONS X)
ment . A feature is identied by a symbol . (setq a '(1 2 #+perq 43 #+(not perq) 27))
A feature is said to be present in a Lisp image if and only if the symbol naming it is an element in implementation A ::: (SETQ A '(1 2 43))
of the list held by the variable *features* , which is called the features list. in implementation B ::: (SETQ A '(1 2 27))
in implementation C ::: (SETQ A '(1 2 27))
24.1.2.1 Feature Expressions (let ((a 3) #+(or spice lispm) (b 3)) (foo a))
in implementation A ::: (LET ((A 3) (B 3)) (FOO A))
Boolean combinations of features , called feature expressions , are used by the #+ and #- reader in implementation B ::: (LET ((A 3) (B 3)) (FOO A))
macros in order to direct conditional reading of expressions by the Lisp reader . in implementation C ::: (LET ((A 3)) (FOO A))
The rules for interpreting a feature expression are as follows: (cons #+Lispm "#+Spice" #+Spice "foo" #-(or Lispm Spice) 7 x)
in implementation A ::: (CONS "foo" X)
feature in implementation B ::: (CONS "#+Spice" X)
in implementation C ::: (CONS 7 X)
If a symbol naming a feature is used as a feature expression , the feature expression
succeeds if that feature is present ; otherwise it fails. Figure 24{1. Features examples
(not feature-conditional )
A not feature expression succeeds if its argument feature-conditional fails; otherwise, it
succeeds.
(and ffeature-conditional g*
)
compile-le
compile-le Function function open. compile-le and load must cooperate in such a way that the resulting compiled
le can be loaded without specifying an external le format anew; see the function load.
Syntax: compile-le binds *readtable* and *package* to the values they held before processing the le.
compile-le input-le &key output-le verbose *compile-le-truename* is bound by compile-le to hold the truename of the pathname of the
print external-format le being compiled.
! output-truename, warnings-p, failure-p *compile-le-pathname* is bound by compile-le to hold a pathname de-
noted by the rst argument to compile-le, merged against the defaults; that is,
(pathname (merge-pathnames input-le )).
Arguments and Values:
input-le |a pathname designator . (Default llers for unspecied components are taken from The compiled functions contained in the compiled le become available for use when the compiled
*default-pathname-defaults*.) le is loaded into Lisp. Any function denition that is processed by the compiler, including
#'(lambda ...) forms and local function denitions made by
et, labels and defun forms, result
output-le |a pathname designator . The default is implementation-dened . in an object of type compiled-function.
verbose |a generalized boolean . The default is the value of *compile-verbose*. The primary value returned by compile-le, output-truename , is the truename of the output le,
or nil if the le could not be created.
print |a generalized boolean . The default is the value of *compile-print*.
The secondary value , warnings-p , is false if no conditions of type error or warning were detected
external-format |an external le format designator . The default is :default. by the compiler, and true otherwise.
output-truename |a pathname (the truename of the output le ), or nil. The tertiary value , failure-p , is false if no conditions of type error or warning (other than
warnings-p |a generalized boolean . style-warning) were detected by the compiler, and true otherwise.
failure-p |a generalized boolean . For general information about how les are processed by the le compiler , see Section 3.2.3 (File
Compilation).
Description: Programs to be compiled by the le compiler must only contain externalizable objects ; for details
compile-le transforms the contents of the le specied by input-le into implementation- on such objects , see Section 3.2.4 (Literal Objects in Compiled Files). For information on how
dependent binary data which are placed in the le specied by output-le . to extend the set of externalizable objects , see the function make-load-form and Section 3.2.4.4
The le to which input-le refers should be a source le . output-le can be used to specify an (Additional Constraints on Externalizable Objects).
output pathname ; the actual pathname of the compiled le to which compiled code will be output Aected By:
is computed as if by calling compile-le-pathname. *error-output*, *standard-output*, *compile-verbose*, *compile-print*
If input-le or output-le is a logical pathname , it is translated into a physical pathname as if by The computer's le system.
calling translate-logical-pathname.
If verbose is true , compile-le prints a message in the form of a comment (i.e., with a leading Exceptional Situations:
semicolon ) to standard output indicating what le is being compiled and other useful information. For information about errors detected during the compilation process, see Section 3.2.5 (Excep-
If verbose is false , compile-le does not print this information. tional Situations in the Compiler).
If print is true , information about top level forms in the le being compiled is printed to standard An error of type le-error might be signaled if (wild-pathname-p input-le ) returns true.
output . Exactly what is printed is implementation-dependent , but nevertheless some information If either the attempt to open the source le for input or the attempt to open the compiled le for
is printed. If print is nil, no information is printed. output fails, an error of type le-error is signaled.
The external-format species the external le format to be used when opening the le ; see the
See Also: compile-le, pathname, logical-pathname, Section 20.1 (File System Concepts), Section 19.1.2
compile, declare, eval-when, pathname, logical-pathname, Section 20.1 (File System Concepts), (Pathnames as Filenames)
Section 19.1.2 (Pathnames as Filenames)
Syntax:
Syntax: load lespec &key verbose print
compile-le-pathname input-le &key output-le &allow-other-keys ! pathname if-does-not-exist external-format
! generalized-boolean
Arguments and Values:
input-le |a pathname designator . (Default llers for unspecied components are taken from
*default-pathname-defaults*.)
Arguments and Values:
lespec |a stream , or a pathname designator . The default is taken from *default-pathname-defaults*.
output-le |a pathname designator . The default is implementation-dened . verbose |a generalized boolean . The default is the value of *load-verbose*.
pathname |a pathname . print |a generalized boolean . The default is the value of *load-print*.
Description: if-does-not-exist |a generalized boolean . The default is true .
Returns the pathname that compile-le would write into, if given the same arguments.
external-format |an external le format designator . The default is :default.
The defaults for the output-le are taken from the pathname that results from merging the input-
le with the value of *default-pathname-defaults*, except that the type component should generalized-boolean|a generalized boolean .
default to the appropriate implementation-dened default type for compiled les .
Description:
If input-le is a logical pathname and output-le is unsupplied, the result is a logical path- load loads the le named by lespec into the Lisp environment.
name . If input-le is a logical pathname , it is translated into a physical pathname as if
by calling translate-logical-pathname. If input-le is a stream , the stream can be ei- The manner in which a source le is distinguished from a compiled le is implementation-
ther open or closed. compile-le-pathname returns the same pathname after a le is dependent . If the le specication is not complete and both a source le and a compiled le
closed as it did when the le was open. It is an error if input-le is a stream that is exist which might match, then which of those les load selects is implementation-dependent .
created with make-two-way-stream , make-echo-stream, make-broadcast-stream , If lespec is a stream , load determines what kind of stream it is and loads directly from the
make-concatenated-stream , make-string-input-stream, make-string-output-stream. stream . If lespec is a logical pathname , it is translated into a physical pathname as if by calling
If an implementation supports additional keyword arguments to compile-le, translate-logical-pathname.
compile-le-pathname must accept the same arguments. load sequentially executes each form it encounters in the le named by lespec . If the le is a
Examples: source le and the implementation chooses to perform implicit compilation , load must recognize
top level forms as described in Section 3.2.3.1 (Processing of Top Level Forms) and arrange for
See logical-pathname-translations. each top level form to be executed before beginning implicit compilation of the next. (Note,
Exceptional Situations: however, that processing of eval-when forms by load is controlled by the :execute situation.)
An error of type le-error might be signaled if either input-le or output-le is wild . If verbose is true , load prints a message in the form of a comment (i.e., with a leading semicolon )
See Also: to standard output indicating what le is being loaded and other useful information. If verbose is
false , load does not print this information.
load
If print is true , load incrementally prints information to standard output showing the progress of (defmacro compile-truename () `',*compile-file-truename*)
the loading process. For a source le , this information might mean printing the values yielded by (defvar *my-compile-truename* (compile-truename) "Just for debugging.")
each form in the le as soon as those values are returned. For a compiled le , what is printed (defvar *my-load-pathname* *load-pathname*)
might not re
ect precisely the contents of the source le , but some information is generally (defun load-my-system ()
printed. If print is false , load does not print this information. (dolist (module-name '("FOO" "BAR" "BAZ"))
(load (merge-pathnames module-name *my-load-pathname*))))
If the le named by lespec is successfully loaded, load returns true . ;----[End of file SETUP]----
If the le does not exist, the specic action taken depends on if-does-not-exist : if it is nil, load
returns nil; otherwise, load signals an error. (load "SETUP")
The external-format species the external le format to be used when opening the le (see the (load-my-system)
function open), except that when the le named by lespec is a compiled le , the external-format
is ignored. compile-le and load cooperate in an implementation-dependent way to assure the
preservation of the similarity of characters referred to in the source le at the time the source le Aected By:
was processed by the le compiler under a given external le format , regardless of the value of The implementation, and the host computer's le system.
external-format at the time the compiled le is loaded .
Exceptional Situations:
load binds *readtable* and *package* to the values they held before loading the le. If :if-does-not-exist is supplied and is true , or is not supplied, load signals an error of type
*load-truename* is bound by load to hold the truename of the pathname of the le being loaded . le-error if the le named by lespec does not exist, or if the le system cannot perform the
requested operation.
*load-pathname* is bound by load to hold a pathname that represents lespec merged against An error of type le-error might be signaled if (wild-pathname-p lespec ) returns true .
the defaults. That is, (pathname (merge-pathnames lespec )).
Examples: See Also:
error, merge-pathnames, *load-verbose*, *default-pathname-defaults*, pathname,
;Establish a data file... logical-pathname, Section 20.1 (File System Concepts), Section 19.1.2 (Pathnames as Filenames)
(with-open-file (str "data.in" :direction :output :if-exists :error)
!
(print 1 str) (print '(setq a 888) str) t)
! true with-compilation-unit
T
!
(load "data.in")
a 888
Macro
(load (setq p (merge-pathnames "data.in")) :verbose t)
; Loading contents of file /fred/data.in Syntax:
! true
; Finished loading /fred/data.in
with-compilation-unit ([[ #option ] ) fformg* ! fresult g*
(load p :print t)
; Loading contents of file /fred/data.in
option::=:override override
; 1
; 888
Arguments and Values:
override |a generalized boolean ; evaluated. The default is nil.
! true
; Finished loading /fred/data.in
forms |an implicit progn .
results |the values returned by the forms .
;----[Begin file SETUP]----
(in-package "MY-STUFF")
features
Description: features Variable
Executes forms from left to right. Within the dynamic environment of with-compilation-unit,
actions deferred by the compiler until the end of compilation will be deferred until the end of the
outermost call to with-compilation-unit. Value Type:
a proper list .
The set of options permitted may be extended by the implementation, but the only standardized
keyword is :override. Initial Value:
If nested dynamically only the outer call to with-compilation-unit has any eect unless the value implementation-dependent .
associated with :override is true , in which case warnings are deferred only to the end of the Description:
innermost call for which override is true . The value of *features* is called the features list . It is a list of symbols , called features , that
The function compile-le provides the eect of correspond to some aspect of the implementation or environment .
(with-compilation-unit (:override nil) ...) Most features have implementation-dependent meanings; The following meanings have been
assigned to feature names:
around its code .
Any implementation-dependent extensions can only be provided as the result of an explicit :cltl1
programmer request by use of an implementation-dependent keyword. Implementations are If present, indicates that the LISP package purports to conform to the 1984 specication
forbidden from attaching additional meaning to a use of this macro which involves either no Common Lisp: The Language . It is possible, but not required, for a conforming imple-
keywords or just the keyword :override. mentation to have this feature because this specication species that its symbols are to
Examples: be in the COMMON-LISP package , not the LISP package.
If an implementation would normally defer certain kinds of warnings, such as warnings about :cltl2
undened functions, to the end of a compilation unit (such as a le ), the following example shows
how to cause those warnings to be deferred to the end of the compilation of several les. If present, indicates that the implementation purports to conform to Common Lisp: The
Language, Second Edition . This feature must not be present in any conforming imple-
(defun compile-files (&rest files) mentation , since conformance to that document is not compatible with conformance to
(with-compilation-unit () this specication. The name, however, is reserved by this specication in order to help
(mapcar #'(lambda (file) (compile-file file)) files))) programs distinguish implementations which conform to that document from implementa-
tions which conform to this specication.
(compile-files "A" "B" "C")
Note however that if the implementation does not normally defer any warnings, use of with- :ieee-floating-point
compilation-unit might not have any eect. If present, indicates that the implementation purports to conform to the requirements of
IEEE Standard for Binary Floating-Point Arithmetic .
See Also:
compile, compile-le :x3j13
If present, indicates that the implementation conforms to some particular working draft
of this specication, or to some subset of features that approximates a belief about
what this specication might turn out to contain. A conforming implementation might
or might not contain such a feature. (This feature is intended primarily as a stopgap
in order to provide implementors something to use prior to the availability of a draft
standard, in order to discourage them from introducing the :draft-ansi-cl and :ansi-cl
features prematurely.)
features
:draft-ansi-cl the specic implementation , so that conditional expressions can be written which distinguish
idiosyncrasies of one implementation from those of another. Since features are normally symbols
If present, indicates that the implementation purports to conform to the rst full draft in the KEYWORD package where name collisions might easily result, and since no uniquely dened
of this specication, which went to public review in 1992. A conforming implementa- mechanism is designated for deciding who has the right to use which symbol for what reason, a
tion which has the :draft-ansi-cl-2 or :ansi-cl feature is not permitted to retain the conservative strategy is to prefer names derived from one's own company or product name, since
:draft-ansi-cl feature since incompatible changes were made subsequent to the rst those names are often trademarked and are hence less likely to be used unwittingly by another
draft. implementation .
:draft-ansi-cl-2
If present, indicates that a second full draft of this specication has gone to public review, compile-le-pathname, compile-le-truename
and that the implementation purports to conform to that specication. (If additional Variable
public review drafts are produced, this keyword will continue to refer to the second draft,
and additional keywords will be added to identify conformance with such later drafts.
As such, the meaning of this keyword can be relied upon not to change over time.) A
conforming implementation which has the :ansi-cl feature is only permitted to retain the
Value Type:
:draft-ansi-cl feature if the nally approved standard is not incompatible with the draft
The value of *compile-le-pathname* must always be a pathname or nil. The value of
standard. *compile-le-truename* must always be a physical pathname or nil.
Initial Value:
:ansi-cl
nil.
If present, indicates that this specication has been adopted by ANSI as an ocial Description:
standard, and that the implementation purports to conform .
During a call to compile-le, *compile-le-pathname* is bound to the pathname denoted
:common-lisp by the rst argument to compile-le, merged against the defaults; that is, it is bound to
(pathname (merge-pathnames input-le )). During the same time interval, *compile-le-truename*
This feature must appear in *features* for any implementation that has one or more of is bound to the truename of the le being compiled .
the features :x3j13, :draft-ansi-cl, or :ansi-cl. It is intended that it should also appear
in implementations which have the features :cltl1 or :cltl2, but this specication At other times, the value of these variables is nil.
cannot force such behavior. The intent is that this feature should identify the language If a break loop is entered while compile-le is ongoing, it is implementation-dependent whether
family named \Common Lisp," rather than some specic dialect within that family. these variables retain the values they had just prior to entering the break loop or whether they
are bound to nil.
See Also: The consequences are unspecied if an attempt is made to assign or bind either of these vari-
Section 1.5.2.1.1 (Use of Read-Time Conditionals), Section 2.4 (Standard Macro Characters) ables .
Notes: Aected By:
The value of *features* is used by the #+ and #- reader syntax. The le system .
Symbols in the features list may be in any package , but in practice they are generally in the
KEYWORD package . This is because KEYWORD is the package used by default when reading 2 feature
See Also:
expressions in the #+ and #- reader macros . Code that needs to name a feature 2 in a package P
compile-le
(other than KEYWORD) can do so by making explicit use of a package prex for , but note that
P
such code must also assure that the package exists in order for the feature expression to be
P
read 2 |even in cases where the feature expression is expected to fail.
It is generally considered wise for an implementation to include one or more features identifying
provide, require
provide, require
;;; Another form of portable usage involves using a variable or
Function ;;; table lookup function to determine the pathname, which again
;;; must be initialized elsewhere.
(require "CALCULUS")