[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using setq to create lists based on other lists...
From: |
Jean-Christophe Helary |
Subject: |
Re: using setq to create lists based on other lists... |
Date: |
Mon, 3 Dec 2018 02:21:05 +0900 |
Thank you for the comments :)
> You're using `setq` on vars you haven't declared/defined yet!
The Introduction doesn't even mention that...
> I recommend you put `-*- lexical-binding:t -*-` somewhere on the first
> line of your file, and that you `M-x byte-compile RET` your file so
> Emacs can help you catch some of those issues.
I will.
> Better write this as (setf (nth 3 myDateLastMonth) myDay)
No reference to setf in the Introduction, and it's buried under tons of
reference in the Reference...
Thank you again. Now I think there really is too much of a gap between the
Introduction and the Reference. The exchange today kind of confirms that there
is a need to overhaul the documentation so as to get beginners to produce
better code...
Jean-Christophe
> On Dec 3, 2018, at 2:02, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> I see. Eventually I used copy-tree instead to initialize the new lists and
>> then modified them separately with setcar.
>
> So you're back to using `setcar` :-(
>
>> Just out of curiosity, let me post what I did. There are probably
>> better ways to do it, but that's the best I could come up with
>> today. I'd love to be able to think in terms closer to what elisp
>> allows though.
>
> Those date/time thingies are indeed rather annoying to construct.
> copy-sequence + in-place modification is probably the best you can
> use, indeed :-(
>
>> (setq now (decode-time (float-time))
>> myDateLastMonth (copy-tree now)
>> myDateThisMonth (copy-tree now)
>> myDateNextMonth (copy-tree now)
>> now (encode-time now 'integer))
>
> You're using `setq` on vars you haven't declared/defined yet!
> And theses aren't "trees" but lists/sequences, so better use
> `copy-sequence` which is also more efficient:
>
> (let* ((decoded-now (decode-time (float-time)))
> (myDateLastMonth (copy-tree now))
> (myDateThisMonth (copy-tree now))
> (myDateNextMonth (copy-tree now))
> (encoded-now (encode-time now 'integer)))
>
> I recommend you put `-*- lexical-binding:t -*-` somewhere on the first
> line of your file, and that you `M-x byte-compile RET` your file so
> Emacs can help you catch some of those issues.
>
>> ;; create the data for last month
>> (setcar (cdr (cdr (cdr myDateLastMonth))) myDay)
>
> Better write this as (setf (nth 3 myDateLastMonth) myDay)
> It's bad enough that the fields aren't named so you have to refer to
> them by position, but having to count `cdr`s is really annoying IMO.
>
>
> -- Stefan
>
>
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
- using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
- Re: using setq to create lists based on other lists..., Stefan Monnier, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
- Re: using setq to create lists based on other lists..., Stefan Monnier, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
- Re: using setq to create lists based on other lists..., Stefan Monnier, 2018/12/02
- Re: using setq to create lists based on other lists...,
Jean-Christophe Helary <=
- Re: using setq to create lists based on other lists..., Robert Thorpe, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
Message not available
- Re: using setq to create lists based on other lists..., Barry Margolin, 2018/12/02
- Re: using setq to create lists based on other lists..., Stephen Berman, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
- Re: using setq to create lists based on other lists..., Stephen Berman, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02
- Re: using setq to create lists based on other lists..., Michael Heerdegen, 2018/12/02
- Re: using setq to create lists based on other lists..., Jean-Christophe Helary, 2018/12/02