1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_load.htm
2024-04-01 10:24:07 +02:00

106 lines
15 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function LOAD</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_cmp__1.htm">
<LINK REL=UP HREF="c_system.htm">
<LINK REL=NEXT HREF="m_w_comp.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_cmp__1.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_system.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="m_w_comp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="load"><I>Function</I> <B>LOAD</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>load</B> <I>filespec <TT>&amp;key</TT> verbose print if-does-not-exist external-format</I><P> =&gt; <I>generalized-boolean</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>filespec</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>, or a <A REL=DEFINITION HREF="26_glo_p.htm#pathname_designator"><I>pathname designator</I></A>. The default is taken from <A REL=DEFINITION HREF="v_defaul.htm#STdefault-pathname-defaultsST"><B>*default-pathname-defaults*</B></A>. <P>
<I>verbose</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. The default is the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="v_ld_prs.htm#STload-verboseST"><B>*load-verbose*</B></A>. <P>
<I>print</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. The default is the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of <A REL=DEFINITION HREF="v_ld_prs.htm#STload-printST"><B>*load-print*</B></A>. <P>
<I>if-does-not-exist</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. The default is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>. <P>
<I>external-format</I>---an <A REL=DEFINITION HREF="26_glo_e.htm#external_file_format_designator"><I>external file format designator</I></A>. The default is <TT>:default</TT>. <P>
<I>generalized-boolean</I>---a <A REL=DEFINITION HREF="26_glo_g.htm#generalized_boolean"><I>generalized boolean</I></A>. <P>
<P><B>Description:</B><P>
<P>
<A REL=DEFINITION HREF="#load"><B>load</B></A> <A REL=DEFINITION HREF="26_glo_l.htm#load"><I>loads</I></A> the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> named by <I>filespec</I> into the Lisp environment. <P>
The manner in which a <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A> is distinguished from a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_file"><I>compiled file</I></A> is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. If the file specification is not complete and both a <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A> and a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_file"><I>compiled file</I></A> exist which might match, then which of those files <A REL=DEFINITION HREF="#load"><B>load</B></A> selects is <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A>. <P>
If <I>filespec</I> is a <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> determines what kind of <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A> it is and loads directly from the <A REL=DEFINITION HREF="26_glo_s.htm#stream"><I>stream</I></A>. If <I>filespec</I> is a <A REL=DEFINITION HREF="26_glo_l.htm#logical_pathname"><I>logical pathname</I></A>, it is translated into a <A REL=DEFINITION HREF="26_glo_p.htm#physical_pathname"><I>physical pathname</I></A> as if by calling <A REL=DEFINITION HREF="f_tr_log.htm#translate-logical-pathname"><B>translate-logical-pathname</B></A>. <P>
<A REL=DEFINITION HREF="#load"><B>load</B></A> sequentially executes each <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> it encounters in the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> named by <I>filespec</I>. If the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> is a <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A> and the <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A> chooses to perform <A REL=DEFINITION HREF="26_glo_i.htm#implicit_compilation"><I>implicit compilation</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> must recognize <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level forms</I></A> as described in <A REL=CHILD HREF="03_bca.htm">Section 3.2.3.1 (Processing of Top Level Forms)</A> and arrange for each <A REL=DEFINITION HREF="26_glo_t.htm#top_level_form"><I>top level form</I></A> to be executed before beginning <A REL=DEFINITION HREF="26_glo_i.htm#implicit_compilation"><I>implicit compilation</I></A> of the next. (Note, however, that processing of <A REL=DEFINITION HREF="s_eval_w.htm#eval-when"><B>eval-when</B></A> <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>forms</I></A> by <A REL=DEFINITION HREF="#load"><B>load</B></A> is controlled by the <TT>:execute</TT> situation.) <P>
If <I>verbose</I> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> prints a message in the form of a comment (i.e., with a leading <A REL=DEFINITION HREF="26_glo_s.htm#semicolon"><I>semicolon</I></A>) to <A REL=DEFINITION HREF="26_glo_s.htm#standard_output"><I>standard output</I></A> indicating what <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> is being <I>loaded</I> and other useful information. If <I>verbose</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> does not print this information. <P>
If <I>print</I> is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> incrementally prints information to <A REL=DEFINITION HREF="26_glo_s.htm#standard_output"><I>standard output</I></A> showing the progress of the <I>loading</I> process. For a <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A>, this information might mean printing the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> <I>yielded</I> by each <A REL=DEFINITION HREF="26_glo_f.htm#form"><I>form</I></A> in the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> as soon as those <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> are returned. For a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_file"><I>compiled file</I></A>, what is printed might not reflect precisely the contents of the <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A>, but some information is generally printed. If <I>print</I> is <A REL=DEFINITION HREF="26_glo_f.htm#false"><I>false</I></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> does not print this information. <P>
If the file named by <I>filespec</I> is successfully loaded, <A REL=DEFINITION HREF="#load"><B>load</B></A> returns <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>. <P>
<P>
If the file does not exist, the specific action taken depends on <I>if-does-not-exist</I>: if it is <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>, <A REL=DEFINITION HREF="#load"><B>load</B></A> returns <A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A>; otherwise, <A REL=DEFINITION HREF="#load"><B>load</B></A> signals an error. <P>
The <I>external-format</I> specifies the <A REL=DEFINITION HREF="26_glo_e.htm#external_file_format"><I>external file format</I></A> to be used when opening the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> (see the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="f_open.htm#open"><B>open</B></A>), except that when the <A REL=DEFINITION HREF="26_glo_f.htm#file"><I>file</I></A> named by <I>filespec</I> is a <A REL=DEFINITION HREF="26_glo_c.htm#compiled_file"><I>compiled file</I></A>, the <I>external-format</I> is ignored. <A REL=DEFINITION HREF="f_cmp_fi.htm#compile-file"><B>compile-file</B></A> and <A REL=DEFINITION HREF="#load"><B>load</B></A> cooperate in an <A REL=DEFINITION HREF="26_glo_i.htm#implementation-dependent"><I>implementation-dependent</I></A> way to assure the preservation of the <A REL=DEFINITION HREF="26_glo_s.htm#similarity"><I>similarity</I></A> of <A REL=DEFINITION HREF="26_glo_c.htm#character"><I>characters</I></A> referred to in the <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A> at the time the <A REL=DEFINITION HREF="26_glo_s.htm#source_file"><I>source file</I></A> was processed by the <A REL=DEFINITION HREF="26_glo_f.htm#file_compiler"><I>file compiler</I></A> under a given <A REL=DEFINITION HREF="26_glo_e.htm#external_file_format"><I>external file format</I></A>, regardless of the value of <I>external-format</I> at the time the <A REL=DEFINITION HREF="26_glo_c.htm#compiled_file"><I>compiled file</I></A> is <I>loaded</I>. <P>
<A REL=DEFINITION HREF="#load"><B>load</B></A> binds <A REL=DEFINITION HREF="v_rdtabl.htm#STreadtableST"><B>*readtable*</B></A> and <A REL=DEFINITION HREF="v_pkg.htm#STpackageST"><B>*package*</B></A> to the values they held before <I>loading</I> the file. <P>
<A REL=DEFINITION HREF="v_ld_pns.htm#STload-truenameST"><B>*load-truename*</B></A> is <A REL=DEFINITION HREF="26_glo_b.htm#bound"><I>bound</I></A> by <A REL=DEFINITION HREF="#load"><B>load</B></A> to hold the <A REL=DEFINITION HREF="26_glo_t.htm#truename"><I>truename</I></A> of the <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> of the file being <I>loaded</I>. <P>
<A REL=DEFINITION HREF="v_ld_pns.htm#STload-pathnameST"><B>*load-pathname*</B></A> is <A REL=DEFINITION HREF="26_glo_b.htm#bound"><I>bound</I></A> by <A REL=DEFINITION HREF="#load"><B>load</B></A> to hold a <A REL=DEFINITION HREF="26_glo_p.htm#pathname"><I>pathname</I></A> that represents <I>filespec</I> merged against the defaults. That is, <TT>(pathname (merge-pathnames </TT><I>filespec</I><TT>))</TT>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
;Establish a data file...
(with-open-file (str &quot;data.in&quot; :direction :output :if-exists :error)
(print 1 str) (print '(setq a 888) str) t)
=&gt; T
(load &quot;data.in&quot;) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
a =&gt; 888
(load (setq p (merge-pathnames &quot;data.in&quot;)) :verbose t)
; Loading contents of file /fred/data.in
; Finished loading /fred/data.in
=&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(load p :print t)
; Loading contents of file /fred/data.in
; 1
; 888
; Finished loading /fred/data.in
=&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
</PRE>
</TT> <P>
<PRE>
;----[Begin file SETUP]----
(in-package &quot;MY-STUFF&quot;)
(defmacro compile-truename () `',*compile-file-truename*)
(defvar *my-compile-truename* (compile-truename) &quot;Just for debugging.&quot;)
(defvar *my-load-pathname* *load-pathname*)
(defun load-my-system ()
(dolist (module-name '(&quot;FOO&quot; &quot;BAR&quot; &quot;BAZ&quot;))
(load (merge-pathnames module-name *my-load-pathname*))))
;----[End of file SETUP]----
(load &quot;SETUP&quot;)
(load-my-system)
</PRE>
</TT> <P>
<P><B>Affected By:</B><P>
<P>
The implementation, and the host computer's file system. <P>
<P><B>Exceptional Situations:</B><P>
<P>
If <TT>:if-does-not-exist</TT> is supplied and is <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>, or is not supplied, <A REL=DEFINITION HREF="#load"><B>load</B></A> signals an error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_file_e.htm#file-error"><B>file-error</B></A> if the file named by <I>filespec</I> does not exist, or if the <A REL=DEFINITION HREF="26_glo_f.htm#file_system"><I>file system</I></A> cannot perform the requested operation. <P>
An error of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_file_e.htm#file-error"><B>file-error</B></A> might be signaled if <TT>(wild-pathname-p </TT><I>filespec</I><TT>)</TT> returns <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>. <P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_error.htm#error"><B>error</B></A>, <A REL=DEFINITION HREF="f_merge_.htm#merge-pathnames"><B>merge-pathnames</B></A>, <A REL=DEFINITION HREF="v_ld_prs.htm#STload-verboseST"><B>*load-verbose*</B></A>, <A REL=DEFINITION HREF="v_defaul.htm#STdefault-pathname-defaultsST"><B>*default-pathname-defaults*</B></A>, <A REL=DEFINITION HREF="t_pn.htm#pathname"><B>pathname</B></A>, <A REL=DEFINITION HREF="t_logica.htm#logical-pathname"><B>logical-pathname</B></A>, <A REL=CHILD HREF="20_a.htm">Section 20.1 (File System Concepts)</A>, <A REL=CHILD HREF="19_ab.htm">Section 19.1.2 (Pathnames as Filenames)</A> <P>
<P><B>Notes:</B> None.
<P>
<P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss258.htm">PATHNAME-HOST-PARSING:RECOGNIZE-LOGICAL-HOST-NAMES</A><LI> <A REL=CHILD HREF="../Issues/iss267.htm">PATHNAME-WILD:NEW-FUNCTIONS</A><LI> <A REL=CHILD HREF="../Issues/iss157.htm">FILE-OPEN-ERROR:SIGNAL-FILE-ERROR</A><LI> <A REL=CHILD HREF="../Issues/iss218.htm">LOAD-TRUENAME:NEW-PATHNAME-VARIABLES</A><LI> <A REL=CHILD HREF="../Issues/iss196.htm">IN-SYNTAX:MINIMAL</A><LI> <A REL=CHILD HREF="../Issues/iss146.htm">EVAL-TOP-LEVEL:LOAD-LIKE-COMPILE-FILE</A><LI> <A REL=CHILD HREF="../Issues/iss259.htm">PATHNAME-LOGICAL:ADD</A><LI> <A REL=CHILD HREF="../Issues/iss155.htm">EXTERNAL-FORMAT-FOR-EVERY-FILE-CONNECTION:MINIMUM</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>