From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: append, push, and add-to-list. Date: Sun, 4 Jul 2021 13:11:34 +0800 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29535"; mail-complaints-to="usenet@ciao.gmane.io" To: Hongyi Zhao , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 04 07:12:11 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lzuQN-0007Ue-Mw for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 04 Jul 2021 07:12:11 +0200 Original-Received: from localhost ([::1]:37880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lzuQM-0004HV-Ms for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 04 Jul 2021 01:12:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lzuQ2-0004HM-F5 for help-gnu-emacs@gnu.org; Sun, 04 Jul 2021 01:11:50 -0400 Original-Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:35630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lzuQ0-0006zq-RH for help-gnu-emacs@gnu.org; Sun, 04 Jul 2021 01:11:50 -0400 Original-Received: by mail-lj1-x22d.google.com with SMTP id k21so19798968ljh.2 for ; Sat, 03 Jul 2021 22:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=mKIuh+auZJ6bMnR10c3Yw263XSONfIHxkDxgHcjqnCs=; b=qD5V+fS4YfDXV0xiWDI6ayijfcyI8wVY7OcFqrm2me9ohCVljBzsPMYR0khHF9OtTh dQLCwf4TmM+h7DsdxHYsXjpoWcfSRtyHVLzQyXXP4srIPl21IVTjZduv1UFX5gOnN6C+ cKBD7iZyewq6lIQTNTM3/Hm1Vo8s9tgWMiQS9EGHj5ppqad4MjU/tgSpLrLpz3tK7+lu KtFbCfuDlQMliWobQjkJVZxYqmz4qyUak+QzloEOmzdfH+EDVamPt8PJjjnbR9p9mqu8 CSqrDS0wbGxdu9gfLSS0ZLZS36mCMtzsIwT9zylLSgKJTzCU6tweYJmFy88lyYPjOJ8u txPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=mKIuh+auZJ6bMnR10c3Yw263XSONfIHxkDxgHcjqnCs=; b=b1ujVHab7dLRDvHja6GDp5RH5agZSH4Uk3y2hoCrZc7XvbDciwv2cVYFQsF4ovBTp7 oDFjPXjiSGugmFAZuv3SRP42fRzO9Uny7U1utXE29eVvaKNGEEc77r8Een3v0jumYkdB ZMJej4OjkyLqc7QiaZHcs9hHycB05lBz2g/csStIEb/Rwxj1dB8ttws9UvePZRLVjoBY flA+YVCcDpxnkJf3BanlThgQmWoj9GRylE0gstSidq3/3p29CogfQndIW2KhISC/WIyd 9DyKxAX0iwAXgTP5L3JLDNnkuKvVba9v/OKIK+q1D8Q1HhFxs03a2dOr5kTgsTAz1epY bW8g== X-Gm-Message-State: AOAM530tUkdg1t0uj7+KyrSe/JA9ov+VZmt9RiCjmWpadJ573L74CvQu beFzN2C+841B5nQMiFxG31Vg4pxAXmJPIjKnXRs= X-Google-Smtp-Source: ABdhPJyCzZzUaANTJIwy6NQJ8SfjGvmq+4MtI7adE/dCc0U8VFrPjhaXnhx6RhhF5oFMXgB/RxiCe3ssvejUr7P5WBY= X-Received: by 2002:a2e:504b:: with SMTP id v11mr6099797ljd.13.1625375506146; Sat, 03 Jul 2021 22:11:46 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::22d; envelope-from=hongyi.zhao@gmail.com; helo=mail-lj1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:131448 Archived-At: On Sun, Jul 4, 2021 at 12:36 PM Jean Louis wrote: > > * Hongyi Zhao [2021-07-04 06:19]: > > I've noticed there are some similar functions, i.e., append, push, and > > add-to-list, for revising/updating the content of a list. But I'm > > still not so clear on the specific use scenarios for them. Consider > > the following command [1]: > > > > (push '(company-capf company-ispell) company-backends) > > > > What's the equivalent representations using append and add-to-list? > > Which methods are preferable? > > It is recommended to review documentation for each function by using > {C-h f} - > > - function add-to-list is traditionally rather used in configurations, > how I see it, like (add-to-list 'load-path "/my/directory") or > similar, instead, in programming code one shall rather use `push' or > `cl-pushnew' as `add-to-list' adds only new unique elements; Thank you. I listed the usages below for all above-mentioned functions by {C-h f} function-name: (add-to-list LIST-VAR ELEMENT &optional APPEND COMPARE-FN) (push NEWELT PLACE) (cl-pushnew X PLACE [KEYWORD VALUE]...) (append &rest SEQUENCES) > > Because you use it more for configurations, then add-to-list would be: > > (add-to-list 'company-backends '(company-capf company-ispell)) Why can't this be written as follows, just like the other two? (add-to-list company-backends '(company-capf company-ispell)) > > and with append > > (append company-backends '(company-capf company-ispell)) Regards -- Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering NO. 552 North Gangtie Road, Xingtai, China