1
0
Fork 0
cl-sites/novaspec.org/cl/3_7_Destructive_Operations.html
2025-02-05 18:52:26 +01:00

574 lines
No EOL
12 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>3.7 Destructive Operations | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="3_7_Destructive_Operations.html"
><LINK REL="next" HREF="3_8_Evaluation_and_Compilation_Dictionary.html" TYPE="text/html" TITLE="3.8 Evaluation and Compilation Dictionary"
><LINK REL="prev" HREF="3_6_Traversal_Rules_and_Side_Effects.html" TYPE="text/html" TITLE="3.6 Traversal Rules and Side Effects"
><LINK REL="up" HREF="3_Evaluation_and_Compilation.html" TYPE="text/html" TITLE="3. Evaluation and Compilation"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="3_Evaluation_and_Compilation.html"
>3. Evaluation and Compilation</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="3_7_Destructive_Operations.html"
>3.7 Destructive Operations</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="3_6_Traversal_Rules_and_Side_Effects.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="3_8_Evaluation_and_Compilation_Dictionary.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><SECTION
><H2 ID="sec_3_7" CLASS="HeadII"
>3.7 Destructive Operations</H2
><UL CLASS="subtoc"
><LI
><A HREF="3_7_Destructive_Operations.html#sec_3_7_1"
>3.7.1 Modification of Literal Objects</A
></LI
><LI
><A HREF="3_7_Destructive_Operations.html#sec_3_7_2"
>3.7.2 Transfer of Control during a Destructive Operation</A
></LI
><LI
><A HREF="3_7_Destructive_Operations.html#sec_3_7_2_1"
>3.7.2.1 Examples of Transfer of Control during a Destructive Operation</A
></LI
></UL
><H3 ID="sec_3_7_1" CLASS="HeadIII"
>3.7.1 Modification of Literal Objects</H3
><P CLASS="j"
>The consequences are undefined if <A HREF="26_1_Glossary.html#literal"
><EM CLASS="term"
>literal</EM
></A
> <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> are destructively modified. For this purpose, the following operations are considered <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
>:</P
><DL
><DT
><A HREF="t_random-state.html" CLASS="typeref"
><B
>random-state</B
></A
></DT
><DD
><P CLASS="j"
>Using it as an <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>argument</EM
></A
> to the <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="f_random.html" CLASS="funref"
><B
>random</B
></A
>.</P
></DD
><DT
><A HREF="t_cons.html" CLASS="typeref"
><B
>cons</B
></A
></DT
><DD
><P CLASS="j"
>Changing the <A HREF="26_1_Glossary.html#car"
><EM CLASS="term"
>car</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
></SPAN
> or <A HREF="26_1_Glossary.html#cdr"
><EM CLASS="term"
>cdr</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>1</SPAN
></SUB
></SPAN
> of the <A HREF="26_1_Glossary.html#cons"
><EM CLASS="term"
>cons</EM
></A
>, or performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> which is either the <A HREF="26_1_Glossary.html#car"
><EM CLASS="term"
>car</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
></SPAN
> or the <A HREF="26_1_Glossary.html#cdr"
><EM CLASS="term"
>cdr</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>2</SPAN
></SUB
></SPAN
> of the <A HREF="26_1_Glossary.html#cons"
><EM CLASS="term"
>cons</EM
></A
>.</P
></DD
><DT
><A HREF="t_array.html" CLASS="typeref"
><B
>array</B
></A
></DT
><DD
><P CLASS="j"
>Storing a new value into some element of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>, or performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that is already such an <A HREF="26_1_Glossary.html#element"
><EM CLASS="term"
>element</EM
></A
>. </P
><P CLASS="j"
>Changing the <A HREF="26_1_Glossary.html#fill_pointer"
><EM CLASS="term"
>fill pointer</EM
></A
>, <A HREF="26_1_Glossary.html#dimension"
><EM CLASS="term"
>dimensions</EM
></A
>, or displacement of the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> (regardless of whether the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> is <A HREF="26_1_Glossary.html#actually_adjustable"
><EM CLASS="term"
>actually adjustable</EM
></A
>). </P
><P CLASS="j"
>Performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on another <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> that is displaced to the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
> or that otherwise shares its contents with the <A HREF="26_1_Glossary.html#array"
><EM CLASS="term"
>array</EM
></A
>.</P
></DD
><DT
><A HREF="t_hash-table.html" CLASS="typeref"
><B
>hash-table</B
></A
></DT
><DD
><P CLASS="j"
>Performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on any <A HREF="26_1_Glossary.html#key"
><EM CLASS="term"
>key</EM
></A
>. </P
><P CLASS="j"
>Storing a new <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
><SPAN CLASS="meaning"
><SUB CLASS="sub"
><SPAN CLASS="cmr"
>4</SPAN
></SUB
></SPAN
> for any <A HREF="26_1_Glossary.html#key"
><EM CLASS="term"
>key</EM
></A
>, or performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on any <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that is such a <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
>. </P
><P CLASS="j"
>Adding or removing entries from the <A HREF="26_1_Glossary.html#hash_table"
><EM CLASS="term"
>hash table</EM
></A
>.</P
></DD
><DT
><A HREF="t_structure-object.html" CLASS="typeref"
><B
>structure-object</B
></A
></DT
><DD
><P CLASS="j"
>Storing a new value into any slot, or performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that is the value of some slot.</P
></DD
><DT
><A HREF="t_standard-object.html" CLASS="typeref"
><B
>standard-object</B
></A
></DT
><DD
><P CLASS="j"
>Storing a new value into any slot, or performing a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation on an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> that is the value of some slot. </P
><P CLASS="j"
>Changing the class of the <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
> (<I CLASS="i"
><I
>e.g.</I
></I
>, using the <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="f_change-class.html" CLASS="funref"
><B
>change-class</B
></A
>).</P
></DD
><DT
><A HREF="t_readtable.html" CLASS="typeref"
><B
>readtable</B
></A
></DT
><DD
><P CLASS="j"
>Altering the <A HREF="26_1_Glossary.html#readtable_case"
><EM CLASS="term"
>readtable case</EM
></A
>. </P
><P CLASS="j"
>Altering the syntax type of any character in this readtable. </P
><P CLASS="j"
>Altering the <A HREF="26_1_Glossary.html#reader_macro_function"
><EM CLASS="term"
>reader macro function</EM
></A
> associated with any <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>character</EM
></A
> in the <A HREF="26_1_Glossary.html#readtable"
><EM CLASS="term"
>readtable</EM
></A
>, or altering the <A HREF="26_1_Glossary.html#reader_macro_function"
><EM CLASS="term"
>reader macro functions</EM
></A
> associated with <A HREF="26_1_Glossary.html#character"
><EM CLASS="term"
>characters</EM
></A
> defined as <A HREF="26_1_Glossary.html#dispatching_macro_character"
><EM CLASS="term"
>dispatching macro characters</EM
></A
> in the <A HREF="26_1_Glossary.html#readtable"
><EM CLASS="term"
>readtable</EM
></A
>.</P
></DD
><DT
><A HREF="t_stream.html" CLASS="typeref"
><B
>stream</B
></A
></DT
><DD
><P CLASS="j"
>Performing I/O operations on the <A HREF="26_1_Glossary.html#stream"
><EM CLASS="term"
>stream</EM
></A
>, or <A HREF="26_1_Glossary.html#close"
><EM CLASS="term"
>closing</EM
></A
> the <A HREF="26_1_Glossary.html#stream"
><EM CLASS="term"
>stream</EM
></A
>.</P
></DD
><DT
><SPAN CLASS="cmr"
>All</SPAN
> <SPAN CLASS="cmr"
>other</SPAN
> <SPAN CLASS="cmr"
>standardized</SPAN
> <SPAN CLASS="cmr"
>types</SPAN
></DT
><DD
><P CLASS="j"
>[This category includes, for example, <A HREF="t_character.html" CLASS="typeref"
><B
>character</B
></A
>, <A HREF="t_condition.html" CLASS="typeref"
><B
>condition</B
></A
>, <A HREF="t_function.html" CLASS="typeref"
><B
>function</B
></A
>, <A HREF="t_method-combination.html" CLASS="typeref"
><B
>method-combination</B
></A
>, <A HREF="t_method.html" CLASS="typeref"
><B
>method</B
></A
>, <A HREF="t_number.html" CLASS="typeref"
><B
>number</B
></A
>, <A HREF="t_package.html" CLASS="typeref"
><B
>package</B
></A
>, <A HREF="t_pathname.html" CLASS="typeref"
><B
>pathname</B
></A
>, <A HREF="t_restart.html" CLASS="typeref"
><B
>restart</B
></A
>, and <A HREF="t_symbol.html" CLASS="typeref"
><B
>symbol</B
></A
>.] </P
><P CLASS="j"
>There are no <A HREF="26_1_Glossary.html#standardized"
><EM CLASS="term"
>standardized</EM
></A
> <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operations defined on <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>objects</EM
></A
> of these <A HREF="26_1_Glossary.html#type"
><EM CLASS="term"
>types</EM
></A
>.</P
></DD
></DL
><H3 ID="sec_3_7_2" CLASS="HeadIII"
>3.7.2 Transfer of Control during a Destructive Operation</H3
><P CLASS="j"
>Should a transfer of control out of a <A HREF="26_1_Glossary.html#destructive"
><EM CLASS="term"
>destructive</EM
></A
> operation occur (<I CLASS="i"
><I
>e.g.</I
></I
>, due to an error) the state of the <VAR CLASS="param"
>object</VAR
> being modified is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
>.</P
><H4 ID="sec_3_7_2_1" CLASS="HeadIV"
>3.7.2.1 Examples of Transfer of Control during a Destructive Operation</H4
><P CLASS="j"
>The following examples illustrate some of the many ways in which the <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
> nature of the modification can manifest itself.</P
><PRE CLASS="screen"
> (let ((a (list 2 1 4 3 7 6 'five)))
(ignore-errors (sort a #'&lt;))
a)
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (1 2 3 4 6 7 FIVE)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (2 1 4 3 7 6 FIVE)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (2)
(prog foo ((a (list 1 2 3 4 5 6 7 8 9 10)))
(sort a #'(lambda (x y) (if (zerop (random 5)) (return-from foo a) (&gt; x y)))))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> (1 2 3 4 5 6 7 8 9 10)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (3 4 5 6 2 7 8 9 10 1)
<SPAN CLASS="sp"
><SPAN CLASS="arrow withabove"
><SPAN CLASS="above"
>or </SPAN
>&#8594;</SPAN
></SPAN
> (1 2 4 3)</PRE
></SECTION
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="3_6_Traversal_Rules_and_Side_Effects.html" CLASS="prev"
>&#8592;</A
><A HREF="3_8_Evaluation_and_Compilation_Dictionary.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>