From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: Elisp - Function returning a list Date: Wed, 16 Dec 2020 09:55:03 +0100 Message-ID: <87im92yvba.fsf@fastmail.fm> References: <87k0ti9ygy.fsf@zoho.eu> <87czza8g37.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7544"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.7; emacs 27.1.50 Cc: help-gnu-emacs@gnu.org, moasenwood@zoho.eu To: steve-humphreys@gmx.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 16 10:07:20 2020 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 1kpSmE-0001pK-3n for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 10:07:18 +0100 Original-Received: from localhost ([::1]:36276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpSmD-0001lp-65 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Dec 2020 04:07:17 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSlB-0001j6-AI for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 04:06:13 -0500 Original-Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:40855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpSl8-0005fS-M4 for help-gnu-emacs@gnu.org; Wed, 16 Dec 2020 04:06:13 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C0DAD9D2; Wed, 16 Dec 2020 04:06:07 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 16 Dec 2020 04:06:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= references:from:to:cc:subject:date:in-reply-to:message-id :mime-version:content-type; s=fm1; bh=XQ8oWomTzmJlzFM03f9hVOpN72 hapMquWcfN4gF2a+w=; b=UGdxf5yUHRZ3w+WcsfOiaAvXx16HqcJ0KjunEmrn0R i8szKfOzfuHl/aub0QHiNzOUQ59uS3UGGwTgkA/ywZ0smXjhZ8gQP+HHPgipyAyP qjXh95c7UUurFtLK3UMsIO0MLQpOlN3+H/fEWcPu+8stiGyJbpy0WzpsVTxoQ2bi 77UNdwcA3gSYZ2sYTpITa3Qg7iefTeGsdBv53T333R7AOJZ/0GJzSJrLtY4i8l2a IM2Pwh4poE5kNjRVkiXeMXoA2443pm5900SPbM8u3tLUUA8XJCRHyTJmfsgCu47Q mf1KbFFwGdiAYsGDcT6IyviLRX13BID5RkRwSdCWYpng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=XQ8oWo mTzmJlzFM03f9hVOpN72hapMquWcfN4gF2a+w=; b=D8vVYYCyMc5bIjTX3dbN/7 Oy2U8Tj0FVkQc0yLcxKob3NiNrYbqcxu5pMgG7ULIUQ+93rAiIehdeKxNKUclWKA lIKIJPUjpq6Ep6JinyDEkcwoY2MVxlNV06xSDCV1vvl+CmLi9MP6r7ixUU8KO7sd yivu4v7+1JROViQuHkoYjBM2b06VG82zFsvodvVaPxR71j1e3ITPoMH5R10EUmAE 3vv2GdC1tPh0ksSIjJJd9haIkXYhf8QeTOu90I+AWSbkSuvNsKsKh9F689mElzZ2 DEN2IrJFAA+LVASMllGR+YIyHKib22ddYr3Fn+o3ubcRMzL9das5YSCVZq6lkTnQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeluddguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfhgfhffvufffjgfkgggtsehttd ertddtredtnecuhfhrohhmpeflohhoshhtucfmrhgvmhgvrhhsuceojhhoohhsthhkrhgv mhgvrhhssehfrghsthhmrghilhdrfhhmqeenucggtffrrghtthgvrhhnpedviefhteeuve ekudetheduieehvdelgfeijeehvdetfeegleelhefhjeduieejveenucfkphepleehrdel tddrvddvgedrvdegieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: from Swift.fastmail.com (ip5f5ae0f6.dynamic.kabel-deutschland.de [95.90.224.246]) by mail.messagingengine.com (Postfix) with ESMTPA id 3A29A24005A; Wed, 16 Dec 2020 04:06:06 -0500 (EST) In-reply-to: Received-SPF: pass client-ip=64.147.123.20; envelope-from=joostkremers@fastmail.fm; helo=wout4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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:126413 Archived-At: On Wed, Dec 16 2020, steve-humphreys@gmx.com wrote: >> Sent: Wednesday, December 16, 2020 at 6:39 AM >> From: "Emanuel Berg via Users list for the GNU Emacs text editor" >> To: help-gnu-emacs@gnu.org >> Subject: Re: Elisp - Function returning a list >> >> steve-humphreys wrote: >> >> > Is using "setq frq" and "setq tim" good >> > >> > (defun agenda-tgrd (&optional tstr tend tskp) >> > "Sets the time grid for the agenda." >> > (interactive "n StartTime: \nn EndTime: \nn SkipTime: ") >> > (let ( (tstr (or tstr 800)) >> > (tend (or tend 1500)) >> > (tskp (or tskp 100)) >> > frq tim) >> > (setq frq '(daily today)) >> > (setq tim (number-sequence tstr tend tskp)) >> > (setq org-agenda-time-grid `(,frq ,tim "------" "---"))) ) >> >> It is better to do all computation in the `let's, then use >> them. No `setq' needed. > > Example? Is there anything written about it? You can use `let*` instead of `let`: ``` (defun agenda-tgrd (&optional tstr tend tskp) "Set the time grid for the agenda." (interactive "n StartTime: \nn EndTime: \nn SkipTime: ") (let* ((tstr (or tstr 800)) (tend (or tend 1500)) (tskp (or tskp 100)) (frq '(daily today)) (tim (number-sequence tstr tend tskp))) (setq org-agenda-time-grid (list frq tim "------" "---")))) ``` (You really only need `let*` for `tim`, in this case; even in your version there was no need to give `frq` a value with `setq`). Some small nitpicks: I'd use `list` instead of backquote-unquote to create a list. And the doc string conventions in Elisp say to use the imperative instead of third person singular, so "Set the time grid" rather than "Sets the time grid". But those are stylistic and therefore personal choices, of course. :-) -- Joost Kremers Life has its moments