Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

The whole world is a tuxedo and you are a pair of brown shoes. -- George Gobel


comp / comp.lang.scheme / re: Elegant solution asked

SubjectAuthor
o re: Elegant solution askedB. Pym

1
Subject: re: Elegant solution asked
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 7 Sep 2024 08:19 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,comp.lang.scheme
Subject: re: Elegant solution asked
Date: Sat, 7 Sep 2024 08:19:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <vbh2an$19l65$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 07 Sep 2024 10:19:40 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="4447948589173226b402cfc683751de7";
logging-data="1365189"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/896eTEKlS2nRi84EeSD6z"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:Z9GOFZS4GmLiTiWtAYNKppYQIjA=
View all headers

> > Very often I need a function to map a 2 argument function over a list and
> > a fixed argument. For example, if we call such function map1:
> > (map1 #'list 'z '(a b c)) should return: '((z a) (z b) (z c))
> >
> > Can anyone suggest an elegant solution for this. The best I could come up
> > with was:
> >
> > (defun map1 (function fixed-argument list)
> > (mapcar (lambda (element) (funcall fn fixed-argument element)) list))
> >
> > This works fine, but I have the gut feeling that there must be a
> > better/simpler way. Any ideas?
> > Thanks in advance.
> > Please reply to: lsarasua@epo.e-mail.com
>
> I prefer the following (I guess because it avoids the funcall), although
> I don't claim it is is significantly better.
>
> (defun map1 (function fixed_argument list) (mapcar function
> (mapcar #'(lambda (x) fixed-argument) list) list))

Scheme

(map (curry list '--) '(a b c))
===>
((-- a) (-- b) (-- c))

(map (curryr list '--) '(a b c))
===>
((a --) (b --) (c --))

1

rocksolid light 0.9.8
clearnet tor