unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29799: 24.5; cl-loop guard clause missing
@ 2017-12-21  9:38 Tino Calancha
  2018-01-01 21:46 ` Noam Postavsky
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Tino Calancha @ 2017-12-21  9:38 UTC (permalink / raw)
  To: 29799; +Cc: monnier, npostavs

X-Debbugs-CC: monnier@iro.umontreal.ca,npostavs@gmail.com

Consider the following snippet code:

--8<-----------------------------cut here---------------start------------->8---
(require 'cl-lib)
(let* ((size 7)
       (arr (make-vector size 0)))
  (cl-loop for k below size
           for x = (* 2 k) and y = (1+ (elt arr k))
           collect (list k x y)))
--8<-----------------------------cut here---------------end--------------->8---

When you execute the form above it fails because
the loop overrun `arr'.

The equivalent code in CL works:
--8<-----------------------------cut here---------------start------------->8---
(let* ((size 7)
       (arr (make-array size :initial-element 0)))
  (loop :for k :below size
           :for x = (* 2 k) :and y = (1+ (elt arr k))
           :collect (list k x y)))
--8<-----------------------------cut here---------------end--------------->8---

* The expansion of `loop' in CL checks the condition
  (>= k 7)
  right before update the internal variables (`x' and `y').

* The expansion of `cl-loop' instead, doesn't check the condition
  before update the vars  =>  in the code above we overrun `arr'.


In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-09-12 on hullmann, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11902000
System Description:	Debian GNU/Linux 9.3 (stretch)





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

end of thread, other threads:[~2019-11-22 14:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-21  9:38 bug#29799: 24.5; cl-loop guard clause missing Tino Calancha
2018-01-01 21:46 ` Noam Postavsky
2018-01-01 22:58   ` Noam Postavsky
2018-01-03 10:34     ` Tino Calancha
2018-01-06 13:43       ` Noam Postavsky
2018-01-08 10:20         ` Tino Calancha
2019-10-28  3:59 ` dick.r.chiang
2019-11-21 23:25 ` dick.r.chiang
2019-11-22 12:55   ` Lars Ingebrigtsen
2019-11-22 13:51     ` dick.r.chiang
2019-11-22 14:53       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).