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

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

Re: Elisp - Function returning a list


From: Joost Kremers
Subject: Re: Elisp - Function returning a list
Date: Wed, 16 Dec 2020 09:55:03 +0100
User-agent: mu4e 1.5.7; emacs 27.1.50

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" 
>> <help-gnu-emacs@gnu.org>
>> 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



reply via email to

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