Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You have an ability to sense and know higher truth.


comp / comp.lang.lisp / Re: Returning no value

SubjectAuthor
* Re: Returning no valueB. Pym
+- Re: Returning no valueB. Pym
`- Re: Returning no valueKaz Kylheku

1
Subject: Re: Returning no value
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 18 Jul 2024 22:38 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Returning no value
Date: Thu, 18 Jul 2024 22:38:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <v7c5g8$2kcte$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 19 Jul 2024 00:38:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="839d7167ff7be0250bddd8e0c01d26f2";
logging-data="2765742"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YPlMPyz0Zzl2CmJRfGQBL"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:1rYNwWipu5lVVG1VPpeQENnhWjU=
View all headers

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)

Subject: Re: Returning no value
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 18 Jul 2024 23:00 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Returning no value
Date: Thu, 18 Jul 2024 23:00:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <v7c6ra$2kkqi$1@dont-email.me>
References: <v7c5g8$2kcte$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 19 Jul 2024 01:01:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="839d7167ff7be0250bddd8e0c01d26f2";
logging-data="2773842"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+bFY9uDimp4jtq6wDv0Kl"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:nEvOfUyD587z1uC2XzVpGmtflk0=
View all headers

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)

Subject: Re: Returning no value
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 19 Jul 2024 16:55 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Returning no value
Date: Fri, 19 Jul 2024 16:55:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20240719095207.219@kylheku.com>
References: <v7c5g8$2kcte$1@dont-email.me>
Injection-Date: Fri, 19 Jul 2024 18:55:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="329fa895c5d6908477a80b789f62a073";
logging-data="3237795"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/nVys3aJNnrHlEEUEnH3o9v4Hb7wfhaM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:im0gimA9FRczsQI2NSAMk6z2QD0=
View all headers

On 2024-07-18, B. Pym <Nobody447095@here-nor-there.org> wrote:
> Another way.
>
> (define (foo) (let1 x (random-integer 10) (and (< 5 x) x)))
>
> (filter-map (^_ (foo)) (iota 10))
> ===>
> (7 8 9 6 6 7)

This is the TXR Lisp interactive listener of TXR 295.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
Please listen carefully to the following spec, as our Lisp has changed.
1> [keep-keys-if (op < 5) 0..10 (ret (rand 10))]
(9 9 7)
2> [keep-keys-if (op < 5) 0..10 (ret (rand 10))]
(6 8 8 7)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

1

rocksolid light 0.9.8
clearnet tor