[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Setting the nth element of a list
From: |
Pascal J. Bourguignon |
Subject: |
Re: Setting the nth element of a list |
Date: |
Fri, 05 Jun 2009 17:08:59 +0200 |
User-agent: |
Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux) |
Nordlöw <per.nordlow@gmail.com> writes:
> I really believe such a function increases the readability of the code
> that uses it, don't you?
> What if I define it as a macro (defmacro) or inline (defsubst)?
> Doesn't that give the best of both worlds+
Readability is somewhat in the eyes of the reader.
That said, I can just repeat wat I wrote: setf is a standard and well
known operator designed to assign a value to any kind of place, so it
will be understood readily by any lisp programmer.
Defining redundant and specific operators just give you more work --
if you change the type of a sequence between list and vector, you'll
have to edit all the place where you used setnthcar or setnthref
instead of (setf (elt ...) ...) -- and it will give more work to the
reader who will have to refer to your functions definitions to know
what they mean.
If you were talking about a new kind of data structure, I'd agree that
it would be ok to define a setter, but then it would have to be
defined with the arguments in the 'correct' order:
(defun set-my-own-data-structure (new-value data-structure index1 ...) ...)
so you could bind it to setf:
(defsetf my-own-data-structure set-my-own-data-structure)
and right away forget about set-my-own-data-structure, but write:
(setf (my-own-data-structure my-ds i...) new-value)
--
__Pascal Bourguignon__
- Setting the nth element of a list, Nordlöw, 2009/06/04
- RE: Setting the nth element of a list, Drew Adams, 2009/06/04
- Re: Setting the nth element of a list, Lennart Borgman, 2009/06/04
- Re: Setting the nth element of a list, Barry Margolin, 2009/06/04
- Re: Setting the nth element of a list, Nordlöw, 2009/06/05
- Re: Setting the nth element of a list, Nordlöw, 2009/06/05
- Re: Setting the nth element of a list, Pascal J. Bourguignon, 2009/06/05
- Re: Setting the nth element of a list, Nordlöw, 2009/06/05
- Re: Setting the nth element of a list,
Pascal J. Bourguignon <=
- Re: Setting the nth element of a list, bigfaceworm, 2009/06/05
- Re: Setting the nth element of a list, Miles Bader, 2009/06/06
- Re: Setting the nth element of a list, Barry Margolin, 2009/06/05