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: Emanuel Berg
Subject: Re: problems of everyday life
Date: Wed, 16 Nov 2022 15:54:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Juri Linkov wrote:

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

This made my day :)

(defun sleep-sort (&rest lst)
  (let ((sorted))
    (dolist (i lst)
      (run-with-timer (* i 0.001) nil (lambda () (push i sorted))) )
    (while (> (length lst) (length sorted))
      (sleep-for 1) )
    (nreverse sorted) ))

(sleep-sort 3 1 4 1 5 92 65 3 5 89 79 3)

-> (1 1 3 3 3 4 5 5 65 79 89 92)

Maybe one can integrate the busy wait somehow since the
maximum wait time is known ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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