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

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

Re: How to: 96 bit Date-time arithmetic?


From: lawrence mitchell
Subject: Re: How to: 96 bit Date-time arithmetic?
Date: Sat, 31 Aug 2002 21:49:08 +0100
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2.90 (i386-mingw-windows98.2222)

Siegfried Heintze wrote:

> While I am still curious about 96 bit arithmetic, here an alternative
> attempt. Why does not it work?

> (setq x (decode-time (current-time)))
> (setq y (list (car x) (cadr x)  (caddr x) (1- (cadddr x))
>        (nth 5 x) (nth 6 x) (nth 7 x)(nth 8 x) ))
       ^ (nth 4 x)
> (apply 'encode-time x) ; no error

> (apply 'encode-time y) ; error -- why?

in `nth', N counts from zero.

Hence you want (nth 4 x) before (nth 5 x)
Notice that:

(length x)
    => 9
(length y)
    => 8

I'd probably do
(setcar (nthcdr 3 x) (1- (nth 3 x)))
instead, as it's somewhat easier to read.

On another note of style, you probably don't want to use setq
unless you've already bound x in a `let' form, or x is indeed a
global variable. e.g.
(let ((x (decode-time (current-time))))
  (setcar (nthcdr 3 x) (1- (nth 3 x)))
  x)
To return the modified value of x.
-- 
lawrence mitchell <wence@gmx.li>


reply via email to

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