GNU bug report logs - #62037
(proper-list-p '#1=(a #1#)) => 2. It should return nil.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Tue, 7 Mar 2023 17:31:01 UTC

Severity: normal

To reply to this bug, email your comments to 62037 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Tue, 07 Mar 2023 17:31:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 07 Mar 2023 17:31:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
Date: Tue, 7 Mar 2023 17:29:53 +0000
-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Wed, 08 Mar 2023 04:34:02 GMT) Full text and rfc822 format available.

Message #8 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Ruijie Yu <ruijie <at> netyu.xyz>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Wed, 08 Mar 2023 12:13:50 +0800
Notice the distinction between these two snippets:

    (let ((lst-1 '#1=(a #1#)))
      (list lst-1 (proper-list-p lst-1)))
    ;; => ((a #1) 2)

    (let ((lst-2 '#1=(a . #1#)))
      (list lst-2 (proper-list-p lst-2)))
    ;; => ((a . #0) nil)

Apparently, at least from the current behaviors, lst-1 is considered a
"proper list" because it is not a *circular list* [1], but still a
*circular object* [2].  This is because, in
essense, this is a list of two elements,
where the first one is 'a, and the second one is lst-1 itself.
Rewriting lst-1, we see that lst-1 is also not considered as dotted.

    (setq lst-1 '#1=(a #1# . nil))

That said, given that the docstring has some ambiguities on what
"circular" means -- as in, whether it means "circular list" or "circular
object", maybe at least the docstring and the Elisp manual about
`proper-list-p' should be updated to clarify which one it means?  Then
the implementation of `proper-list-p' can follow suite if necessary.

[1]:
(info "(elisp) Cons Cells")

> If the CDR of a list’s last cons cell is some value other than ‘nil’,
> we call the structure a “dotted list”, since its printed
> representation would use dotted pair notation (*note Dotted Pair
> Notation::).  There is one other possibility: some cons cell’s CDR
> could point to one of the previous cons cells in the list.  We call
> that structure a “circular list”.

[2]:
(info "(elisp) Circular Objects")

> To represent shared or circular structures within a complex of Lisp
> objects, you can use the reader constructs ‘#N=’ and ‘#N#’.

--
Best,


RY




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Sat, 18 Mar 2023 07:42:01 GMT) Full text and rfc822 format available.

Message #11 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Ruijie Yu <ruijie <at> netyu.xyz>
Cc: Alan Mackenzie <acm <at> muc.de>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Sat, 18 Mar 2023 07:41:14 +0000
Ruijie Yu <ruijie <at> netyu.xyz> writes:

> Notice the distinction between these two snippets:
>
>     (let ((lst-1 '#1=(a #1#)))
>       (list lst-1 (proper-list-p lst-1)))
>     ;; => ((a #1) 2)
>
>     (let ((lst-2 '#1=(a . #1#)))
>       (list lst-2 (proper-list-p lst-2)))
>     ;; => ((a . #0) nil)

Doesn't this point resolve the issue?  Shouldn't the bug report be
closed?

-- 
Philip Kaludercic




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Sat, 18 Mar 2023 08:30:01 GMT) Full text and rfc822 format available.

Message #14 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: Ruijie Yu <ruijie <at> netyu.xyz>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Sat, 18 Mar 2023 08:29:02 +0000
Hello, Philip.

On Sat, Mar 18, 2023 at 07:41:14 +0000, Philip Kaludercic wrote:
> Ruijie Yu <ruijie <at> netyu.xyz> writes:

> > Notice the distinction between these two snippets:

> >     (let ((lst-1 '#1=(a #1#)))
> >       (list lst-1 (proper-list-p lst-1)))
> >     ;; => ((a #1) 2)

> >     (let ((lst-2 '#1=(a . #1#)))
> >       (list lst-2 (proper-list-p lst-2)))
> >     ;; => ((a . #0) nil)

> Doesn't this point resolve the issue?

No, it doesn't.  A circular list is defined (Elisp manual page "Lists
and Cons Cells") as one where "some cons cell’s CDR could point to one
of the previous cons cells in the list".  A proper list (page
"List-related Predicates") is one which is neither dotted nor circular.

The list #1=(a . #1#) is clearly circular.  proper-list-p should return
nil for it.

The purpose of proper-list-p is surely to find out in advance whether an
algorithm one wishes to run on a list can proceed without taking special
precautions for dottedness or circularity.  proper-list-p fails here.

> Shouldn't the bug report be closed?

Only once it's been fixed.

> -- 
> Philip Kaludercic

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Sat, 18 Mar 2023 13:49:01 GMT) Full text and rfc822 format available.

Message #17 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Ruijie Yu <ruijie <at> netyu.xyz>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Sat, 18 Mar 2023 13:48:40 +0000
Alan Mackenzie <acm <at> muc.de> writes:

> Hello, Philip.
>
> On Sat, Mar 18, 2023 at 07:41:14 +0000, Philip Kaludercic wrote:
>> Ruijie Yu <ruijie <at> netyu.xyz> writes:
>
>> > Notice the distinction between these two snippets:
>
>> >     (let ((lst-1 '#1=(a #1#)))
>> >       (list lst-1 (proper-list-p lst-1)))
>> >     ;; => ((a #1) 2)
>
>> >     (let ((lst-2 '#1=(a . #1#)))
>> >       (list lst-2 (proper-list-p lst-2)))
>> >     ;; => ((a . #0) nil)
>
>> Doesn't this point resolve the issue?
>
> No, it doesn't.  A circular list is defined (Elisp manual page "Lists
> and Cons Cells") as one where "some cons cell’s CDR could point to one
> of the previous cons cells in the list".  A proper list (page
> "List-related Predicates") is one which is neither dotted nor circular.
>
> The list #1=(a . #1#) is clearly circular.  proper-list-p should return
> nil for it.

But (proper-list-p '#1=(a . #1#)) does return nil?  And (proper-list-p
'#1=(a #1#)) does return 2, 

 +---+---+   +---+---+
 | a | ----->| | | ------> nil
 +---+---+   +-|-+---+
   ^           |
    \_________/

because #1=(a #1#)) is not a circular list, the cadr only has a
reference back to a the beginning of the list, but #1=(a . #1#)) is
cyclical because as you say a cdr points back to a previous cons cell:

 +---+---+
 | a | | |
 +---+-|-+
   ^   |  
    \__/

> The purpose of proper-list-p is surely to find out in advance whether an
> algorithm one wishes to run on a list can proceed without taking special
> precautions for dottedness or circularity.  proper-list-p fails here.
>
>> Shouldn't the bug report be closed?
>
> Only once it's been fixed.
>
>> --
>> Philip Kaludercic




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Fri, 31 Mar 2023 04:47:02 GMT) Full text and rfc822 format available.

Message #20 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Ruijie Yu <ruijie <at> netyu.xyz>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: Alan Mackenzie <acm <at> muc.de>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Fri, 31 Mar 2023 12:35:49 +0800
>> [...]
>>> Doesn't this point resolve the issue?
>>
>> No, it doesn't.  A circular list is defined (Elisp manual page "Lists
>> and Cons Cells") as one where "some cons cell’s CDR could point to one
>> of the previous cons cells in the list".  A proper list (page
>> "List-related Predicates") is one which is neither dotted nor circular.
>>
>> The list #1=(a . #1#) is clearly circular.  proper-list-p should return
>> nil for it.
>
> But (proper-list-p '#1=(a . #1#)) does return nil? [...]
>
> because #1=(a #1#)) is not a circular list, the cadr only has a
> reference back to a the beginning of the list, but #1=(a . #1#)) is
> cyclical because as you say a cdr points back to a previous cons cell:
> [...]
>
>> The purpose of proper-list-p is surely to find out in advance whether an
>> algorithm one wishes to run on a list can proceed without taking special
>> precautions for dottedness or circularity.  proper-list-p fails here.
> [...]

So, it all boils down to the fact that the current documentation is
lacking and/or ambiguous, in terms of "the purpose of `proper-list-p'",
as well as the two definitions of the adjective "circular", which are
not interchangeable in different contexts.

If we all agree that only some pieces of documentation need updating,
then I will try to come up with a patch(set) in the upcoming few days --
or someone else can, should one volunteers to do so.  FTR, I am still
waiting for a counter signature from FSF.

-- 
Best,


RY




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Fri, 31 Mar 2023 07:26:02 GMT) Full text and rfc822 format available.

Message #23 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Philip Kaludercic <philipk <at> posteo.net>
To: Ruijie Yu <ruijie <at> netyu.xyz>
Cc: Alan Mackenzie <acm <at> muc.de>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Fri, 31 Mar 2023 07:25:12 +0000
Ruijie Yu <ruijie <at> netyu.xyz> writes:

>>> [...]
>>>> Doesn't this point resolve the issue?
>>>
>>> No, it doesn't.  A circular list is defined (Elisp manual page "Lists
>>> and Cons Cells") as one where "some cons cell’s CDR could point to one
>>> of the previous cons cells in the list".  A proper list (page
>>> "List-related Predicates") is one which is neither dotted nor circular.
>>>
>>> The list #1=(a . #1#) is clearly circular.  proper-list-p should return
>>> nil for it.
>>
>> But (proper-list-p '#1=(a . #1#)) does return nil? [...]
>>
>> because #1=(a #1#)) is not a circular list, the cadr only has a
>> reference back to a the beginning of the list, but #1=(a . #1#)) is
>> cyclical because as you say a cdr points back to a previous cons cell:
>> [...]
>>
>>> The purpose of proper-list-p is surely to find out in advance whether an
>>> algorithm one wishes to run on a list can proceed without taking special
>>> precautions for dottedness or circularity.  proper-list-p fails here.
>> [...]
>
> So, it all boils down to the fact that the current documentation is
> lacking and/or ambiguous, in terms of "the purpose of `proper-list-p'",
> as well as the two definitions of the adjective "circular", which are
> not interchangeable in different contexts.

It might be lacking, but I don't think the explanation is ambiguous.
"its last cdr is nil" might not be awfully formal, but it does describe
the problem.

> If we all agree that only some pieces of documentation need updating,
> then I will try to come up with a patch(set) in the upcoming few days --
> or someone else can, should one volunteers to do so.  FTR, I am still
> waiting for a counter signature from FSF.

-- 
Philip Kaludercic




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Fri, 31 Mar 2023 07:46:02 GMT) Full text and rfc822 format available.

Message #26 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Ruijie Yu <ruijie <at> netyu.xyz>
To: Philip Kaludercic <philipk <at> posteo.net>
Cc: Alan Mackenzie <acm <at> muc.de>, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Fri, 31 Mar 2023 15:29:13 +0800
Philip Kaludercic <philipk <at> posteo.net> writes:
>> So, it all boils down to the fact that the current documentation is
>> lacking and/or ambiguous, in terms of "the purpose of `proper-list-p'",
>> as well as the two definitions of the adjective "circular", which are
>> not interchangeable in different contexts.
>
> It might be lacking, but I don't think the explanation is ambiguous.
> "its last cdr is nil" might not be awfully formal, but it does describe
> the problem.

I agree.  However, I would reorganize it slightly to make "cdr being
nil" stand out more.  See this snippet for `proper-list-p' docstring,
and note that I explicitly mentioned circular _list_ to avoid confusion.

--8<---------------cut here---------------start------------->8---
- A proper list is neither circular nor dotted (i.e., its last cdr is nil).
+ A proper list is a list whose last cdr is nil (i.e., neither a circular list nor dotted list).
--8<---------------cut here---------------end--------------->8---

Again, I find it problematic that there are two related definitions of
"circular", and the first search result for "circular" under Elisp info
manual is (info "(elisp) Circular Objects"), which is not what is
intended for `proper-list-p'.  This causes problems in understanding the
intended behavior of this function, manifested via this bug.

-- 
Best,


RY




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Fri, 31 Mar 2023 07:51:01 GMT) Full text and rfc822 format available.

Message #29 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ruijie Yu <ruijie <at> netyu.xyz>
Cc: acm <at> muc.de, philipk <at> posteo.net, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2. It should return nil.
Date: Fri, 31 Mar 2023 10:50:15 +0300
> Cc: Alan Mackenzie <acm <at> muc.de>, 62037 <at> debbugs.gnu.org
> Date: Fri, 31 Mar 2023 15:29:13 +0800
> From:  Ruijie Yu via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> Again, I find it problematic that there are two related definitions of
> "circular", and the first search result for "circular" under Elisp info
> manual is (info "(elisp) Circular Objects"), which is not what is
> intended for `proper-list-p'.

How did you search?  If you type "i circular RET", the first hit lands
you in "Cons Cells", where both "circular list" and proper-list-p are
described.  So I don't think I understand what you mean by "the first
search result".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62037; Package emacs. (Sat, 01 Apr 2023 14:20:01 GMT) Full text and rfc822 format available.

Message #32 received at 62037 <at> debbugs.gnu.org (full text, mbox):

From: Ruijie Yu <ruijie <at> netyu.xyz>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: acm <at> muc.de, philipk <at> posteo.net, 62037 <at> debbugs.gnu.org
Subject: Re: bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return
 nil.
Date: Sat, 01 Apr 2023 22:16:33 +0800
Eli Zaretskii <eliz <at> gnu.org> writes:

> [...]
> How did you search?  If you type "i circular RET", the first hit lands
> you in "Cons Cells", where both "circular list" and proper-list-p are
> described.  So I don't think I understand what you mean by "the first
> search result".

I used `s circular RET', because in my mind I want to _search_ for the
word "circular".  But I guess I never knew about `Info-index', so TIL.

-- 
Best,


RY




This bug report was last modified 1 year and 20 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.