unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Setting the nth element of a list
Date: Fri, 05 Jun 2009 17:08:59 +0200	[thread overview]
Message-ID: <7cab4mogz8.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: df76eb1b-0573-45dc-8f39-50bf311e1391@r13g2000vbr.googlegroups.com

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__


  reply	other threads:[~2009-06-05 15:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-04 21:08 Setting the nth element of a list Nordlöw
2009-06-04 22:06 ` Drew Adams
2009-06-04 22:35 ` Lennart Borgman
2009-06-05  2:25 ` Barry Margolin
2009-06-05 13:06   ` Nordlöw
2009-06-05 13:10     ` Nordlöw
2009-06-05 13:25       ` Pascal J. Bourguignon
2009-06-05 13:57         ` Nordlöw
2009-06-05 15:08           ` Pascal J. Bourguignon [this message]
2009-06-05 16:56           ` bigfaceworm
2009-06-06  6:01             ` Miles Bader
2009-06-05 20:51     ` Barry Margolin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7cab4mogz8.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).