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

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

Re: problems of everyday life


From: Stefan Monnier
Subject: Re: problems of everyday life
Date: Wed, 16 Nov 2022 22:04:18 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

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---




reply via email to

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