all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
@ 2023-03-07 17:29 Alan Mackenzie
  2023-03-08  4:13 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2023-03-07 17:29 UTC (permalink / raw)
  To: 62037

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-07 17:29 bug#62037: (proper-list-p '#1=(a #1#)) => 2. It should return nil Alan Mackenzie
@ 2023-03-08  4:13 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-03-18  7:41   ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-03-08  4:13 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 62037


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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-08  4:13 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-03-18  7:41   ` Philip Kaludercic
  2023-03-18  8:29     ` Alan Mackenzie
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2023-03-18  7:41 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Alan Mackenzie, 62037

Ruijie Yu <ruijie@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-18  7:41   ` Philip Kaludercic
@ 2023-03-18  8:29     ` Alan Mackenzie
  2023-03-18 13:48       ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Alan Mackenzie @ 2023-03-18  8:29 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Ruijie Yu, 62037

Hello, Philip.

On Sat, Mar 18, 2023 at 07:41:14 +0000, Philip Kaludercic wrote:
> Ruijie Yu <ruijie@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).





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-18  8:29     ` Alan Mackenzie
@ 2023-03-18 13:48       ` Philip Kaludercic
  2023-03-31  4:35         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2023-03-18 13:48 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Ruijie Yu, 62037

Alan Mackenzie <acm@muc.de> writes:

> Hello, Philip.
>
> On Sat, Mar 18, 2023 at 07:41:14 +0000, Philip Kaludercic wrote:
>> Ruijie Yu <ruijie@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-18 13:48       ` Philip Kaludercic
@ 2023-03-31  4:35         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-03-31  7:25           ` Philip Kaludercic
  0 siblings, 1 reply; 10+ messages in thread
From: Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-03-31  4:35 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Alan Mackenzie, 62037


>> [...]
>>> 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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-31  4:35         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-03-31  7:25           ` Philip Kaludercic
  2023-03-31  7:29             ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Philip Kaludercic @ 2023-03-31  7:25 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Alan Mackenzie, 62037

Ruijie Yu <ruijie@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-31  7:25           ` Philip Kaludercic
@ 2023-03-31  7:29             ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-03-31  7:50               ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-03-31  7:29 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Alan Mackenzie, 62037


Philip Kaludercic <philipk@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2. It should return nil.
  2023-03-31  7:29             ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-03-31  7:50               ` Eli Zaretskii
  2023-04-01 14:16                 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-03-31  7:50 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: acm, philipk, 62037

> Cc: Alan Mackenzie <acm@muc.de>, 62037@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@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".





^ permalink raw reply	[flat|nested] 10+ messages in thread

* bug#62037: (proper-list-p '#1=(a #1#)) => 2.  It should return nil.
  2023-03-31  7:50               ` Eli Zaretskii
@ 2023-04-01 14:16                 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 10+ messages in thread
From: Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-04-01 14:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: acm, philipk, 62037


Eli Zaretskii <eliz@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





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-04-01 14:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-07 17:29 bug#62037: (proper-list-p '#1=(a #1#)) => 2. It should return nil Alan Mackenzie
2023-03-08  4:13 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-18  7:41   ` Philip Kaludercic
2023-03-18  8:29     ` Alan Mackenzie
2023-03-18 13:48       ` Philip Kaludercic
2023-03-31  4:35         ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-31  7:25           ` Philip Kaludercic
2023-03-31  7:29             ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-31  7:50               ` Eli Zaretskii
2023-04-01 14:16                 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.