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))
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 55:55:41 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,712 |