emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] master b7fa6b1 1/4: Simplify use of FOR_EACH_TAIL


From: Paul Eggert
Subject: Re: [Emacs-diffs] master b7fa6b1 1/4: Simplify use of FOR_EACH_TAIL
Date: Sun, 5 Feb 2017 21:23:43 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

Stefan Monnier wrote:
I'm surprised you
also decided to remove `tail`, since that one *is* used by the users of
the macro and forcing them to use `li.tail` instead of the variable of
their choice is rather odd.

Logically, the variable is part of the iterator, not of the surrounding code. I did at first write a macro along the lines that you suggest, and also tried another variant where the user could specify a name of their choice for the iterator, but in both cases this extra flexibility made the code a bit more verbose and was not that useful in practice. It would be easy to resurrect this flexibility if needed (it doesn't affect efficiency, of course).

Here's an example. At first, I wrote a revised version like this:

  Lisp_Object tail;
  FOR_EACH_TAIL (tail, list)
    if (EQ (XCAR (tail), elt))
      return true;

but this was annoying both because the user must declare 'tail', and because typically 'tail' should not survive the loop but the declaration forces it to survive. I wanted something more like this:

  FOR_EACH_TAIL (tail, list)
    if (EQ (XCAR (tail), elt))
      return true;

where the macro declares 'tail' to be local to the loop. Unfortunately there doesn't seem to be any way to that in portable C. So I settled for this:

  FOR_EACH_TAIL (list)
    if (EQ (XCAR (li.tail), elt))
      return true;

which is even shorter than what I wanted, albeit with an 'li.tail' that looks odd at least at first. Although we could easily change things to let the caller specify a name, like this:

  FOR_EACH_TAIL (li, list)
    if (EQ (XCAR (li.tail), elt))
      return true;

it's rare to need different names for iterators, so it's unclear that this extra complexity would be helpful.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]