unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: uzibalqa <uzibalqa@proton.me>
To: Sebastian Miele <iota@whxvd.name>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Making a list of lists
Date: Mon, 03 Jul 2023 19:08:02 +0000	[thread overview]
Message-ID: <KjlAQX7RTERbF_p0g9ZLVGMKm3gqdGZe8-A3DbqXCFm4TatDuc0Jravd3nb7At2GOG-sok4kJtoh4D5nCQOIEfoVfjPuPmDjgbpc-7WSAd8=@proton.me> (raw)
In-Reply-To: <87jzvgc0r1.fsf@whxvd.name>

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



  reply	other threads:[~2023-07-03 19:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2023-07-03 19:28           ` uzibalqa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='KjlAQX7RTERbF_p0g9ZLVGMKm3gqdGZe8-A3DbqXCFm4TatDuc0Jravd3nb7At2GOG-sok4kJtoh4D5nCQOIEfoVfjPuPmDjgbpc-7WSAd8=@proton.me' \
    --to=uzibalqa@proton.me \
    --cc=help-gnu-emacs@gnu.org \
    --cc=iota@whxvd.name \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).