all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* variables for yesterday and today
@ 2002-10-14 18:39 ken
  0 siblings, 0 replies; 7+ messages in thread
From: ken @ 2002-10-14 18:39 UTC (permalink / raw)




I'm not a great elisp coder, but figured it would be trivial to create a
couple variables similar to current-time, but containing the values for
yesterday and tomorrow, bzw. 'current-time - 86400 seconds' and
'current-time + 86400 seconds'.

But it's not trivial at all, at least not how I've seen it.  So before
reinventing the wheel, has anyone coded these before?


tnx,
ken

-- 
AMD crashes?  See http://cleveland.lug.net/~ken/amd-problem/.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
       [not found] <mailman.1034620817.532.help-gnu-emacs@gnu.org>
@ 2002-10-15  6:52 ` foomaster1200
  2002-10-15 15:15   ` ken
       [not found]   ` <mailman.1034695100.1318.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: foomaster1200 @ 2002-10-15  6:52 UTC (permalink / raw)


ken <ken@cleveland.lug.net> writes:

> I'm not a great elisp coder, but figured it would be trivial to create a
> couple variables similar to current-time, but containing the values for
> yesterday and tomorrow, bzw. 'current-time - 86400 seconds' and
> 'current-time + 86400 seconds'.
> 
> But it's not trivial at all, at least not how I've seen it.  So before
> reinventing the wheel, has anyone coded these before?

I'm still pretty fresh to LISP in general, but this would be my first
hack;

,----
| (defun yesterday-time ()
|   (let ((1day-lsw (% 86400 (<< 1 16)))
| 	(1day-msw (/ 86400 (<< 1 16)))
| 	(now (current-time)))
|     (list
|       (+ (car now) 1day-msw) 
|       (+ (car (cdr now)) 1day-lsw) 
|       (car (cdr (cdr now))))))
`----

The main thing to remember is integers in Emacs are 28 bits I guess.

-- 
You mean you don't want to watch WRESTLING from ATLANTA?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
  2002-10-15  6:52 ` variables for yesterday and today foomaster1200
@ 2002-10-15 15:15   ` ken
       [not found]   ` <mailman.1034695100.1318.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: ken @ 2002-10-15 15:15 UTC (permalink / raw)
  Cc: help-gnu-emacs


foo,

Thanks for the reply, but this isn't working for me.  Maybe there's more 
to it.

The problem seems to be that

(<< 1 16)

yeilds: "Symbol's function definition is void: <<".

I'm using GNU Emacs 20.7.1 (if that could be relevant).

-- 
AMD crashes?  See http://cleveland.lug.net/~ken/amd-problem/.

Spake foomaster1200 at 06:52 (UTC-0000) on Tue, 15 Oct 2002:

= ken <ken@cleveland.lug.net> writes:
= 
= > I'm not a great elisp coder, but figured it would be trivial to create a
= > couple variables similar to current-time, but containing the values for
= > yesterday and tomorrow, bzw. 'current-time - 86400 seconds' and
= > 'current-time + 86400 seconds'.
= > 
= > But it's not trivial at all, at least not how I've seen it.  So before
= > reinventing the wheel, has anyone coded these before?
= 
= I'm still pretty fresh to LISP in general, but this would be my first
= hack;
= 
= ,----
= | (defun yesterday-time ()
= |   (let ((1day-lsw (% 86400 (<< 1 16)))
= | 	(1day-msw (/ 86400 (<< 1 16)))
= | 	(now (current-time)))
= |     (list
= |       (+ (car now) 1day-msw) 
= |       (+ (car (cdr now)) 1day-lsw) 
= |       (car (cdr (cdr now))))))
= `----
= 
= The main thing to remember is integers in Emacs are 28 bits I guess.

Emacs is saying they're 16 bits.

From "C-h f current-time":

Return the current time, as the number of seconds since 1970-01-01 
00:00:00.
The time is returned as a list of three integers.  The first has the
most significant 16 bits of the seconds, while the second has the
least significant 16 bits.  The third integer gives the microsecond
count.


Thanks,
ken

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
       [not found]   ` <mailman.1034695100.1318.help-gnu-emacs@gnu.org>
@ 2002-10-15 16:05     ` Daniel Jensen
  2002-10-15 17:38       ` ken
       [not found]       ` <mailman.1034703565.23323.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Jensen @ 2002-10-15 16:05 UTC (permalink / raw)


ken <ken@cleveland.lug.net> writes:

> Thanks for the reply, but this isn't working for me.  Maybe there's more 
> to it.
>
> The problem seems to be that
>
> (<< 1 16)
>
> yeilds: "Symbol's function definition is void: <<".
>
> I'm using GNU Emacs 20.7.1 (if that could be relevant).

Try using (lsh 1 16) instead.

-- 
Daniel Jensen

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
  2002-10-15 16:05     ` Daniel Jensen
@ 2002-10-15 17:38       ` ken
       [not found]       ` <mailman.1034703565.23323.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: ken @ 2002-10-15 17:38 UTC (permalink / raw)
  Cc: help-gnu-emacs


Yes, that's much better.  But it occurs to me also that this always 
resolves to 65536.  So why not just use the constant and save processing 
time?  The answer is that this would cause an overflow.  

But then the expression "(% 86400 (lsh 1 16))" also always yeilds one 
and the same integer expression, 20864, and "(/ 86400 (lsh 1 16))" 
always yeilds 1.  Is there any reason not to replace these expression 
with the constants they're always going to resolve to?


Thanks everyone for their assistance.

ken

-- 
AMD crashes?  See http://cleveland.lug.net/~ken/amd-problem/.

Spake Daniel Jensen at 18:05 (UTC+0200) on Tue, 15 Oct 2002:

= ken <ken@cleveland.lug.net> writes:
= 
= > Thanks for the reply, but this isn't working for me.  Maybe there's more 
= > to it.
= >
= > The problem seems to be that
= >
= > (<< 1 16)
= >
= > yeilds: "Symbol's function definition is void: <<".
= >
= > I'm using GNU Emacs 20.7.1 (if that could be relevant).
= 
= Try using (lsh 1 16) instead.
= 
= 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
       [not found]       ` <mailman.1034703565.23323.help-gnu-emacs@gnu.org>
@ 2002-10-16  5:25         ` foomaster1200
  2002-10-16 14:05           ` ken
  0 siblings, 1 reply; 7+ messages in thread
From: foomaster1200 @ 2002-10-16  5:25 UTC (permalink / raw)


ken <ken@cleveland.lug.net> writes:

> Yes, that's much better.  But it occurs to me also that this always 
> resolves to 65536.  So why not just use the constant and save processing 
> time?  The answer is that this would cause an overflow.  

Because I wanted to make it plainly obvious how it works.

BTW, the symbol << is in (require 'cl)

-- 
Should I do my BOBBIE VINTON medley?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: variables for yesterday and today
  2002-10-16  5:25         ` foomaster1200
@ 2002-10-16 14:05           ` ken
  0 siblings, 0 replies; 7+ messages in thread
From: ken @ 2002-10-16 14:05 UTC (permalink / raw)
  Cc: help-gnu-emacs


Spake foomaster1200 at 05:25 (UTC-0000) on Wed, 16 Oct 2002:

= ken <ken@cleveland.lug.net> writes:
= 
= > Yes, that's much better.  But it occurs to me also that this always 
= > resolves to 65536.  So why not just use the constant and save processing 
= > time?  The answer is that this would cause an overflow.  
= 
= Because I wanted to make it plainly obvious how it works.
= ...

And this is good practice... much appreciated.  It was mentioned just to 
see if the group saw any possible holes in my thinking in the logic.

Documentation in the code's comments could accomplish this also, while
still producing faster code.  Different strokes, I guess.

Upon testing the function (the slightly revised version of it) I found 
that it doesn't actually return yesterday's date (i.e., yesterday's 
current-time), but rather tomorrow's.  So how would we alter this to get 
yesterday's?


(defun yesterday-time ()
  (let ((1day-lsw (% 86400 (lsh 1 16)))
	(1day-msw (/ 86400 (lsh 1 16)))
	(now (current-time)))
    (list
     (+ (car now) 1day-msw) 
     (+ (car (cdr now)) 1day-lsw) 
     (car (cdr (cdr now))))))


Thanks very much,
ken

-- 
AMD crashes?  See http://cleveland.lug.net/~ken/amd-problem/.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-10-16 14:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1034620817.532.help-gnu-emacs@gnu.org>
2002-10-15  6:52 ` variables for yesterday and today foomaster1200
2002-10-15 15:15   ` ken
     [not found]   ` <mailman.1034695100.1318.help-gnu-emacs@gnu.org>
2002-10-15 16:05     ` Daniel Jensen
2002-10-15 17:38       ` ken
     [not found]       ` <mailman.1034703565.23323.help-gnu-emacs@gnu.org>
2002-10-16  5:25         ` foomaster1200
2002-10-16 14:05           ` ken
2002-10-14 18:39 ken

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.