unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: Appending lists
@ 2021-06-14 16:44 Pierpaolo Bernardi
  2021-06-15  0:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 66+ messages in thread
From: Pierpaolo Bernardi @ 2021-06-14 16:44 UTC (permalink / raw)
  To: henri-biard@francemel fr, help-gnu-emacs@gnu org

(defvar newlist 
    (append city district))


Il giorno 14 giugno 2021, alle ore 18:40, henri-biard@francemel.fr ha scritto:



I want to make a new list named newlist to be



 (append city district)



and put the new list into a new list.




I want to end up the equivalent of 

(defvar newlist
'( ("London" . 1)  ("Paris" . 2) ("Madrid" . 3)  ("Greenwich" . 1) ("Louvre" . 2) ("Centro" . 3) ) ) 





From: Pierpaolo Bernardi <olopierpa@gmail.com>
To: henri-biard@francemel fr <henri-biard@francemel.fr>;
   help-gnu-emacs@gnu org <help-gnu-emacs@gnu.org>
Subject: Re: Appending lists
Date: 14/06/2021 18:36:08 Europe/Paris

Then

(append city district)

does what you say you want. I suspect you want something else, though.

Il giorno 14 giugno 2021, alle ore 18:32, henri-biard@francemel.fr ha scritto:

From: Pierpaolo Bernardi <olopierpa@gmail.com>
To: henri-biard@francemel.fr <henri-biard@francemel.fr>;
   help-gnu-emacs@gnu org <help-gnu-emacs@gnu.org>
Subject: Re: Appending lists
Date: 14/06/2021 18:24:21 Europe/Paris

It is not clear what you want to do. Give an example of inputs and the relative output.

Il giorno 14 giugno 2021, alle ore 18:13, henri-biard@francemel.fr ha scritto:


I would like to make a list that is composed of appending three lists together.  Could use append,

but do not know how to put the result into a new list. 



(defvar city
  '( ("London" . 1)  ("Paris" . 2) ("Madrid" . 3))
   "docstring" )

(defvar district
   '( ("Greenwich" . 1) ("Louvre" . 2) ("Centro" . 3) )

   "docstring" )






^ permalink raw reply	[flat|nested] 66+ messages in thread
* Re: Appending lists
@ 2021-06-17  3:18 Drew Adams
  2021-06-17  7:48 ` tomas
  0 siblings, 1 reply; 66+ messages in thread
From: Drew Adams @ 2021-06-17  3:18 UTC (permalink / raw)
  To: Emanuel Berg, Help-Gnu-Emacs (help-gnu-emacs@gnu.org)

> >> What's a "deep copy"?
> >
> > It's a copy where every part of the object is separate, not
> > `eq' to the corresponding parts of the object that
> > you copied.
> >
> > For a cons, which is a tree, it would mean that neither car
> > nor cdr are shared between the original and the copy, and
> > that the same is true for any cars and cdrs that are,
> > themselves, conses.
> >
> > IOW, the tree is separate/independent from its copy.
> > When that's the case you can change any parts of either
> > without affecting the other.
> >
> > `C-h f copy-tree' describes the difference between what it
> > does (a deep copy) and what `copy-sequence' does (shallow
> > copy - doesn't copy cars.
> 
> deep copy = actual copy
> shallow copy = copy of references?

Did you read `C-h f copy-tree'?

No.  Everything involving list structure (conses)
uses references.

`copy-sequence' is a shallow copy - it copies only
the conses that make up the cdrs, so that you get
new conses for ONLY those - just the conses that
make up the _sequence_).

It copies only the flat, cdr list structure, not
any list structure in cars.  You get a new sequence,
but the sequence elements (the cars) share list
structure with the input sequence.

E.g., `copy-sequence' on the list `((1 2) 3 (4))'
gives you a new sequence (list) whose elements are
also `(1 2)', `3', and `(4)'.  The first and third
elements are not only `equal' to those of the input
sequence - they are `eq' to them.

`copy-tree' is a deep copy - it copies conses in
both cars and cdrs, so you get new list structure
(conses) everywhere.  There is NO cons in the
output that's `eq' to a cons in the input.

The result of `copy-tree' is a new `((1 2) 3 (4))'
list a new tree through and through.  Its first
element, `(1 2)' is not `eq' to the `(1 2)' of the
input list.  Same thing for its last element.

`copy-tree' results in a list that's `equal' to
the input list, but there is no cons in it that's
`eq' to a cons of the input.  `copy-sequence'
guarantees that conses in cars of the output
sequence ARE `eq' to those in the input.

(setq foo '((1 2) 3 (4)))

(setq sfoo (copy-sequence foo))

(eq foo sfoo)                 ; nil
(eq (car foo) (car sfoo))     ; t
(eq (caddr foo) (caddr sfoo)) ; t

(setq tfoo (copy-tree foo))

(eq foo tfoo)                 ; nil
(eq (car foo) (car tfoo))     ; nil
(eq (caddr foo) (caddr tfoo)) ; nil

`copy-tree' is more expensive.  `copy-sequence'
lets you continue to share sequence elements.

If two lists share any parts, then if you change
such a shared part in one it's changed also in
the other.  That's exactly the point of sharing.

It's also the "danger".  Don't share List
structure unless you intend to.  You may never
need to or want to.

You will need to be aware of list structure
and the possibility that it gets shared, when
playing with Lisp code that you didn't write,
at least.

And know about Lisp functions that can catch
you up on this kind of thing - functions called
"destructive" in the doc, i.e., functions that
can modify or share list structure.

____

[If you happen to know Fortran then think
COMMON blocks plus overlapping DIMENSION specs:
shared bits of overlapping memory, like Venn
diagrams.  Programs can act on different bits
in different ways.  Many large Fortran programs
were all about this sort of thing.  Likewise
some assembler programs.]




^ permalink raw reply	[flat|nested] 66+ messages in thread
* Re: Appending lists
@ 2021-06-14 16:36 Pierpaolo Bernardi
  2021-06-14 16:40 ` henri-biard
  0 siblings, 1 reply; 66+ messages in thread
From: Pierpaolo Bernardi @ 2021-06-14 16:36 UTC (permalink / raw)
  To: henri-biard@francemel fr, help-gnu-emacs@gnu org

Then

    (append city district)

does what you say you want. I suspect you want something else, though.

Il giorno 14 giugno 2021, alle ore 18:32, henri-biard@francemel.fr ha scritto:

I want to do 


  (append '(city district))


and put the new list into a new list.



From: Pierpaolo Bernardi <olopierpa@gmail.com>
To: henri-biard@francemel.fr <henri-biard@francemel.fr>;
   help-gnu-emacs@gnu org <help-gnu-emacs@gnu.org>
Subject: Re: Appending lists
Date: 14/06/2021 18:24:21 Europe/Paris

It is not clear what you want to do. Give an example of inputs and the relative output.

Il giorno 14 giugno 2021, alle ore 18:13, henri-biard@francemel.fr ha scritto:


I would like to make a list that is composed of appending three lists together.  Could use append,

but do not know how to put the result into a new list. 



(defvar city
  '( ("London" . 1)  ("Paris" . 2) ("Madrid" . 3))
   "docstring" )

(defvar district
   '( ("Greenwich" . 1) ("Louvre" . 2) ("Centro" . 3) )

   "docstring" )





^ permalink raw reply	[flat|nested] 66+ messages in thread
* Re: Appending lists
@ 2021-06-14 16:24 Pierpaolo Bernardi
  2021-06-14 16:32 ` henri-biard
  0 siblings, 1 reply; 66+ messages in thread
From: Pierpaolo Bernardi @ 2021-06-14 16:24 UTC (permalink / raw)
  To: henri-biard@francemel.fr, help-gnu-emacs@gnu org

It is not clear what you want to do. Give an example of inputs and the relative output.

Il giorno 14 giugno 2021, alle ore 18:13, henri-biard@francemel.fr ha scritto:


I would like to make a list that is composed of appending three lists together.  Could use append,

but do not know how to put the result into a new list. 



(defvar city
  '( ("London" . 1)  ("Paris" . 2) ("Madrid" . 3))
   "docstring" )

(defvar district
   '( ("Greenwich" . 1) ("Louvre" . 2) ("Centro" . 3) )

   "docstring" )





^ permalink raw reply	[flat|nested] 66+ messages in thread
* Appending lists
@ 2021-06-14 16:08 henri-biard
  0 siblings, 0 replies; 66+ messages in thread
From: henri-biard @ 2021-06-14 16:08 UTC (permalink / raw)
  To: help-gnu-emacs


I would like to make a list that is composed of appending three lists together.  Could use append,

but do not know how to put the result into a new list. 



(defvar city
  '( ("London" . 1)  ("Paris" . 2) ("Madrid" . 3))
   "docstring" )

(defvar district
   '( ("Greenwich" . 1) ("Louvre" . 2) ("Centro" . 3) )

   "docstring" )






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

end of thread, other threads:[~2021-06-19 21:31 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-14 16:44 Appending lists Pierpaolo Bernardi
2021-06-15  0:56 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  1:47   ` henri-biard
2021-06-15  7:09     ` Emanuel Berg via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2021-06-17  3:18 Drew Adams
2021-06-17  7:48 ` tomas
2021-06-18 23:38   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-18 23:50   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  6:57     ` tomas
2021-06-19 21:31       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-14 16:36 Pierpaolo Bernardi
2021-06-14 16:40 ` henri-biard
2021-06-14 18:21   ` Alexandr Vityazev
2021-06-15  0:46     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  8:27       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-15  9:18         ` tomas
2021-06-16  1:11           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16  7:28             ` tomas
2021-06-16  9:13               ` Jean Louis
2021-06-16  9:32                 ` tomas
2021-06-16 10:55                   ` Jean Louis
2021-06-16 16:44                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16  9:19               ` Jean Louis
2021-06-16  9:35                 ` tomas
2021-06-16 10:57                   ` Jean Louis
2021-06-16 16:55                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 11:16                 ` Yuri Khan
2021-06-16 11:30                   ` Jean Louis
2021-06-16 11:54                     ` tomas
2021-06-16 17:31                       ` Jean Louis
2021-06-16 23:13                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:41                           ` Jean Louis
2021-06-16 13:01                     ` Philip Kaludercic
2021-06-16 16:59                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 17:36                       ` Jean Louis
2021-06-16 18:54                         ` tomas
2021-06-16 21:24                           ` Philip Kaludercic
2021-06-16 23:25                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:16                               ` tomas
2021-06-17  7:14                             ` tomas
2021-06-16 23:24                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:19                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:54                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 18:49                   ` tomas
2021-06-16 21:40                     ` Jean Louis
2021-06-16 22:35                       ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 23:02                         ` Jean Louis
2021-06-17  0:00                           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:44                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:20                           ` tomas
2021-06-16 23:39                       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 23:31                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 14:22               ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 15:11                 ` tomas
2021-06-16 15:31                   ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-16 15:48                     ` tomas
2021-06-16 23:04                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-17  7:50                       ` tomas
2021-06-18 23:47                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-19  2:35                           ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-06-19  6:52                             ` tomas
2021-06-16 23:03                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-16 16:42               ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-06-14 16:24 Pierpaolo Bernardi
2021-06-14 16:32 ` henri-biard
2021-06-14 16:08 henri-biard

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