Re: Returning no value

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Returning no value
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 19. Jul 2024, 00:00:59
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v7c6ra$2kkqi$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:

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
 
(use srfi-27) ;; random-integer
 
(define (foo . _) (let1 x (random-integer 10) (and (< 5 x) x)))
 
(filter-map foo (iota 10))
  ===>
(9 6 7 8 9)
 
Another way.
 
(define (foo) (let1 x (random-integer 10) (and (< 5 x) x)))
 
(filter-map (^_ (foo)) (iota 10))
  ===>
(7 8 9 6 6 7)


Another way:

(use gauche.generator)

(filter + (generator->list foo 10))
  ===>
(7 8 9 8)



Date Sujet#  Auteur
18 Jul 24 * Re: Returning no value3B. Pym
19 Jul 24 +- Re: Returning no value1B. Pym
19 Jul 24 `- Re: Returning no value1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal