GNU bug report logs - #23550
25.0.93; cl.texi (for var on list by func): Fix documentation

Previous Next

Package: emacs;

Reported by: Tino Calancha <f92capac <at> gmail.com>

Date: Mon, 16 May 2016 15:47:02 UTC

Severity: minor

Tags: patch

Found in version 25.0.93

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23550 in the body.
You can then email your comments to 23550 AT debbugs.gnu.org in the normal way.

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#23550; Package emacs. (Mon, 16 May 2016 15:47:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <f92capac <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 16 May 2016 15:47:02 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <f92capac <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.93; cl.texi (for var on list by func): Fix documentation
Date: Tue, 17 May 2016 00:49:02 +0900 (JST)
* doc/misc/cl.texi (for var on list by func): Fix documentation

'cl-loop for var on list by func' behaves as in CL: 'on' expression
need to be a list.

The following tests run in the *scratch* buffer return
same values as in SBCL: 
;; CL cl-loop -> loop

emacs -Q:

(require 'cl-lib)
(setq preys '("grass" "lion" "rabbit"))

(defun next-prey (x)
  "Return the name of the prey of animal X."
  (cl-loop while (not (atom x))
           do (setq x (car x)))
  (cond ((member x preys) ; elisp
  ;; (cond ((member x preys :test #'string=) ; CL
         (cond ((string= x "lion") "rabbit")
               ((string= x "rabbit") "grass")
               (t nil)))
        (t
         nil)))
(defun next-prey-list (x)
  "Return a list with the name of the prey of animal X."
  (let ((res (next-prey x)))
    (if res
        (list res)
      nil)))

[A] (mapcar 'next-prey '("grass" "lion" "rabbit"))
[B] (mapcar 'next-prey-list '("grass" "lion" "rabbit"))

[A] (nil "rabbit" "grass")
[B] (nil ("rabbit") ("grass"))

[I]   (cl-loop for y on preys collect y)
[II]  (cl-loop for y on preys by #'next-prey collect y)
[III] (cl-loop for y on (car preys) by #'next-prey collect y)
[IV]  (cl-loop for y on (car preys) by #'next-prey-list collect y)
[V]   (cl-loop for y on preys by #'next-prey-list collect y)

[I]   (("grass" "lion" "rabbit") ("lion" "rabbit") ("rabbit"))
[II]  (("grass" "lion" "rabbit"))
[III] nil
[IV]  nil
[V]   (("grass" "lion" "rabbit"))


In GNU Emacs 25.0.93.3 (x86_64-pc-linux-gnu, GTK+ Version 2.24.30)
Repository revision: 6de0715f5467d4b925e2dfe082174529ace3b174


From 3e1756fb4d76e34b74b96782d4509582e9ce0cd3 Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac <at> gmail.com>
Date: Tue, 17 May 2016 00:04:56 +0900
Subject: [PATCH] ; * cl.texi (clause 'for' with 'on'): Fix documentation

---
 doc/misc/cl.texi | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi
index 4137a95..319592c 100644
--- a/doc/misc/cl.texi
+++ b/doc/misc/cl.texi
@@ -1956,18 +1956,6 @@ For Clauses
         @result{} ((1 2 3 4) (2 3 4) (3 4) (4))
 @end example

-With @code{by}, there is no real reason that the @code{on} expression
-must be a list.  For example:
-
-@example
-(cl-loop for x on first-animal by 'next-animal collect x)
-@end example
-
-@noindent
-where @code{(next-animal x)} takes an ``animal'' @var{x} and returns
-the next in the (assumed) sequence of animals, or @code{nil} if
-@var{x} was the last animal in the sequence.
-
 @item for @var{var} in-ref @var{list} by @var{function}
 This is like a regular @code{in} clause, but @var{var} becomes
 a @code{setf}-able ``reference'' onto the elements of the list
-- 
2.8.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23550; Package emacs. (Sun, 26 Mar 2017 03:01:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Tino Calancha <f92capac <at> gmail.com>
Cc: 23550 <at> debbugs.gnu.org
Subject: Re: bug#23550: 25.0.93;
 cl.texi (for var on list by func): Fix documentation
Date: Sat, 25 Mar 2017 23:01:45 -0400
Tino Calancha <f92capac <at> gmail.com> writes:

> * doc/misc/cl.texi (for var on list by func): Fix documentation
>
> 'cl-loop for var on list by func' behaves as in CL: 'on' expression
> need to be a list.

Well, it only needs to be a cons, because that's what the loop checks
for.

>
> emacs -Q:
>
> (require 'cl-lib)
> (setq preys '("grass" "lion" "rabbit"))
>
> (defun next-prey (x)
>   "Return the name of the prey of animal X."
>   (cl-loop while (not (atom x))
>            do (setq x (car x)))
>   (cond ((member x preys) ; elisp
>   ;; (cond ((member x preys :test #'string=) ; CL
>          (cond ((string= x "lion") "rabbit")
>                ((string= x "rabbit") "grass")
>                (t nil)))
>         (t
>          nil)))
> (defun next-prey-list (x)
>   "Return a list with the name of the prey of animal X."
>   (let ((res (next-prey x)))
>     (if res
>         (list res)
>       nil)))

I guess the idea behind that statement is that the rest of the list can
be implied by the stepping function, e.g.

    (cl-loop for y on (list "lion") by #'next-prey-list collect (car y))
      ;=> ("lion" "rabbit" "grass")

Works with the "in" clause too:

    (cl-loop for y in (list "lion") by #'next-prey-list collect y)
      ;=> ("lion" "rabbit" "grass")

I guess it could be useful in combination with streams?  Not sure if
it's worth having this in the manual.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23550; Package emacs. (Wed, 29 Mar 2017 13:27:01 GMT) Full text and rfc822 format available.

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

From: Tino Calancha <tino.calancha <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: Tino Calancha <f92capac <at> gmail.com>, 23550 <at> debbugs.gnu.org
Subject: Re: bug#23550: 25.0.93;
 cl.texi (for var on list by func): Fix documentation
Date: Wed, 29 Mar 2017 22:26:27 +0900
npostavs <at> users.sourceforge.net writes:

>>
>> emacs -Q:
>>
>> (require 'cl-lib)
>> (setq preys '("grass" "lion" "rabbit"))
>>
>> (defun next-prey (x)
>>   "Return the name of the prey of animal X."
>>   (cl-loop while (not (atom x))
>>            do (setq x (car x)))
>>   (cond ((member x preys) ; elisp
>>   ;; (cond ((member x preys :test #'string=) ; CL
>>          (cond ((string= x "lion") "rabbit")
>>                ((string= x "rabbit") "grass")
>>                (t nil)))
>>         (t
>>          nil)))
>> (defun next-prey-list (x)
>>   "Return a list with the name of the prey of animal X."
>>   (let ((res (next-prey x)))
>>     (if res
>>         (list res)
>>       nil)))
>
> I guess the idea behind that statement is that the rest of the list can
> be implied by the stepping function, e.g.
>
>     (cl-loop for y on (list "lion") by #'next-prey-list collect (car y))
>       ;=> ("lion" "rabbit" "grass")
>
> Works with the "in" clause too:
>
>     (cl-loop for y in (list "lion") by #'next-prey-list collect y)
>       ;=> ("lion" "rabbit" "grass")
>
> I guess it could be useful in combination with streams?  Not sure if
> it's worth having this in the manual.
In the way is written makes me expect that:
(cl-loop for y on "lion" by #'next-prey-list collect (car y))

will be evaluated to: ("lion" "rabbit" "grass").

Becase i read in the example first-animal, instead of (list first-animal), 
and they also write:
'With @code{by}, there is no real reason that the @code{on} expression
must be a list.'

It might be useful rewrite that part to make it more clear, but i don't
have a clear proposal.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#23550; Package emacs. (Wed, 29 Mar 2017 14:07:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Tino Calancha <tino.calancha <at> gmail.com>
Cc: Tino Calancha <f92capac <at> gmail.com>, 23550 <at> debbugs.gnu.org
Subject: Re: bug#23550: 25.0.93;
 cl.texi (for var on list by func): Fix documentation
Date: Wed, 29 Mar 2017 10:08:14 -0400
Tino Calancha <tino.calancha <at> gmail.com> writes:

> It might be useful rewrite that part to make it more clear, but i don't
> have a clear proposal.

Actually, looking at this some more, I think you should just apply your
patch that removes this stuff completely.  It's much clearer to write
that sort of example as

    (cl-loop for y = "lion" then (next-prey y)
             while y collect y)

And looking down the page, `for VAR = EXPR1 then EXPR2' is already
explained well enough (as well as the equivalence to the `for VAR on
LIST by FUNCTION' form).




Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Fri, 31 Mar 2017 08:21:01 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <f92capac <at> gmail.com>:
bug acknowledged by developer. (Fri, 31 Mar 2017 08:21:02 GMT) Full text and rfc822 format available.

Message #19 received at 23550-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 23550-done <at> debbugs.gnu.org
Subject: Re: bug#23550: 25.0.93;
 cl.texi (for var on list by func): Fix documentation
Date: Fri, 31 Mar 2017 17:20:31 +0900
npostavs <at> users.sourceforge.net writes:

> Tino Calancha <tino.calancha <at> gmail.com> writes:
>
>> It might be useful rewrite that part to make it more clear, but i don't
>> have a clear proposal.
>
> Actually, looking at this some more, I think you should just apply your
> patch that removes this stuff completely.  It's much clearer to write
> that sort of example as
>
>     (cl-loop for y = "lion" then (next-prey y)
>              while y collect y)
>
> And looking down the page, `for VAR = EXPR1 then EXPR2' is already
> explained well enough (as well as the equivalence to the `for VAR on
> LIST by FUNCTION' form).
Thank you.
Pushed fix into emacs-25 branch with commit:
3f0d047d2eb1fb59be2ff962c01392d8c808a654




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Apr 2017 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 55 days ago.

Previous Next


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