Gnus development mailing list
 help / color / mirror / Atom feed
* cl in message.el, etc
@ 2002-04-19 21:41 Josh Huber
  2002-04-19 22:13 ` Josh Huber
  2002-04-20  3:43 ` Daniel Pittman
  0 siblings, 2 replies; 8+ messages in thread
From: Josh Huber @ 2002-04-19 21:41 UTC (permalink / raw)


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)))))


to this:

 	     (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.

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. (even though (eval-when-compile (require 'cl)) is
all over the place)

Does this sound ok?

-- 
Josh Huber



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

* Re: cl in message.el, etc
  2002-04-19 21:41 cl in message.el, etc Josh Huber
@ 2002-04-19 22:13 ` Josh Huber
  2002-04-20  3:43 ` Daniel Pittman
  1 sibling, 0 replies; 8+ messages in thread
From: Josh Huber @ 2002-04-19 22:13 UTC (permalink / raw)


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?

BTW, the execution speed seems to be about the same.  For me most of
the speed hit is taken in the gnus-find-subscribed-addresses
function. (since I have so many groups)

ttyl,

-- 
Josh Huber



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

* Re: cl in message.el, etc
  2002-04-19 21:41 cl in message.el, etc Josh Huber
  2002-04-19 22:13 ` Josh Huber
@ 2002-04-20  3:43 ` Daniel Pittman
  2002-04-20 15:14   ` Josh Huber
  2002-04-22  8:18   ` Kai Großjohann
  1 sibling, 2 replies; 8+ messages in thread
From: Daniel Pittman @ 2002-04-20  3:43 UTC (permalink / raw)


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



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

* Re: cl in message.el, etc
  2002-04-20  3:43 ` Daniel Pittman
@ 2002-04-20 15:14   ` Josh Huber
  2002-04-20 16:03     ` Daniel Pittman
  2002-04-22  8:18   ` Kai Großjohann
  1 sibling, 1 reply; 8+ messages in thread
From: Josh Huber @ 2002-04-20 15:14 UTC (permalink / raw)


BTW, thanks for the help ;)

Daniel Pittman <daniel@rimspace.net> writes:

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

I actually tried this at one point, but it didn't work for me, and
doesn't work in the message code.  Perhaps you could explain this to
me?

(defun jmh:loop-test (recipients)
  (let* ((mft-regexps '("list@foo\\.com\\|list2@bar\\.org\\|list3@baz\\.net"))
	 (list (loop for regexp in mft-regexps and recipient in recipients
		 when (string-match regexp recipient) return recipient)))
    list))

(jmh:loop-test '("list2@bar.org" "foo@bar.com")) => "list2@bar.org"
(jmh:loop-test '("foo@bar.com" "list2@bar.org")) => nil

I must be missing something pretty major ;)

Thanks,

-- 
Josh Huber



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

* Re: cl in message.el, etc
  2002-04-20 15:14   ` Josh Huber
@ 2002-04-20 16:03     ` Daniel Pittman
  2002-04-20 17:34       ` Josh Huber
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Pittman @ 2002-04-20 16:03 UTC (permalink / raw)


On Sat, 20 Apr 2002, Josh Huber wrote:
> BTW, thanks for the help ;)

It would have been more helpful if it was right. ;)

> Daniel Pittman <daniel@rimspace.net> writes:
> 
>> (loop for regexp in mft-regexps and recipient in recipients
>>       when (string-match regexp recipient) return recipient)
> 
> I actually tried this at one point, but it didn't work for me, and
> doesn't work in the message code.  Perhaps you could explain this to
> me?

I screwed up in my thinking about the problem space and, as a result,
gave you something that works if and only if (= (length mft-regexps)
(length recipients)).

You want the first entry in recipients that matched any regexp in
mft-regexps, right?

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

[...]

> I must be missing something pretty major ;)

Well, /one/ of us did. ;)
        Daniel

-- 
Every artist knows that he is engaged in an encounter with infinity, and that
work done with heart and hand is ultimately worship of life itself.
        -- Bernard Leach



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

* Re: cl in message.el, etc
  2002-04-20 16:03     ` Daniel Pittman
@ 2002-04-20 17:34       ` Josh Huber
  2002-04-21  2:28         ` Daniel Pittman
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Huber @ 2002-04-20 17:34 UTC (permalink / raw)


Daniel Pittman <daniel@rimspace.net> writes:

> It would have been more helpful if it was right. ;)

:)

> I screwed up in my thinking about the problem space and, as a
> result, gave you something that works if and only if (= (length
> mft-regexps) (length recipients)).

Ah, okay.  It's still good to know -- the cl 'and' loop construct only
works with lists of equal length?

> You want the first entry in recipients that matched any regexp in
> mft-regexps, right?

That's correct.

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

Yep, this is it.

Thanks again,
-- 
Josh Huber



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

* Re: cl in message.el, etc
  2002-04-20 17:34       ` Josh Huber
@ 2002-04-21  2:28         ` Daniel Pittman
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Pittman @ 2002-04-21  2:28 UTC (permalink / raw)


On Sat, 20 Apr 2002, Josh Huber wrote:
> Daniel Pittman <daniel@rimspace.net> writes:

[...]

>> I screwed up in my thinking about the problem space and, as a
>> result, gave you something that works if and only if (= (length
>> mft-regexps) (length recipients)).
> 
> Ah, okay.  It's still good to know -- the cl 'and' loop construct only
> works with lists of equal length?

Saying (loop for foo in bar and qux in quux) means that each iteration
will bind 'foo' to the next element of 'bar' /and/ 'qux' to the next
element of 'quux', in parallel.

Once either list is empty the loop terminates, by default. So, they only
perform as many steps as the shortest list.

>> You want the first entry in recipients that matched any regexp in
>> mft-regexps, right?
> 
> That's correct.

Good. It occurred to me that I might have had that wrong as well. :)

[... correct code dropped ...]

> Yep, this is it.

That should be as good as, or better than, the existing code. It should
also be comprehensible, so I would be happy to see it committed. `loop'
is a macro and shouldn't be a runtime CL issue...

        Daniel

-- 
The sky above the port was the color of television, tuned to a dead channel.
        -- William Gibson, __Neuromancer__



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

* Re: cl in message.el, etc
  2002-04-20  3:43 ` Daniel Pittman
  2002-04-20 15:14   ` Josh Huber
@ 2002-04-22  8:18   ` Kai Großjohann
  1 sibling, 0 replies; 8+ messages in thread
From: Kai Großjohann @ 2002-04-22  8:18 UTC (permalink / raw)
  Cc: ding

Daniel Pittman <daniel@rimspace.net> writes:

> 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 anyone know who else except Richard dislikes CL?  I think that
Emacs Lisp should move in the direction of CL.

kai
-- 
Silence is foo!



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

end of thread, other threads:[~2002-04-22  8:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-19 21:41 cl in message.el, etc Josh Huber
2002-04-19 22:13 ` Josh Huber
2002-04-20  3:43 ` Daniel Pittman
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

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).