Sie eine LAMBDA
um die Funktion wickeln kann:
(mapcar (lambda (string) (substitute #\d #\o string)) '("test" "wow" "waow"))
;=> ("test" "wdw" "wadw")
Oder Sie können eine Hilfsfunktion verwenden CURRY
genannt (die nicht Teil des Gemeinsamen ist Lisp-Standard, ist aber verfügbar z. B. in Alexandria).
(ql:quickload :alexandria)
(use-package :alexandria)
(mapcar (curry #'substitute #\d #\o) '("test" "wow" "waow"))
;=> ("test" "wdw" "wadw")
Für mehrere Strings in Unterlisten können Sie verschachtelte mapcar/lambda verwenden:
(mapcar (lambda (sentence)
(mapcar (lambda (string)
(substitute #\d #\o string))
sentence))
'(("I" "like" "my" "dog.") ("My" "dog" "likes" "me" "too.")))
;=> (("I" "like" "my" "ddg.") ("My" "ddg" "likes" "me" "tdd."))
Die innere LAMBDA
zu einem CURRY
auch geändert werden könnte:
(mapcar (lambda (sentence)
(mapcar (curry #'substitute #\d #\o) sentence))
'(("I" "like" "my" "dog.") ("My" "dog" "likes" "me" "too.")))
Oder auch:
(mapcar (curry #'mapcar (curry #'substitute #\d #\o))
'(("I" "like" "my" "dog.") ("My" "dog" "likes" "me" "too.")))
nicht mapcar hier Verwenden Sie scheint eine Schleife besser geeignet. – coredump