help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looping lists through mapcar


From: Jean Louis
Subject: Re: Looping lists through mapcar
Date: Wed, 24 Aug 2022 13:52:45 +0300
User-agent: Mutt/+ () (2022-06-11)

* uzibalqa <uzibalqa@proton.me> [2022-08-24 12:04]:
> ------- Original Message -------
> On Wednesday, August 24th, 2022 at 6:24 AM, Jean Louis <bugs@gnu.support> 
> wrote:
> 
> > I cannot understand.  Provide exactly what you mean.
> 
> Here is what I mean.  When I have many alists (`andromeda-assoc-table-N' 
> where `N' is a numeric value
> with say `N' being from 1 to 57), I want to avoid having to write them all 
> down inside the function 
> `andromeda-translate'.

I got it now.

(defvar nscrip '())

(defconst andromeda-assoc-table-1
  '( ("OrycteropusAfer" . "Aardvark")  
     ("VicugnaPacos" . "Alpaca") 
     ("MyrmecophagaTridactyla" . "Anteater") ))

(defconst andromeda-assoc-table-2
  '( ("Dasypodidae" . "Armadillo")  
     ("TaxideaTaxus" . "Badger")
     ("Beaver" . "Beaver") ))

(defconst andromeda-assoc-table-3
  '( ("LynxRufus" . "Bobcat")
     ("LepomisMacrochirus" . "Bluegill")
     ("RangiferTarandus" . "Caribou") ))

(defun my-assoc-lists ()
  (let* ((name "andromeda-assoc-table-")
         (list '())
         (counter 1))
    (while (boundp (intern (concat name (number-to-string counter))))
      (setq list (append list (symbol-value (intern (concat name 
(number-to-string counter))))))
      (setq counter (1+ counter)))
    list))

;; Testing

(my-assoc-lists) ⇒ (("OrycteropusAfer" . "Aardvark") ("VicugnaPacos" . 
"Alpaca") ("MyrmecophagaTridactyla" . "Anteater") ("Dasypodidae" . "Armadillo") 
("TaxideaTaxus" . "Badger") ("Beaver" . "Beaver") ("LynxRufus" . "Bobcat") 
("LepomisMacrochirus" . "Bluegill") ("RangiferTarandus" . "Caribou"))

(defun andromeda-translate ()
  "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 (my-assoc-lists))
      (setq rplc (cdr (assoc word aggr)))
      (unless (null rplc)
         (add-to-list 'nscrip
             (replace-regexp-in-string word rplc word)))) ))

;; I did not test your function.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]