Deutsch   English   Français   Italiano  
<vas2fe$ebqd$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Returning no value
Date: Fri, 30 Aug 2024 09:13:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <vas2fe$ebqd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 30 Aug 2024 11:13:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="abfbf0e8d1f6a5c18d0eb734601f646f";
	logging-data="470861"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19BPvoIVHNa+NBqCQe1uda2"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:GVGR43bE/dX+Lp2rY0iQZ8Z8yUo=
Bytes: 1610

Ken Tilton wrote:

> Steven M. Haflich wrote:
> > I think the OP may be looking for something like this:
> >
> > cl-user(10): (defun foo()
> >           (let ((x (random 10)))
> >         (and (< 5 x) x)))
> > foo
> > cl-user(11): (loop repeat 10
> >         as x = (foo)
> >         when x collect x)   ; <<<<<
> > (6 8 9)
> 
> Sweet. But not wnat someone already offered?:
> 
>    (loop repeat 10
>          when (foo)
>          collect it)

Gauche Scheme

(define (foo) (let1 x (random-integer 10) (and (< 5 x) x)))

(define (tcollect func tries)
  (if (zero? tries)
    '()
    (append (cond ((func) => list) (#t '()))
            (tcollect func (- tries 1)))))

(tcollect foo 10)

(9 8 9 6 7 9)

(tcollect + 3)

(0 0 0)