[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cl-dolist, dolist, cl-return,
From: |
John Mastro |
Subject: |
Re: cl-dolist, dolist, cl-return, |
Date: |
Tue, 7 Jul 2015 17:31:35 -0700 |
Emanuel Berg <embe8573@student.uu.se> wrote:
> I just wrote the below code.
>
> `cl-return' works for `cl-dolist', but not for
> `dolist' because it hasn't an "implicit nil block ...
> established around the loop". And there is no
> `return'! I think this "cl-" stuff is confusing.
> Anyone cares to explain?
The `cl' prefix stands for Common Lisp, from whence the functionality
there came (or was inspired by).
> By the way, I know there are one zillion loops
> in Lisp. What is the conventional way to
>
> 1. iterate a list
> 2. until some condition is met for some element
> 3. then break, to speak in C
I don't know if there's one most-conventional way, but here are a couple
options:
;; Use `catch' and `throw'
(catch 'done
(dolist (elt list)
(do-something elt)
(when (some-condition)
(throw 'done t))))
;; Use `while' and a condition variable
(let (done)
(while (and list (not done))
(let ((elt (pop list)))
(do-something elt)
(when (some-condition)
(setq done t)))))
> And: With [cl-]dolist, if the list is an expression
> and not an atom, does that get evaluated once, or does
> it happen every iteration like, say, a string length
> test would, again in C?
Just once. Besides inefficiency, evaluating it every time would lead to
wrong results.
> Also: why isn't there a "neq"?
I don't know the real answer, but it may be because then people would
expect `n=', `neql', `nequal', `nequalp', `nstring=', and so on. Or
perhaps some would have a "not variant" and others wouldn't, in which
case we'd need to remember which did and didn't. IMHO it's simpler and
cleaner to have a single `not' which can be used with any predicate as
needed.
--
john
- cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/07
- Re: cl-dolist, dolist, cl-return,,
John Mastro <=
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/07
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, John Mastro, 2015/07/08
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/09
- Message not available
- Re: cl-dolist, dolist, cl-return,, Barry Margolin, 2015/07/10
- Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/11
- Re: cl-dolist, dolist, cl-return,, Stefan Monnier, 2015/07/10
Re: cl-dolist, dolist, cl-return,, Emanuel Berg, 2015/07/08
- Prev by Date:
cl-dolist, dolist, cl-return,
- Next by Date:
Re: cl-dolist, dolist, cl-return,
- Previous by thread:
cl-dolist, dolist, cl-return,
- Next by thread:
Re: cl-dolist, dolist, cl-return,
- Index(es):