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

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

Re: Doing something different for the last element of a sequence (partit


From: Tim Landscheidt
Subject: Re: Doing something different for the last element of a sequence (partition)?
Date: Mon, 16 Nov 2020 11:40:37 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

2QdxY4RzWzUUiLuE@potatochowder.com wrote:

>> I have a list of URLs (all-urls) and I want to launch a
>> Firefox window for the first x URLs, then wait y seconds,
>> then launch another one, etc., and then prompt the user if
>> the source of URLs can be deleted (provided that everything
>> went smoothly).

>> If I do:

>> | (seq-doseq (firefox-urls (seq-partition (seq-sort all-urls #'string<) x))
>> |   (apply 'call-process "firefox" nil "*firefox*" nil firefox-urls)
>> |   (sleep-for y))

>> that works fine, except that it also waits for y seconds af-
>> ter the last launch.

> Or handle the first one as the special case (completely untested):

>     (cl-do (((firefox-urls (seq-partition (seq-sort all-urls #'string<) x))
>              (delay 0 y)))
>       (sleep-for delay)
>       (apply 'call-process "firefox" nil "*firefox*" nil firefox-urls))

Inspiration!  I initially looked at seq-reduce, but dismiss-
ed it because I was focussing on the /last/ partition.  But
it is rather simple:

| (let
|     ((all-urls (mapcar 'number-to-string (number-sequence 1 25))))
|   (message "all-urls = %S" all-urls)
|   (seq-reduce
|    (lambda (not-first-call firefox-urls)
|      (if not-first-call
|          (message "Would sleep"))
|      (message "firefox-urls = %S" firefox-urls)
|      t)  ;; Set not-first-call for subsequent calls.
|    (seq-partition (seq-sort #'string< all-urls) 3)
|    nil))

Thanks!

Tim




reply via email to

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