[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing Destructive Functions
- To: info-mcl
- Subject: Re: Writing Destructive Functions
- From: york@oakland-hills.lucid.com (Bill York)
- Date: 22 Sep 92 18:27:36 GMT
- In-reply-to: jbk@world.std.com's message of 21 Sep 92 15:30:00 GMT
- Newsgroups: comp.lang.lisp.mcl
- Organization: Lucid, Inc.
- References: <199209211530.AA14643@world.std.com>
- Reply-to: York@Lucid.COM
- Sender: usenet@lucid.com
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)
list)
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.