Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!ucbvax!decwrl!hplabs!sm.unisys.com!randvax!valley!stan
From: stan@valley.UUCP (Stanley L. Kameny)
Newsgroups: comp.lang.lisp
Subject: Re: Setf Method for LAST
Message-ID: <37.UUL1.2#239@valley.UUCP>
Date: 19 Sep 88 14:02:57 GMT
References: <3673@phoenix.Princeton.EDU>
Lines: 19


Assuming that your lisp uses DE to define a function (if not, you can
readily change this to whatever is appropriate in your version of lisp),
the following should work:

  (DE LASTPP (X)
     (COND ((OR (ATOM X)(ATOM (CDR X))) NIL)
           ((ATOM (CDDR X)) X) (T(LASTPP (CDR X)))))
  (DE RPLALAST(X Y) (PROG2 (RPLACD (LASTPP X) Y) X))

at least, it works on my system:

 (RPLALAST '(1 2 3 4) '(5))
(1 2 3 5)

Stan Kameny  valley!stan@rand.org   {sm.unisys.com!}randvax!valley!stan
      14314 Hatteras Street, Van Nuys, CA 91401    (818)-994-7767

   Prends moi tel que je suis.        Ricketts House motto (Caltech)
   Honi soit qui mal y pense.         Order of the Garter motto (GB)