CLHS: Section 5.1.1.2.1

#

## 5.1.1.2.1 Examples of Setf Expansions

Examples of the contents of the constituents of setf expansions follow.

For a variable x:

    ()              ;list of temporary variables
    ()              ;list of value forms
    (g0001)         ;list of store variables
    (setq x g0001)  ;storing form
    x               ;accessing form

Figure 5-3. Sample Setf Expansion of a Variable

For `(car` exp`)`:

    (g0002)                             ;list of temporary variables
    (exp)                               ;list of value forms
    (g0003)                             ;list of store variables
    (progn (rplaca g0002 g0003) g0003)  ;storing form
    (car g0002)                         ;accessing form

Figure 5-4. Sample Setf Expansion of a CAR Form

For `(subseq` seq`` s`` e`)`:

    (g0004 g0005 g0006)         ;list of temporary variables
    (seq s e)                   ;list of value forms
    (g0007)                     ;list of store variables
    (progn (replace g0004 g0007 :start1 g0005 :end1 g0006) g0007)
                                ;storing form
    (subseq g0004 g0005 g0006)  ; accessing form

Figure 5-5. Sample Setf Expansion of a SUBSEQ Form

In some cases, if a subform of a place is itself a place, it is necessary to expand the subform in order to compute some of the values in the expansion of the outer place. For `(ldb` bs`(car` exp`))`:

    (g0001 g0002)            ;list of temporary variables
    (bs exp)                 ;list of value forms
    (g0003)                  ;list of store variables
    (progn (rplaca g0002 (dpb g0003 g0001 (car g0002))) g0003)
                             ;storing form
    (ldb g0001 (car g0002))  ; accessing form

Figure 5-6. Sample Setf Expansion of a LDB Form

The following X3J13 cleanup issue, not part of the specification, applies to this section:

- SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS

Copyright 1996-2005, LispWorks Ltd. All rights reserved.