unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: problems of everyday life
Date: Wed, 16 Nov 2022 22:04:18 -0500	[thread overview]
Message-ID: <jwvcz9mcmhw.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 87sfijf6b5.fsf@disroot.org

Reminds me of those analog logic circuits which use "standard" digital
gates but represent analog values as durations during which a signal is
asserted, so you can implement the `max` and `min` functions with `or`
and `and` gates respectively.


        Stefan


Akib Azmain Turja [2022-11-16 18:10:54] wrote:

> Juri Linkov <juri@linkov.net> writes:
>
>>> or maybe
>>>
>>>   (apply #'+ '(5 7 10))
>>>
>>> or ... well, what do you prefer?
>>
>> This reminds the implementation of sleep sort:
>>
>>   (dolist (i '(3 1 4 1 5 92 65 3 5 89 79 3))
>>     (run-with-timer (* i 0.001) nil 'message "%d" i))
>>
>> The sorted output printed in the *Messages* buffer:
>>
>>   1 [2 times]
>>   3 [3 times]
>>   4
>>   5 [2 times]
>>   65
>>   79
>>   89
>>   92
>>
>
> Someone implemented addition using sleep.  Now I have implemented
> subtraction:
>
> --8<---------------cut here---------------start------------->8---
> (defun subtract (x y)
>   (when (< y x)
>     (let ((tmp x))
>       (setq x y)
>       (setq y tmp)))
>   (let ((time-a (current-time)))
>     (sleep-for x)
>     (let ((time-b (current-time)))
>       (while (< (float-time (time-subtract nil time-a)) y)
>         (sleep-for 0.9))
>       (floor (float-time (time-subtract nil time-b))))))
>
> (subtract 0 1)     ; => 1
> (subtract 3 5)     ; => 2
> --8<---------------cut here---------------end--------------->8---




  parent reply	other threads:[~2022-11-17  3:04 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 15:19 problems of everyday life Emanuel Berg
2022-11-15 16:45 ` Heime
2022-11-15 16:46 ` Dmitry Gutov
2022-11-15 17:17   ` Heime
2022-11-16 12:02     ` Akib Azmain Turja
2022-11-15 18:38 ` tomas
2022-11-16  7:51 ` Juri Linkov
2022-11-16 12:10   ` Akib Azmain Turja
2022-11-16 20:39     ` Emanuel Berg
2022-11-17  3:04     ` Stefan Monnier via Users list for the GNU Emacs text editor [this message]
2022-11-17  4:56       ` Emanuel Berg
2022-11-17  5:48       ` tomas
2022-11-17  6:13       ` Yuri Khan
2022-11-17  6:25         ` Stefan Monnier
2022-11-16 14:31   ` Emanuel Berg
2022-11-16 14:54   ` Emanuel Berg
2022-11-16 16:14   ` Rudolf Adamkovič
2022-11-16 17:17     ` Emanuel Berg
2022-11-16 20:54 ` North Year
2022-11-16 21:06   ` Emanuel Berg
2022-11-16 21:30   ` Emanuel Berg
2022-11-16 21:38   ` Emanuel Berg
2022-11-17  6:33 ` Jean Louis

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=jwvcz9mcmhw.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).