From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: bug-gnu-emacs@gnu.org
Subject: bug#6583: 23.2; cl loop macro with `and' clause
Date: Thu, 08 Jul 2010 09:40:22 +0200 [thread overview]
Message-ID: <87hbkah15l.fsf@tux.homenetwork> (raw)
In-Reply-To: <871vbedfzq.fsf@blah.blah>
Kevin Ryde <user42@zip.com.au> writes:
> Evaluating
>
> (require 'cl)
> (loop for elem in '(1 2 3)
> for k = elem and j = 99
> do
> (print k))
IMHO this is not correct, 'and' clauses should be used after conditionals
(e.g if, when etc..)
,----
| ELISP> (loop for elem in '(1 2 3)
| for k = elem
| if (oddp k)
| collect k and do (print k))
`----
> shows
>
> 1
> 1
> 2
Instead of returning this, emacs should throw an error as SBCL does for
same code.
,----
| CL-USER> (loop for i in '(1 2 3)
| for k = i and j = 99
| (print k))
| ; Evaluation aborted.
`----
> where I thought it might be
>
> 1
> 2
> 3
>
> I'm don't know much about the cl loop macro but thought the `for k' step
> would be evaluated after the `for elem' step, "sequential" per the cl
> info manual near the end of "For Clauses"
>
> If you include several `for' clauses in a row, they are treated
> sequentially
>
> The 1,2,3 is what you get from pasting the same form into clisp, if that
> suggests what an actual common lisp does or should do. And in Emacs
> it's had if you omit the "and j",
>
> (loop for elem in '(1 2 3)
> for k = elem
> do
> (print k))
> =>
> 1 2 3
>
> Nosing around the macro expansion I wondered if the "step" of k/j gets
> mispositioned if there's an `and', but it's hard to be sure.
>
>
> I struck this when making a loop over an alist where I thought to take
> apart the key and value with an `and' as they didn't need to be
> sequential,
>
> (loop for elem in my-alist
> for k = (car elem) and v = (cdr elem)
> do
> ...
>
> Alas the effect of the "1 1 2" was to double the first element and omit
> the last.
>
>
> In GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0)
> of 2010-05-16 on raven, modified by Debian
> configured using `configure '--build' 'i486-linux-gnu' '--build' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' '--with-toolkit-scroll-bars' 'build_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''
>
> Important settings:
> value of $LC_ALL: nil
> value of $LC_COLLATE: nil
> value of $LC_CTYPE: nil
> value of $LC_MESSAGES: nil
> value of $LC_MONETARY: nil
> value of $LC_NUMERIC: nil
> value of $LC_TIME: nil
> value of $LANG: en_AU
> value of $XMODIFIERS: nil
> locale-coding-system: iso-latin-1-unix
> default enable-multibyte-characters: t
>
>
>
>
--
Thierry Volpiatto
Gpg key: http://pgp.mit.edu/
next prev parent reply other threads:[~2010-07-08 7:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-07 23:33 bug#6583: 23.2; cl loop macro with `and' clause Kevin Ryde
2010-07-08 7:40 ` Thierry Volpiatto [this message]
2010-07-08 8:28 ` Lawrence Mitchell
2016-06-02 22:06 ` Noam Postavsky
2017-06-10 19:10 ` Alex
2017-06-25 0:22 ` npostavs
2017-06-25 3:03 ` Alex
2020-09-14 13:10 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87hbkah15l.fsf@tux.homenetwork \
--to=thierry.volpiatto@gmail.com \
--cc=bug-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).