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

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

Re: Making a list of lists


From: Sebastian Miele
Subject: Re: Making a list of lists
Date: Mon, 03 Jul 2023 19:56:40 +0200

> From: uzibalqa <uzibalqa@proton.me>
> Date: Mon, 2023-07-03 17:51 +0000
>
>> > Suppose I have mylist, with a number of lists constructed as follows
>> > 
>> > (setq mylist '())
>> > (setq entry1 (linseq "A" "B" "C"))
>> > (setq entry2 (linseq "D" "E" "F"))
>> > 
>> > Then how do I add entry1 and entry2, to mylist ?
>> 
>> Examples:
>> 
>> (setq mylist (cons entry1 (cons entry2 mylist)))
>> (push entry2 mylist) (push entry1 mylist)
>> (add-to-list 'mylist entry2) (add-to-list 'mylist entry1)
>> (setq mylist `(,entry1 ,entry2 ,@mylist))
>
> Can push be used with multiple entries ? 
>
> (push entry1 entry2 mylist)

No.  (Both the Emacs Lisp manual, and C-h f push RET, mention that.)

> I would like to write a function that pushes a whole list to a list, to make
> a list of lists, called a chart.

I do not know what a chart is.  Maybe

  (setq mylist nil
        l1     '(a b c)
        l2     '(d e f))
  (setq mylist `(,@l1 ,@l2 ,@l))

is what you want.  Read about the "backquote construct" in the Emacs
Lisp manual.  Another function to explore in this context is ‘append’:

  (setq mylist (append l1 l2 mylist))

> Here is my function, but need some form of loop, to traverse all the
> function arguments.
>
> (defun linseq (&rest sequence)
>   sequence)
>
> (defun attach (chart &rest linsq)
>   (apply #'push linsq chart))

Again, I do not exactly understand what you want to acheive.

‘apply’ would not work in that example, because of its special handling
of its last parameter.  ‘funcall’ would.  But neither is necessary here.

In principle, e.g., ‘mapc’ yields a way to loop over elements of a list
(for side-effects only).  But looping probably is not necessary, too.

It is my strong impression, that you should take the time and work
through a general introduction to (Emacs) Lisp first.  A lack of that
background just is too limiting.



reply via email to

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