From: Marcin Borkowski <mbork@mbork.pl>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Making sure I'm not checking email (or doing other things) too often
Date: Sun, 06 Mar 2016 14:26:47 +0100 [thread overview]
Message-ID: <87k2lfzqi0.fsf@mbork.pl> (raw)
In-Reply-To: <87h9hayr31.fsf@web.de>
On 2016-02-15, at 15:40, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Factoring out the greatest common divider would give you something like
> this:
>
> --8<---------------cut here---------------start------------->8---
> -*- lexical-binding: t -*-
>
> (defun stopwatch ()
> "Return a fresh stopwatch.
> This is a function accepting zero arguments that upon each call
> will return the time difference from its last call in seconds.
> When called the first time it will return nil."
> (let ((last-invocation nil))
> (lambda ()
> (prog1 (and last-invocation
> (time-to-seconds (time-subtract (current-time) last-invocation)))
> (setq last-invocation (current-time))))))
> --8<---------------cut-here---------------end--------------->8---
>
> With that, one could make your advice functions reference and use such a
> stopwatch object (each an individual one, of course).
Thanks. This is my version:
(defun create-stopwatch ()
"Return a closure which returns time (in seconds) since its
last invocation every time it is called."
(let (last-invocation-time (current-time))
(lambda ()
(prog1
(time-to-seconds (time-subtract (current-time) last-invocation-time))
(setq last-invocation-time (current-time))))))
I don't claim it to be better, but I noticed a strange phenomenon. When
I invoke the "stopwatch object" (closure, in fact) for the first time,
I get negative result. Why is that so?
> Regards,
>
> Michael.
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2016-03-06 13:26 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-14 21:05 Making sure I'm not checking email (or doing other things) too often Marcin Borkowski
2016-02-15 1:29 ` Emanuel Berg
2016-02-15 15:21 ` Marcin Borkowski
2016-02-15 16:32 ` tomas
2016-02-16 0:48 ` Emanuel Berg
2016-02-16 7:38 ` tomas
2016-02-17 2:38 ` Emanuel Berg
2016-02-16 0:37 ` Emanuel Berg
[not found] ` <mailman.4745.1455549737.843.help-gnu-emacs@gnu.org>
2016-02-15 21:10 ` Joost Kremers
2016-02-16 0:56 ` Emanuel Berg
2016-02-17 13:42 ` Rusi
2016-02-18 0:24 ` Emanuel Berg
2016-02-15 14:40 ` Michael Heerdegen
2016-02-15 14:58 ` Marcin Borkowski
2016-02-15 15:08 ` Michael Heerdegen
2016-02-15 15:18 ` Marcin Borkowski
2016-03-06 13:26 ` Marcin Borkowski [this message]
2016-03-06 13:36 ` Marcin Borkowski
2016-03-06 13:59 ` Michael Heerdegen
2016-03-06 13:39 ` Michael Heerdegen
2016-03-06 14:09 ` Marcin Borkowski
2016-03-06 14:22 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k2lfzqi0.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=help-gnu-emacs@gnu.org \
--cc=michael_heerdegen@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).