[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: encode-time vs decode-time
From: |
Stefan Monnier |
Subject: |
Re: encode-time vs decode-time |
Date: |
Mon, 19 Aug 2019 17:12:00 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
>> So maybe we should stop documenting "decoded time" objects as being of
>> the form (SEC MINUTE HOUR DAY MONTH YEAR DOW DST UTCOFF SUBSEC), but
>> instead say that it's a `decoded-time` object on which you can use
>> the `decoded-time-*` accessors (and provide a corresponding pcase pattern
>> to replace the `(,sec ,minute ...) one).
>
> That sounds like a reasonable way to move forward.
>
> I'm not a pcase expert. How would one go about doing the pcase stuff? That
> is, how does one provide a pattern so that code like (pcase time
> ((decoded-time :year y :month m) (some-expr-involving y & m))) can extract
> the year and month components Y and M from the broken-down time TIME that
> was created via (make-decoded-time :year y :month m)? Is there an example of
> doing this sort of thing somewhere?
With the cl-defstruct we use for decoded-time, we can already do:
(pcase-let (((cl-struct decoded-time (second s) (minute m) hour day) time))
...)
so we could define
(pcase-defmacro decoded-time (&rest fields)
`(cl-struct decoded-time ,@fields))
OTOH it doesn't work in plain `pcase` currently because of a bug in the
`cl-struct` pcase pattern (it expands to code which does (cl-typep XX
'decoded-time) but the way `decoded-time` is defined makes it unusable
with `cl-typep`).
Stefan
- Re: encode-time vs decode-time, (continued)
- Re: encode-time vs decode-time, Lars Ingebrigtsen, 2019/08/11
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/17
- Re: encode-time vs decode-time, Lars Ingebrigtsen, 2019/08/07
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/17
- Re: encode-time vs decode-time, Eli Zaretskii, 2019/08/17
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/17
- Re: encode-time vs decode-time, Lars Ingebrigtsen, 2019/08/17
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/17
- Re: encode-time vs decode-time, Stefan Monnier, 2019/08/17
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/17
- Re: encode-time vs decode-time,
Stefan Monnier <=
- Re: encode-time vs decode-time, Adam Porter, 2019/08/21
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/21
- Re: encode-time vs decode-time, Adam Porter, 2019/08/26
- Re: encode-time vs decode-time, Paul Eggert, 2019/08/26
- Re: encode-time vs decode-time, Eli Zaretskii, 2019/08/07
Re: encode-time vs decode-time, Lars Ingebrigtsen, 2019/08/07