Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #60: system has been recalled


comp / comp.lang.lisp / Re: help me with this function

SubjectAuthor
* Re: help me with this functionB. Pym
+- Re: help me with this functionKaz Kylheku
`- Re: help me with this functionPaul Rubin

1
Subject: Re: help me with this function
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 2 Jul 2024 09:44 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: help me with this function
Date: Tue, 2 Jul 2024 09:44:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <v60i57$1jclv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 02 Jul 2024 11:44:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a5ce9095f63423d5c7f6062626603d29";
logging-data="1684159"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eu1mFVJRMaBAM0/I0DkMH"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:bPJREzwvdK2A4g/+2zgZPOnZyTQ=
View all headers

> i'm trying to write a function that takes two arguments - one is
> an ato the other is a list of lists - for each list within the
> list, if the atom matches its first memeber, i want it's second
> member to be added to a master list and finally returned- for
> example:
>
> (setq mylist '((a b)(a c)(a d)))
> (myfunc 'a lst)
>
> and myfunc would return
>
> (b c d)

Kenny Tilton wrote:

> I do not know of a one-step solution, but you could try:
>
> (defun cullCar (match lists)
> (delete-if #'null (mapcar #'(lambda (list)
> (when (eql match (car list))
> (cadr list)))
> lists)))
>
> This would be inefficent where many non-matches occur. Doesn't
> the loop macro have some neat features for this? (Don't use it
> myself.)

Scheme

(define (myfunc x lst)
(filter-map
(lambda(xs) (and (equal? x (car xs)) (cadr xs)))
lst))

(myfunc 'b '((b 2) (c 3) (b 4) (d 5) (b 6)))

===>
(2 4 6)

Subject: Re: help me with this function
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 2 Jul 2024 10:24 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: help me with this function
Date: Tue, 2 Jul 2024 10:24:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20240702025737.299@kylheku.com>
References: <v60i57$1jclv$1@dont-email.me>
Injection-Date: Tue, 02 Jul 2024 12:24:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="61ea95c593e0883a342ca528aa1d84f8";
logging-data="1686456"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EyQzCoC2naNMYa0Xyh95DaQeySngPzOQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:0x1zJtrbDRQCHQNO9D6y68nuWhQ=
View all headers

On 2024-07-02, B. Pym <No_spamming@noWhere_7073.org> wrote:
>> i'm trying to write a function that takes two arguments - one is
>> an ato the other is a list of lists - for each list within the
>> list, if the atom matches its first memeber, i want it's second
>> member to be added to a master list and finally returned- for
>> example:
>>
>> (setq mylist '((a b)(a c)(a d)))
>> (myfunc 'a lst)
>>
>> and myfunc would return
>>
>> (b c d)

1> (match @(coll (a @x)) '((a b) (a c) (a d) (x 0) (a e)) x)
(b c d e)

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

Subject: Re: help me with this function
From: Paul Rubin
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 3 Jul 2024 00:03 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.lisp
Subject: Re: help me with this function
Date: Tue, 02 Jul 2024 17:03:12 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <87ikxnjq9r.fsf@nightsong.com>
References: <v60i57$1jclv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 03 Jul 2024 02:03:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="88cddf8af9c7125058ea83d38371ccbd";
logging-data="1948774"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/f4sRCgliNsWlAHrLfEpFk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:FYN0M7Yd2D3r/Q3fIXVkLLzwWUs=
sha1:PeWKs1hUfLC3AqBOgbC9SBq/aVM=
View all headers

"B. Pym" <No_spamming@noWhere_7073.org> writes:
> (myfunc 'b '((b 2) (c 3) (b 4) (d 5) (b 6)))
> ===>
> (2 4 6)

(myfunc 'b '((b 2) (c 3) (b #f) (d 5) (b 6)))
===>
(2 6)

Should be (2 #f 6).

This works:

(define (m2 x lst)
(map cadr (filter (lambda (ys) (equal? (car ys) x)) lst)))

1

rocksolid light 0.9.8
clearnet tor