help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Break from a dolist


From: Le Wang
Subject: Re: Break from a dolist
Date: Sun, 9 Sep 2012 21:52:50 +0800

On Sun, Sep 9, 2012 at 8:49 PM, Cecil Westerhof <Cecil@decebal.nl> wrote:
>
> Thanks. That makes for better code. I now have the following code,
> that I am going to call from dcbl-gnus-get-mailing-list-address. Much
> more clear code and I have now a generic function that I can call from
> other places also.
>
>     (defun dcbl-get-tuple-value (tuple index)
>       "Get value from tuple indexed by index (if it exist);"
>         (when index
>           (catch 'loop
>             (dolist (item tuple)
>               (when (string-match (car item) index)
>                   (throw 'loop (cdr item)))))))


`dolist' (like all cl looping mechanisms) runs within an implicit anonymous
local return.  So you can simply use

    (defun dcbl-get-tuple-value (tuple index)
      "Get value from tuple indexed by index (if it exist);"
        (when index
          (dolist (item tuple)
            (when (string-match (car item) index)
              (return (cdr item))))))


--
Le



reply via email to

[Prev in Thread] Current Thread [Next in Thread]