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

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

Re: Easy to add with push but not to the end of a list


From: Emanuel Berg
Subject: Re: Easy to add with push but not to the end of a list
Date: Tue, 06 Dec 2022 03:40:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Michael Heerdegen wrote:

> What happens if you compile a file with these contents
> for example?
>
> (defun test ()
>   (let ((l (list 1 2)))
>     (push-last 2 l)
>     l))

Okay, this then?

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/list.el

(defmacro push-last (elem lst)
  "Push ELEM to be the last element of LST.
Beware that this is O(n) while `push' is O(1)."
  `(if (and (symbolp ,lst)
            (not (symbol-value ,lst)) )
       (setq ,lst (list ,elem))
     (nconc ,lst (list ,elem)) ))

>> Here is the `push' macro - TBH, I don't know what most of
>> that means ...
>
> That supports generalized variables; you don't need to do
> that (unless you want to).

Just wonder why mine looks so different ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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