[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing Destructive Functions

In article <199209211530.AA14643@world.std.com> jbk@world.std.com (Jeffrey B Kane) writes:

   I want to implement something where a parameter is passed in a similar
   fashion to the "var" in Pascal or "aType* aParameterPtr" in C or "aType&
   aParameter" in C++. This is particular important in two areas:

   string manipulation

   lists, where I need to change the first element of the list

You can use SETF on the various list component accessors to alter the
contents of a list.

(defun replace-first (list new-element)
  (setf (car list) new-element)

   An example might be my own version of "adjoin" or a (delete-substring
   aString :start 2 :stop 4) kind of function.

You can replace the elements of a string (or an array) by using SETF
of AREF of the elements in question.