XEROX SETF 2 4 1 SETF 1 4 By: Kelly Roach (Roach.pa@Xerox.com) Last Revised 23-JUL-85. SETF (SET Field) modifies the record package slightly to get the user the COMMON LISP SETF-style record accessing. Less verbose than CLISP fetch & replace, but without the drawbacks of packing record accesses into atoms as with CLISP infixes ":" and ".". To use, LOAD SETF.DCOM. (1) RECORD ACCESS. For any record name "r" and field name "f", SETF makes the following translations: (r.f d) => (fetch (r f) of d) (SETF (r.f d) v) => (replace (r f) of d with v) Thus, the following translations are effected by SETF: (POSITION.XCOORD P) => (fetch (POSITION XCOORD) of P) (SETF (REGION.LEFT R) 234) => (replace (REGION LEFT) of R with 234) These SETF expressions translate in exactly the same way as their fetch and replace counterparts, using the same CLISP machinery that fetch and replace use. An example of SETF usage. The following function CHANGEREGION changes a REGION's south-west and north-east corners to be POSITION1 and POSITION2 and returns the changed REGION. (DEFINEQ (CHANGEREGION (LAMBDA (REGION POSITION1 POSITION2) (* Make REGION's SW and NE corners be POSITION1 and POSITION2. *) (PROG () (SETF (REGION.LEFT REGION) (POSITION.XCOORD POSITION1)) (SETF (REGION.BOTTOM REGION) (POSITION.YCOORD POSITION1)) (SETF (REGION.WIDTH REGION) (IPLUS (POSITION.XCOORD POSITION2) (IMINUS (POSITION.XCOORD POSITION1)) 1)) (SETF (REGION.BOTTOM REGION) (IPLUS (POSITION.YCOORD POSITION2) (IMINUS (POSITION.YCOORD POSITION1)) 1)) (RETURN REGION))))) (2) ARRAY ACCESS. SETF used with ELT translates into a SETA form: (SETF (ELT ARRAY N) V) => (SETA ARRAY N V) The following loop would zero out an array called MYARRAY: (FOR I FROM 1 TO (ARRAYSIZE MYARRAY) DO (SETF (ELT MYARRAY I) 0)) (3) CAR & CDR ACCESS. SETF used with CAR and CDR translates into RPLACA and RPLACD forms: (SETF (CAR X) Y) => (RPLACA X Y) (SETF (CDR X) Y) => (RPLACD X Y) This loop records the number of occurences of each atom in LIST using an ALIST: (FOR ATOM IN LIST DO (SETQ BUCKET (ASSOC ATOM ALIST)) (COND (BUCKET (SETF (CDR BUCKET) (ADD1 (CDR BUCKET)))) (T (PUSH ALIST (CONS ATOM 0))))) (4) USER HOOK. The user can define his own SETF translations using property SETFDEF (This is how SETF for ELT, CAR, & CDR is implemented). If the user does (PUTPROP 'CADR 'SETFDEF '(RPLACA (CDR DATUM) NEWVALUE)) (PUTPROP 'ASSOC 'SETFDEF 'FOOFN) then SETF will make the translations (SETF (CADR X) Y) => (RPLACA (CDR X) Y) (SETF (ASSOC KEY ALST) V) => what (FOOFN '(ASSOC KEY ALST)) evals to. In general, if the user does (PUTPROP a 'SETFDEF setfdef) then SETF makes the translation (SETF (a d) n) => setdef with d & n substituted for DATUM & NEWVALUE if "setfdef" is a list and (SETF (a ...) ...) => what (setfdef '(SETF (a ...) ...)) evals to if "setfdef" is a litatom. (LIST ((PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC ) STARTINGPAGE# 1) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC ) STARTINGPAGE# NIL) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC ) STARTINGPAGE# NIL) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD CENTERED) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC )) (174 36 288 36) NIL) (HEADING NIL (HEADINGTYPE RUNNINGHEAD) (84 744 528 36) NIL) (TEXT NIL NIL (84 96 456 600) NIL)))))( ((8(8D PAGEHEADING RUNNINGHEADMODERN TERMINAL MODERN ?1(DEFAULTFONT 1 (GACHA 10) (GACHA 8) (TERMINAL 8)) MODERN MODERN MODERNLOGO HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN  HRULE.GETFNMODERN &= VT7 3-;MGHP Z$I)MG ~cz