GNU bug report logs -
#23550
25.0.93; cl.texi (for var on list by func): Fix documentation
Previous Next
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.
Full log
View this message in rfc822 format
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.
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.