Gnus development mailing list
 help / color / mirror / Atom feed
From: Daniel Pittman <daniel@rimspace.net>
Subject: Re: cl in message.el, etc
Date: Sat, 20 Apr 2002 13:43:44 +1000	[thread overview]
Message-ID: <87lmbjm3v3.fsf@inanna.rimspace.net> (raw)
In-Reply-To: <87g01r74d7.fsf@alum.wpi.edu> (Josh Huber's message of "Fri, 19 Apr 2002 17:41:56 -0400")

On Fri, 19 Apr 2002, Josh Huber wrote:
> I was thinking of changing this:
> 
>  	     (eval
>  	      (apply 'append '(or)
>  		     (mapcar
>  		      #'(lambda (regexp)
>  			  (mapcar
>  			   #'(lambda (recipient)
>  			       `(when (string-match ,regexp ,recipient)
>  				  ,recipient))
>  			   recipients))
>  		      mft-regexps)))))

[...]

> But, the CL loop macro looks pretty disgusting when mixed in with
> other lisp code IMHO, and I think we're supposed to try to avoid using
> cl in the Gnus code.

In Emacs, actually, because of the distaste that RMS (and possibly other
Emacs developers) feel for it. XEmacs dumps cl and, as such, don't
object to it's use. ;)

[...]

> Does this sound ok?

I certainly think that it's a better way of expressing things than the
current code...

On Fri, 19 Apr 2002, Josh Huber wrote:
> Josh Huber <huber@alum.wpi.edu> writes:
> 
>>  	     (loop for regexp in mft-regexps and recipient in recipients
>>  	       thereis (when (string-match regexp recipient)
>>  			 recipient))))
>>
>> Since It's a lot shorter, and (I think) easier to read.
> 
> Oh, and it also doesn't work. ;)  Here's the working version:
> 
>  	     (loop for regexp in mft-regexps thereis
> 	       (loop for recipient in recipients
> 		 thereis (when (string-match regexp recipient)
> 			   recipient)))))
> 
> what do other people think?

...but you possibly want this, which is all of correct, efficient and
clear, I think. OTOH, I grok loop[1] in Common Lisp so I am probably
biased. :)

(loop for regexp in mft-regexps and recipient in recipients
      when (string-match regexp recipient) return recipient)

The key is the 'return' statement. That tells the loop to terminate,
returning the specified value. Your original didn't work because it
failed to do then. 'when' is also nice for the sort of conditional
execution you want. :)

> BTW, the execution speed seems to be about the same.  

It should be. The code seen before is /almost/ the open-coded version of
the loop macro, except that it calls eval one extra time. :)

        Daniel


Footnotes: 
[1]  ...even if I don't think it's the best iteration construct in the
     world. :)

-- 
If a voice inside tells you that you are not a painter, then by all means
paint! And that voice will be silenced...
        -- Vincent Van Gogh



  parent reply	other threads:[~2002-04-20  3:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-19 21:41 Josh Huber
2002-04-19 22:13 ` Josh Huber
2002-04-20  3:43 ` Daniel Pittman [this message]
2002-04-20 15:14   ` Josh Huber
2002-04-20 16:03     ` Daniel Pittman
2002-04-20 17:34       ` Josh Huber
2002-04-21  2:28         ` Daniel Pittman
2002-04-22  8:18   ` Kai Großjohann

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lmbjm3v3.fsf@inanna.rimspace.net \
    --to=daniel@rimspace.net \
    /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.
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 NNTP newsgroup(s).