The following function add string associations if matches are found within a collection of alists. Currently I am listing the alists andromeda-assoc-tablet-N
one by one. Can one manage to this without actually listing them individually because I have many of them (have got 57 alists)? Perhaps apply mapcar
then pass the actual list to the loop.
Have been scrutinising why I cannot get the following implementation plan that uses mapcar
to work.
(dolist (aggr (list (mapcar #'andromeda-construct-assoc-tablet
(number-sequence 1 57))))
(setq rplc (cdr (assoc word aggr)))
(unless (null rplc)
(add-to-list 'nscrip
(replace-regexp-in-string word rplc word))))
Here is the detailed description
(defvar nscrip '())
(defconst andromeda-assoc-tablet-1
'( ("OrycteropusAfer" . "Aardvark")
("VicugnaPacos" . "Alpaca")
("MyrmecophagaTridactyla" . "Anteater") ))
(defconst andromeda-assoc-tablet-2
'( ("Dasypodidae" . "Armadillo")
("TaxideaTaxus" . "Badger")
("Beaver" . "Beaver") ))
(defconst andromeda-assoc-tablet-3
'( ("LynxRufus" . "Bobcat")
("LepomisMacrochirus" . "Bluegill")
("RangiferTarandus" . "Caribou") ))
(defun andromeda-shorten-word ()
"Shorten word at point according to specific rules."
(interactive)
(let* ( (bounds (bounds-of-thing-at-point 'word))
(word (downcase (buffer-substring (car bounds) (cdr bounds))))
(rplc "") )
(goto-char (car bounds))
(add-to-list 'nscrip word)
(dolist (aggr (list andromeda-assoc-tablet-1
andromeda-assoc-tablet-2
andromeda-assoc-tablet-3))
(setq rplc (cdr (assoc word aggr)))
(unless (null rplc)
(add-to-list 'nscrip
(replace-regexp-in-string word rplc word)))) ))
Thus if word
is LynxRufus
, then nscrip
is Bobcat
.
I have made the following function
(defun andromeda-construct-assoc-tablet (n)
"Return value of symbol `andromeda-assoc-tablet-N', an alist of
paired string elements."
(symbol-value (intern (format "andromeda-assoc-tablet-%d" n))))
My scheme is to use something like
(mapcar #'andromeda-construct-assoc-tablet (number-sequence 1 57)
that I can pass to aggr
in function andromeda-shorten-word
.
nscrip
to look like afterwards.code smell
problem, but necessitates from requirements of supportable code. Do not worry about the psychological smell.