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

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

Re: [External] : Re: Appending lists


From: Jean Louis
Subject: Re: [External] : Re: Appending lists
Date: Sun, 20 Jun 2021 23:10:49 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> [2021-06-20 23:00]:
> > After this discussion, I thought I'd examine my `nconc' once
> > more and I then realized my use of them resembles a functional
> > style, while it (nconc) is already destructively doing the
> > updateing [...]
> 
> What functions are doing this except for `nreverse' and
> `nconc'?
> 
> I think I have probably used them the same way, should change
> it now when I have learned of their true nature...
> 
> PS. Except for nreverse and nconc, `sort' was mentioned.
>     And the docstring confirms it, "SEQ is modified by side
>     effects." Well, my code has the word "sort" 52 times so
>     I'll check that out tomorrow, Gw...

From: (info "(elisp) Standard Properties")

‘side-effect-free’
     A non-‘nil’ value indicates that the named function is free of side
     effects (*note What Is a Function::), so the byte compiler may
     ignore a call whose value is unused.  If the property’s value is
     ‘error-free’, the byte compiler may even delete such unused calls.
     In addition to byte compiler optimizations, this property is also
     used for determining function safety (*note Function Safety::).

Now... you could make a list of all functions and separate those with
`side-effect-free' and those without, though I don't think it would
guarantee the result.

Then: (info "(elisp) What Is a Function")

13.1 What Is a Function?
========================

In a general sense, a function is a rule for carrying out a computation
given input values called “arguments”.  The result of the computation is
called the “value” or “return value” of the function.  The computation
can also have side effects, such as lasting changes in the values of
variables or the contents of data structures (*note Definition of side
effect::).  A “pure function” is a function which, in addition to having
no side effects, always returns the same value for the same combination
of arguments, regardless of external factors such as machine type or
system state.

Now, you can search in Emacs Lisp manual for "side effect" or
"destruct" and often functions beginning with `n' are such:

 -- Function: nbutlast x &optional n
     This is a version of ‘butlast’ that works by destructively
     modifying the ‘cdr’ of the appropriate element, rather than making
     a copy of the list.

(info "(elisp) Modifying Lists")

(info "(elisp) Rearrangement")

I like following and use it often:

 -- Function: delq object list
     This function destructively removes all elements ‘eq’ to OBJECT
     from LIST, and returns the resulting list.  The letter ‘q’ in
     ‘delq’ says that it uses ‘eq’ to compare OBJECT against the
     elements of the list, like ‘memq’ and ‘remq’.

But I should probably use this one in `let' forms for easier debuggin:

 -- Function: remove object sequence
     This function is the non-destructive counterpart of ‘delete’.  It
     returns a copy of ‘sequence’, a list, vector, or string, with
     elements ‘equal’ to ‘object’ removed.  For example:

More to go:

 -- Function: delete-dups list
     This function destructively removes all ‘equal’ duplicates from
     LIST, stores the result in LIST and returns it.  Of several ‘equal’
     occurrences of an element in LIST, ‘delete-dups’ keeps the first
     one.

Search for "destruct".

-- 
Jean

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

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



reply via email to

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