all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Looping lists through mapcar
@ 2022-08-23 12:16 uzibalqa
  2022-08-23 19:13 ` Jean Louis
  0 siblings, 1 reply; 19+ messages in thread
From: uzibalqa @ 2022-08-23 12:16 UTC (permalink / raw)
  To: uzibalqa via Users list for the GNU Emacs text editor


I would like to pass a number of alists in the form assoc-table-N so that I can store data
in another list named `nscrip'.   Would like to manage the lists without having to list them
individually.  My idea has been to use mapcar, but the scheme has not worked out, and the lists
are net being passed through the loop.


(dolist (aggr (list (mapcar #'construct-assoc-table
                            (number-sequence 1 8))))
  (setq rplc (cdr (assoc word aggr)))
  (unless (null rplc)
     (add-to-list 'nscrip
         (replace-regexp-in-string word rplc word))))


(defun construct-assoc-table (n)
  "Return value of symbol `assoc-table-N', an alist of
paired string elements."

  (symbol-value (intern (format "assoc-table-%d" n))))



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-23 12:16 Looping lists through mapcar uzibalqa
@ 2022-08-23 19:13 ` Jean Louis
  2022-08-24  5:34   ` uzibalqa
  0 siblings, 1 reply; 19+ messages in thread
From: Jean Louis @ 2022-08-23 19:13 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

* uzibalqa <uzibalqa@proton.me> [2022-08-23 15:18]:
> 
> I would like to pass a number of alists in the form assoc-table-N so that I can store data
> in another list named `nscrip'.   Would like to manage the lists without having to list them
> individually.  My idea has been to use mapcar, but the scheme has not worked out, and the lists
> are net being passed through the loop.

I find it difficult to understand your above description. I got
the idea that you wish to name alists such as assoc-table-1,
assoc-table-2 and that you put those symbols in a new list.

;; (dolist (aggr (list (mapcar #'construct-assoc-table
;;                             (number-sequence 1 8))))
;;   (setq rplc (cdr (assoc word aggr)))
;;   (unless (null rplc)
;;     (add-to-list 'nscrip
;; 		 (replace-regexp-in-string word rplc word))))

I cannot understand the above.

Do this: {C-h f add-to-list RET} and find quote there:

"This is handy to add some elements to configuration variables,
but please do not abuse it in Elisp code, where you are usually
better off using ‘push’ or ‘cl-pushnew’."


-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-23 19:13 ` Jean Louis
@ 2022-08-24  5:34   ` uzibalqa
  2022-08-24  6:24     ` Jean Louis
  0 siblings, 1 reply; 19+ messages in thread
From: uzibalqa @ 2022-08-24  5:34 UTC (permalink / raw)
  To: Jean Louis; +Cc: uzibalqa via Users list for the GNU Emacs text editor

------- Original Message -------
On Tuesday, August 23rd, 2022 at 7:13 PM, Jean Louis <bugs@gnu.support> wrote:


> * uzibalqa uzibalqa@proton.me [2022-08-23 15:18]:
> 
> > I would like to pass a number of alists in the form assoc-table-N so that I can store data
> > in another list named `nscrip'. Would like to manage the lists without having to list them
> > individually. My idea has been to use mapcar, but the scheme has not worked out, and the lists
> > are net being passed through the loop.
> 
> 
> I find it difficult to understand your above description. I got
> the idea that you wish to name alists such as assoc-table-1,
> assoc-table-2 and that you put those symbols in a new list.
> 
> ;; (dolist (aggr (list (mapcar #'construct-assoc-table
> ;; (number-sequence 1 8))))
> ;; (setq rplc (cdr (assoc word aggr)))
> ;; (unless (null rplc)
> ;; (add-to-list 'nscrip
> ;; (replace-regexp-in-string word rplc word))))
> 

I give you  an implementation that works, assoc-table-N each being an alist

(dolist (aggr (list assoc-table-1 assoc-table-2 assoc-table-3

But with many lists, this becomes cumbersome to list them all when.  Had a go
at using mapcar on a string that matches the names of the alists.
    









^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24  5:34   ` uzibalqa
@ 2022-08-24  6:24     ` Jean Louis
  2022-08-24  9:03       ` uzibalqa
  0 siblings, 1 reply; 19+ messages in thread
From: Jean Louis @ 2022-08-24  6:24 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

I cannot understand.

> I give you  an implementation that works, assoc-table-N each being
> an alist

Provide fully working implementation. Nothing you sent worked on my
side.

> But with many lists, this becomes cumbersome to list them all when.

What is "this" that become cumbersome?

> Had a go at using mapcar on a string that matches the names of the
> alists.

Provide exactly what you mean.

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24  6:24     ` Jean Louis
@ 2022-08-24  9:03       ` uzibalqa
  2022-08-24  9:54         ` Emanuel Berg
  2022-08-24 10:52         ` Jean Louis
  0 siblings, 2 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-24  9:03 UTC (permalink / raw)
  To: Jean Louis; +Cc: uzibalqa via Users list for the GNU Emacs text editor

------- 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'.

(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 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 (list andromeda-assoc-table-1
                        andromeda-assoc-table-2
                        andromeda-assoc-table-3))
      (setq rplc (cdr (assoc word aggr)))
      (unless (null rplc)
         (add-to-list 'nscrip
             (replace-regexp-in-string word rplc word)))) ))




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24  9:03       ` uzibalqa
@ 2022-08-24  9:54         ` Emanuel Berg
  2022-08-24 10:52         ` Jean Louis
  1 sibling, 0 replies; 19+ messages in thread
From: Emanuel Berg @ 2022-08-24  9:54 UTC (permalink / raw)
  To: help-gnu-emacs

uzibalqa 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'.
>
> (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 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 (list andromeda-assoc-table-1
>                         andromeda-assoc-table-2
>                         andromeda-assoc-table-3))
>       (setq rplc (cdr (assoc word aggr)))
>       (unless (null rplc)
>          (add-to-list 'nscrip
>              (replace-regexp-in-string word rplc word)))) ))

Unheard of :)

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24  9:03       ` uzibalqa
  2022-08-24  9:54         ` Emanuel Berg
@ 2022-08-24 10:52         ` Jean Louis
  2022-08-24 11:02           ` uzibalqa
                             ` (2 more replies)
  1 sibling, 3 replies; 19+ messages in thread
From: Jean Louis @ 2022-08-24 10:52 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

* 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/



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 10:52         ` Jean Louis
@ 2022-08-24 11:02           ` uzibalqa
  2022-08-24 11:49             ` uzibalqa
  2022-08-24 12:08             ` Jean Louis
  2022-08-24 11:44           ` Emanuel Berg
  2022-08-24 23:56           ` uzibalqa
  2 siblings, 2 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-24 11:02 UTC (permalink / raw)
  To: Jean Louis; +Cc: uzibalqa via Users list for the GNU Emacs text editor


------- Original Message -------
On Wednesday, August 24th, 2022 at 10:52 AM, Jean Louis <bugs@gnu.support> wrote:


> * 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

I hope your new function does not actually make an additional list, because I want to save
memory.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 10:52         ` Jean Louis
  2022-08-24 11:02           ` uzibalqa
@ 2022-08-24 11:44           ` Emanuel Berg
  2022-08-24 12:09             ` Jean Louis
                               ` (2 more replies)
  2022-08-24 23:56           ` uzibalqa
  2 siblings, 3 replies; 19+ messages in thread
From: Emanuel Berg @ 2022-08-24 11:44 UTC (permalink / raw)
  To: help-gnu-emacs

> (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))

         DANGER!
Don't read the above code.
Your own programming could
deteriorate as a result.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:02           ` uzibalqa
@ 2022-08-24 11:49             ` uzibalqa
  2022-08-24 16:17               ` Jean Louis
  2022-08-24 12:08             ` Jean Louis
  1 sibling, 1 reply; 19+ messages in thread
From: uzibalqa @ 2022-08-24 11:49 UTC (permalink / raw)
  To: Jean Louis; +Cc: uzibalqa via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, August 24th, 2022 at 11:02 AM, uzibalqa <uzibalqa@proton.me> wrote:


> ------- Original Message -------
> On Wednesday, August 24th, 2022 at 10:52 AM, Jean Louis bugs@gnu.support wrote:
> 
> 
> 
> > * 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
> 
> 
> I hope your new function does not actually make an additional list, because I want to save
> memory.

Testing your function I am getting

Lisp error: (wrong-type-argument listp ("OrycteropusAfer" . "Aardvark")





^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:02           ` uzibalqa
  2022-08-24 11:49             ` uzibalqa
@ 2022-08-24 12:08             ` Jean Louis
  1 sibling, 0 replies; 19+ messages in thread
From: Jean Louis @ 2022-08-24 12:08 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

* uzibalqa <uzibalqa@proton.me> [2022-08-24 14:03]:
> I hope your new function does not actually make an additional list,
> because I want to save memory.

You are right, be careful. 👀

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:44           ` Emanuel Berg
@ 2022-08-24 12:09             ` Jean Louis
  2022-08-25 10:49               ` uzibalqa
  2022-08-24 12:24             ` uzibalqa
  2022-08-25  0:31             ` uzibalqa
  2 siblings, 1 reply; 19+ messages in thread
From: Jean Louis @ 2022-08-24 12:09 UTC (permalink / raw)
  To: help-gnu-emacs

* Emanuel Berg <incal@dataswamp.org> [2022-08-24 15:05]:
> > (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))
> 
>          DANGER!
> Don't read the above code.
> Your own programming could
> deteriorate as a result.

But it works, doesn't it?

How can you make it easier?

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:44           ` Emanuel Berg
  2022-08-24 12:09             ` Jean Louis
@ 2022-08-24 12:24             ` uzibalqa
  2022-08-25  0:31             ` uzibalqa
  2 siblings, 0 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-24 12:24 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


------- Original Message -------
On Wednesday, August 24th, 2022 at 11:44 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> > (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))
> 
> 
> DANGER!
> Don't read the above code.
> Your own programming could
> deteriorate as a result.
 
The Satanic Verses !



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:49             ` uzibalqa
@ 2022-08-24 16:17               ` Jean Louis
  0 siblings, 0 replies; 19+ messages in thread
From: Jean Louis @ 2022-08-24 16:17 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

To test my function, you first evaluate these:

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

;; So I evaluate it, and it is there:
;; andromeda-assoc-table-1 ⇒ (("OrycteropusAfer" . "Aardvark") ("VicugnaPacos" . "Alpaca") ("MyrmecophagaTridactyla" . "Anteater"))

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

;; andromeda-assoc-table-2 ⇒ (("Dasypodidae" . "Armadillo") ("TaxideaTaxus" . "Badger") ("Beaver" . "Beaver"))

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

;; 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))

Then you evaluate this function:

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

That way you can add any number instead of XX
 `andromeda-assoc-table-XX' and function will add them all
 together. You need not update your other function with new
 symbols such as `andromeda-assoc-table-23' or number of them.

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 10:52         ` Jean Louis
  2022-08-24 11:02           ` uzibalqa
  2022-08-24 11:44           ` Emanuel Berg
@ 2022-08-24 23:56           ` uzibalqa
  2 siblings, 0 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-24 23:56 UTC (permalink / raw)
  To: Jean Louis; +Cc: uzibalqa via Users list for the GNU Emacs text editor


------- Original Message -------
On Wednesday, August 24th, 2022 at 10:52 AM, Jean Louis <bugs@gnu.support> wrote:


> * 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, seems that your version of andromeda-translate is expecting a list of alists.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 11:44           ` Emanuel Berg
  2022-08-24 12:09             ` Jean Louis
  2022-08-24 12:24             ` uzibalqa
@ 2022-08-25  0:31             ` uzibalqa
  2 siblings, 0 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-25  0:31 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 11:44 AM, Emanuel Berg <incal@dataswamp.org> wrote:


> > (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))
> 
> 
> DANGER!
> Don't read the above code.
> Your own programming could
> deteriorate as a result.

A better way is to critique it, and we will look at that very closely.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-24 12:09             ` Jean Louis
@ 2022-08-25 10:49               ` uzibalqa
  2022-08-25 15:57                 ` Jean Louis
  0 siblings, 1 reply; 19+ messages in thread
From: uzibalqa @ 2022-08-25 10:49 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs

------- Original Message -------
On Wednesday, August 24th, 2022 at 12:09 PM, Jean Louis <bugs@gnu.support> wrote:


> * Emanuel Berg incal@dataswamp.org [2022-08-24 15:05]:
> 
> > > (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))
> > 
> > DANGER!
> > Don't read the above code.
> > Your own programming could
> > deteriorate as a result.
> 
> 
> But it works, doesn't it?
> 
> How can you make it easier?
> 
> --
> Jean

Disregard the comments by Berg.  He is just being condescending as happens quite too often in
society.

I wanted to ask you whether one should use an "alist" or a "list of alists".  Because 
"my-assoc-lists" makes "an alist", but  (dolist (aggr (my-assoc-lists))  accepts "a list
of alists".




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-25 10:49               ` uzibalqa
@ 2022-08-25 15:57                 ` Jean Louis
  2022-08-26  2:48                   ` uzibalqa
  0 siblings, 1 reply; 19+ messages in thread
From: Jean Louis @ 2022-08-25 15:57 UTC (permalink / raw)
  To: uzibalqa; +Cc: help-gnu-emacs

* uzibalqa <uzibalqa@proton.me> [2022-08-25 13:49]:
> I wanted to ask you whether one should use an "alist" or a "list of alists".  Because 
> "my-assoc-lists" makes "an alist", but  (dolist (aggr (my-assoc-lists))  accepts "a list
> of alists".

I have already demonstrated how my function works.

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Looping lists through mapcar
  2022-08-25 15:57                 ` Jean Louis
@ 2022-08-26  2:48                   ` uzibalqa
  0 siblings, 0 replies; 19+ messages in thread
From: uzibalqa @ 2022-08-26  2:48 UTC (permalink / raw)
  To: Jean Louis; +Cc: help-gnu-emacs


------- Original Message -------
On Thursday, August 25th, 2022 at 3:57 PM, Jean Louis <bugs@gnu.support> wrote:


> * uzibalqa uzibalqa@proton.me [2022-08-25 13:49]:
> 
> > I wanted to ask you whether one should use an "alist" or a "list of alists". Because
> > "my-assoc-lists" makes "an alist", but (dolist (aggr (my-assoc-lists)) accepts "a list
> > of alists".
> 
> 
> I have already demonstrated how my function works.

(dolist (aggr (my-assoc-lists))

fails upon taking the first element because it is not a list.



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-08-26  2:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-23 12:16 Looping lists through mapcar uzibalqa
2022-08-23 19:13 ` Jean Louis
2022-08-24  5:34   ` uzibalqa
2022-08-24  6:24     ` Jean Louis
2022-08-24  9:03       ` uzibalqa
2022-08-24  9:54         ` Emanuel Berg
2022-08-24 10:52         ` Jean Louis
2022-08-24 11:02           ` uzibalqa
2022-08-24 11:49             ` uzibalqa
2022-08-24 16:17               ` Jean Louis
2022-08-24 12:08             ` Jean Louis
2022-08-24 11:44           ` Emanuel Berg
2022-08-24 12:09             ` Jean Louis
2022-08-25 10:49               ` uzibalqa
2022-08-25 15:57                 ` Jean Louis
2022-08-26  2:48                   ` uzibalqa
2022-08-24 12:24             ` uzibalqa
2022-08-25  0:31             ` uzibalqa
2022-08-24 23:56           ` uzibalqa

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.