* Making a list of lists
@ 2023-07-03 16:18 uzibalqa
2023-07-03 16:24 ` Sebastian Miele
0 siblings, 1 reply; 10+ messages in thread
From: uzibalqa @ 2023-07-03 16:18 UTC (permalink / raw)
To: uzibalqa via Users list for the GNU Emacs text editor
I want to make a list of lists. Suppose I make a list by calling this function
(defun linseq (&rest sequence)
sequence)
How can then I have a function that adds the list as an element to a list of lists ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:18 Making a list of lists uzibalqa
@ 2023-07-03 16:24 ` Sebastian Miele
2023-07-03 16:33 ` Sebastian Miele
2023-07-03 16:41 ` uzibalqa
0 siblings, 2 replies; 10+ messages in thread
From: Sebastian Miele @ 2023-07-03 16:24 UTC (permalink / raw)
To: uzibalqa; +Cc: help-gnu-emacs
> From: uzibalqa <uzibalqa@proton.me>
> Date: Mon, 2023-07-03 16:18 +0000
>
> I want to make a list of lists. Suppose I make a list by calling this function
>
> (defun linseq (&rest sequence)
> sequence)
>
> How can then I have a function that adds the list as an element to a list of lists ?
The Emacs Lisp manual contains such information.
`linseq' basically is the built-in `list' function. You could do
(linseq (linseq 'a 'b 'c))
which is equivalent to:
(list (list 'a 'b 'c))
Another possibility is the "backquote construct" (also see the manual).
For example
`(,(list 'a 'b 'c))
has the same result.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:24 ` Sebastian Miele
@ 2023-07-03 16:33 ` Sebastian Miele
2023-07-03 16:40 ` Sebastian Miele
2023-07-03 16:41 ` uzibalqa
1 sibling, 1 reply; 10+ messages in thread
From: Sebastian Miele @ 2023-07-03 16:33 UTC (permalink / raw)
To: Sebastian Miele; +Cc: uzibalqa, help-gnu-emacs
> From: Sebastian Miele <iota@whxvd.name>
> Date: Mon, 2023-07-03 18:24 +0200
>
>> From: uzibalqa <uzibalqa@proton.me>
>> Date: Mon, 2023-07-03 16:18 +0000
>>
>> I want to make a list of lists. Suppose I make a list by calling this function
>>
>> (defun linseq (&rest sequence)
>> sequence)
>>
>> How can then I have a function that adds the list as an element to a list of lists ?
>
> The Emacs Lisp manual contains such information.
I have to admit: I do not know in how far the Emacs Lisp manual works as
a tutorial/introduction to (Emacs) Lisp for people who do not already
know a Lisp. But your question suggests that you need an sufficiently
gentle introduction to (Emacs) Lisp in general.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:33 ` Sebastian Miele
@ 2023-07-03 16:40 ` Sebastian Miele
0 siblings, 0 replies; 10+ messages in thread
From: Sebastian Miele @ 2023-07-03 16:40 UTC (permalink / raw)
To: Sebastian Miele; +Cc: uzibalqa, help-gnu-emacs
> From: Sebastian Miele <iota@whxvd.name>
> Date: Mon, 2023-07-03 18:33 +0200
>
>> From: Sebastian Miele <iota@whxvd.name>
>> Date: Mon, 2023-07-03 18:24 +0200
>>
>>> From: uzibalqa <uzibalqa@proton.me>
>>> Date: Mon, 2023-07-03 16:18 +0000
>>>
>>> I want to make a list of lists. Suppose I make a list by calling this function
>>>
>>> (defun linseq (&rest sequence)
>>> sequence)
>>>
>>> How can then I have a function that adds the list as an element to a list of lists ?
>>
>> The Emacs Lisp manual contains such information.
>
> I have to admit: I do not know in how far the Emacs Lisp manual works as
> a tutorial/introduction to (Emacs) Lisp for people who do not already
> know a Lisp. But your question suggests that you need an sufficiently
> gentle introduction to (Emacs) Lisp in general.
(Sorry for the multiple postings.)
I quick look at the beginning of the Emacs Lisp manual reveals:
This manual attempts to be a full description of Emacs Lisp. For a
beginner’s introduction to Emacs Lisp, see ‘An Introduction to Emacs
Lisp Programming’, by Bob Chassell, also published by the Free
Software Foundation.
And that introductory text is distributed with Emacs.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:24 ` Sebastian Miele
2023-07-03 16:33 ` Sebastian Miele
@ 2023-07-03 16:41 ` uzibalqa
2023-07-03 16:44 ` Sebastian Miele
1 sibling, 1 reply; 10+ messages in thread
From: uzibalqa @ 2023-07-03 16:41 UTC (permalink / raw)
To: Sebastian Miele; +Cc: help-gnu-emacs
------- Original Message -------
On Tuesday, July 4th, 2023 at 4:24 AM, Sebastian Miele <iota@whxvd.name> wrote:
> > From: uzibalqa uzibalqa@proton.me
> > Date: Mon, 2023-07-03 16:18 +0000
> >
> > I want to make a list of lists. Suppose I make a list by calling this function
> >
> > (defun linseq (&rest sequence)
> > sequence)
> >
> > How can then I have a function that adds the list as an element to a list of lists ?
>
>
> The Emacs Lisp manual contains such information.
>
> `linseq' basically is the built-in` list' function. You could do
>
> (linseq (linseq 'a 'b 'c))
>
> which is equivalent to:
>
> (list (list 'a 'b 'c))
>
> Another possibility is the "backquote construct" (also see the manual).
> For example
>
> `(,(list 'a 'b 'c))
>
> has the same result.
I do not follow your explanation very well.
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 ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:41 ` uzibalqa
@ 2023-07-03 16:44 ` Sebastian Miele
2023-07-03 17:51 ` uzibalqa
0 siblings, 1 reply; 10+ messages in thread
From: Sebastian Miele @ 2023-07-03 16:44 UTC (permalink / raw)
To: uzibalqa; +Cc: help-gnu-emacs
> From: uzibalqa <uzibalqa@proton.me>
> Date: Mon, 2023-07-03 16:41 +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))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 16:44 ` Sebastian Miele
@ 2023-07-03 17:51 ` uzibalqa
2023-07-03 17:56 ` Sebastian Miele
0 siblings, 1 reply; 10+ messages in thread
From: uzibalqa @ 2023-07-03 17:51 UTC (permalink / raw)
To: Sebastian Miele; +Cc: help-gnu-emacs
------- Original Message -------
On Tuesday, July 4th, 2023 at 4:44 AM, Sebastian Miele <iota@whxvd.name> wrote:
> > From: uzibalqa uzibalqa@proton.me
> > Date: Mon, 2023-07-03 16:41 +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)
I would like to write a function that pushes a whole list to a list, to make
a list of lists, called a chart.
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))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 17:51 ` uzibalqa
@ 2023-07-03 17:56 ` Sebastian Miele
2023-07-03 19:08 ` uzibalqa
2023-07-03 19:28 ` uzibalqa
0 siblings, 2 replies; 10+ messages in thread
From: Sebastian Miele @ 2023-07-03 17:56 UTC (permalink / raw)
To: uzibalqa; +Cc: help-gnu-emacs
> 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 17:56 ` Sebastian Miele
@ 2023-07-03 19:08 ` uzibalqa
2023-07-03 19:28 ` uzibalqa
1 sibling, 0 replies; 10+ messages in thread
From: uzibalqa @ 2023-07-03 19:08 UTC (permalink / raw)
To: Sebastian Miele; +Cc: help-gnu-emacs
------- Original Message -------
On Tuesday, July 4th, 2023 at 5:56 AM, Sebastian Miele <iota@whxvd.name> wrote:
> > 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
I define a chart to be a list of lists, with each sublist being a row of a chart.
Thus
chart is (("row1" "r11" "r12") ("row2" "" "r21" "r22"))
> (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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Making a list of lists
2023-07-03 17:56 ` Sebastian Miele
2023-07-03 19:08 ` uzibalqa
@ 2023-07-03 19:28 ` uzibalqa
1 sibling, 0 replies; 10+ messages in thread
From: uzibalqa @ 2023-07-03 19:28 UTC (permalink / raw)
To: Sebastian Miele; +Cc: help-gnu-emacs
------- Original Message -------
On Tuesday, July 4th, 2023 at 5:56 AM, Sebastian Miele <iota@whxvd.name> wrote:
> > 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))
I want a list of two lists ((a b c) (d e f)) () instead of one list (a b c d e f).
> > 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-07-03 19:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-03 16:18 Making a list of lists uzibalqa
2023-07-03 16:24 ` Sebastian Miele
2023-07-03 16:33 ` Sebastian Miele
2023-07-03 16:40 ` Sebastian Miele
2023-07-03 16:41 ` uzibalqa
2023-07-03 16:44 ` Sebastian Miele
2023-07-03 17:51 ` uzibalqa
2023-07-03 17:56 ` Sebastian Miele
2023-07-03 19:08 ` uzibalqa
2023-07-03 19:28 ` uzibalqa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).