User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:revappend [2019/09/14 05:00]
cl:functions:revappend [2019/09/20 16:00] (current)
Line 1: Line 1:
 +====== Function REVAPPEND, NRECONC ======
  
 +====Syntax====
 +  * **revappend** //list tail// → //​result-list//​
 +  * **nreconc ​ ** //list tail// → //​result-list//​
 +
 +====Arguments and Values====
 +  * //list// - a //​[[CL:​Glossary:​proper list]]//.
 +  * //tail// - an //​[[CL:​Glossary:​object]]//​. ​
 +  * //​result-list//​ - an //​[[CL:​Glossary:​object]]//​.
 +
 +====Description====
 +**revappend** constructs a //​[[CL:​Glossary:​copy]]//​ of //list//, but with the //​[[CL:​Glossary:​elements]]//​ in reverse order. ​ It then appends (as if by **[[CL:​Functions:​nconc]]**) the //tail// to that reversed list and returns the result.
 +
 +**nreconc** reverses the order of //​[[CL:​Glossary:​elements]]//​ in //list// (as if by **[[CL:​Functions:​nreverse]]**). ​ It then appends (as if by **[[CL:​Functions:​nconc]]**) the //tail// to that reversed list and returns the result.
 +
 +The resulting //​[[CL:​Glossary:​list]]//​ shares //​[[CL:​Glossary:​list structure]]//​ with //tail//.
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Special Operators:​let]] ((list-1 ([[CL:​Functions:​list]] 1 2 3))
 +      (list-2 ([[CL:​Functions:​list]] 'a 'b 'c)))
 +  ([[CL:​Functions:​print]] (revappend list-1 list-2))
 +  ([[CL:​Functions:​print]] ([[CL:​Functions:​equal]] list-1 '(1 2 3)))
 +  ([[CL:​Functions:​print]] ([[CL:​Functions:​equal]] list-2 '(a b c))))
 +<o>(3 2 1 A B C) 
 +[[CL:​Constant Variables:​t|T]]
 +[[CL:​Constant Variables:​t|T]]</​o>​
 +<​r>​[[CL:​Constant Variables:​t|T]]</​r>​
 +
 +(revappend '(1 2 3) '()) <r>(3 2 1)</​r>​
 +(revappend '(1 2 3) '(a . b)) <r>(3 2 1 A . B)</​r>​
 +(revappend '() '(a b c)) <r>(A B C)</​r>​
 +(revappend '(1 2 3) 'a) <r>(3 2 1 . A)</​r>​
 +(revappend '() 'a) <r>A ; degenerate case</​r>​
 +
 +([[CL:​Special Operators:​let]] ((list-1 ([[CL:​Functions:​list]] 1 2 3))
 +      (list-2 ([[CL:​Functions:​list]] 'a 'b 'c)))
 +  ([[CL:​Functions:​print]] (nreconc list-1 list-2))
 +  ([[CL:​Functions:​print]] ([[CL:​Functions:​equal]] list-1 '(1 2 3)))
 +  ([[CL:​Functions:​print]] ([[CL:​Functions:​equal]] list-2 '(a b c))))
 +<o>(3 2 1 A B C) 
 +[[CL:​Constant Variables:​nil|NIL]]
 +[[CL:​Constant Variables:​t|T]]</​o>​
 +<​r>​[[CL:​Constant Variables:​t|T]]</​r>​
 +
 +</​blockquote>​
 +
 +====Side Effects====
 +**revappend** does not modify either of its //​[[CL:​Glossary:​argument|arguments]]//​. **nreconc** is permitted to modify //list// but not //tail//.
 +
 +Although it might be implemented differently,​ **nreconc** is constrained to have side-effect behavior equivalent to:
 +
 +<​blockquote>​
 +([[CL:​Functions:​nconc]] (nreverse //list//) //tail//)
 +</​blockquote>​
 +
 +====Affected By====
 +None.
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +**[[CL:​Functions:​reverse|Function REVERSE]]**,​ **[[CL:​Functions:​nreverse|Function NREVERSE]]**,​ **[[CL:​Functions:​nconc|Function NCONC]]**
 +
 +====Example Implementation====
 +The following functional equivalences are true,  although good //​[[CL:​Glossary:​implementation|implementations]]//​ will typically use a faster algorithm for achieving the same effect:
 +
 +<​blockquote>​
 +(revappend //list// //tail//) ≡ ([[CL:​Functions:​nconc]] ([[CL:​Functions:​reverse]] //list//) //tail//)
 +(nreconc //list// //tail//) ≡ ([[CL:​Functions:​nconc]] ([[CL:​Functions:​nreverse]] //list//) //tail//)
 +</​blockquote>​
 +
 +====Notes====
 +None.
 +
 +\issue{REMF-DESTRUCTION-UNSPECIFIED:​X3J13-MAR-89}
 +\issue{DOTTED-LIST-ARGUMENTS:​CLARIFY}