unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Nested gexps in mcron job definitions
@ 2024-12-09 12:36 Yulran
  2024-12-09 13:08 ` Julien Lepiller
  0 siblings, 1 reply; 3+ messages in thread
From: Yulran @ 2024-12-09 12:36 UTC (permalink / raw)
  To: help-guix

Hi guix,

I'm having trouble with nesting g-expressions when defining a mcron job. I want the job to run the same "mastodon-archive" commands for several accounts, so I define a list of accounts and use 'map' to build the complete command. This works well when there are only strings involved, but I can't make it work with gexps.

Here's a simplified example with only strings:

--8<---------------cut here---------------start------------->8---
(define succeeding-job
  (let* ((accounts '("account1" "account2"))
         (cmd (apply string-append
                     (map
                      (lambda (acct)
                        (string-append
                         "mastodon-archive archive " acct "; "))
                      accounts))))
    #~(job '(next-second (range 1 61 10))
           (lambda ()
             (system (string-append "echo '" #$cmd "'")))
           "mastodon-archive")))
--8<---------------cut here---------------end--------------->8---

The job succeeds and the mcron log prints as expected "mastodon-archive archive account1; mastodon-archive archive account2;". Now to use the full path to the mastodon-archive binary, cmd must be a gexp:

--8<---------------cut here---------------start------------->8---
(define failing-job
  (let* ((accounts '("account1" "account2"))
         (cmd #~(apply string-append
                       (map
                        (lambda (acct)
                          (string-append
                           #$mastodon-archive "/bin/mastodon-archive archive " acct "; "))
                        #$accounts))))
    #~(job '(next-second (range 1 61 10))
           (lambda ()
             (system (string-append "echo '" #$cmd "'")))
           "mastodon-archive")))
--8<---------------cut here---------------end--------------->8---

The home configuration builds fine, but the mcron job fails with the error: (wrong-type-arg #f Wrong type to apply: ~S (account1) (account1))

I played around with gexp-ing the string-append in the lambda, ungexp-ing acct, and trying every other combination of gexp/ungexp I could think of, but I could only make it worse.

Any idea what I'm doing wrong?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Nested gexps in mcron job definitions
  2024-12-09 12:36 Nested gexps in mcron job definitions Yulran
@ 2024-12-09 13:08 ` Julien Lepiller
  2024-12-09 13:37   ` Yulran
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Lepiller @ 2024-12-09 13:08 UTC (permalink / raw)
  To: help-guix, Yulran

Hi Yulran,

I think this is related to how gexps are expanded. In your first gexp, you use #$accounts, which expands to ("account1" "account2"), and it's interpreted as a procedure call.

Untested, but '#$accounts should work.

It might be easier to work with a single gexp, like so:

#~(job '(next-second (range 1 61 10))
  (lambda ()
    (let ((accounts …))
      …
      (system …))))

Le 9 décembre 2024 13:36:45 GMT+01:00, Yulran <yulran@posteo.net> a écrit :
>Hi guix,
>
>I'm having trouble with nesting g-expressions when defining a mcron job. I want the job to run the same "mastodon-archive" commands for several accounts, so I define a list of accounts and use 'map' to build the complete command. This works well when there are only strings involved, but I can't make it work with gexps.
>
>Here's a simplified example with only strings:
>
>--8<---------------cut here---------------start------------->8---
>(define succeeding-job
>  (let* ((accounts '("account1" "account2"))
>         (cmd (apply string-append
>                     (map
>                      (lambda (acct)
>                        (string-append
>                         "mastodon-archive archive " acct "; "))
>                      accounts))))
>    #~(job '(next-second (range 1 61 10))
>           (lambda ()
>             (system (string-append "echo '" #$cmd "'")))
>           "mastodon-archive")))
>--8<---------------cut here---------------end--------------->8---
>
>The job succeeds and the mcron log prints as expected "mastodon-archive archive account1; mastodon-archive archive account2;". Now to use the full path to the mastodon-archive binary, cmd must be a gexp:
>
>--8<---------------cut here---------------start------------->8---
>(define failing-job
>  (let* ((accounts '("account1" "account2"))
>         (cmd #~(apply string-append
>                       (map
>                        (lambda (acct)
>                          (string-append
>                           #$mastodon-archive "/bin/mastodon-archive archive " acct "; "))
>                        #$accounts))))
>    #~(job '(next-second (range 1 61 10))
>           (lambda ()
>             (system (string-append "echo '" #$cmd "'")))
>           "mastodon-archive")))
>--8<---------------cut here---------------end--------------->8---
>
>The home configuration builds fine, but the mcron job fails with the error: (wrong-type-arg #f Wrong type to apply: ~S (account1) (account1))
>
>I played around with gexp-ing the string-append in the lambda, ungexp-ing acct, and trying every other combination of gexp/ungexp I could think of, but I could only make it worse.
>
>Any idea what I'm doing wrong?
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Nested gexps in mcron job definitions
  2024-12-09 13:08 ` Julien Lepiller
@ 2024-12-09 13:37   ` Yulran
  0 siblings, 0 replies; 3+ messages in thread
From: Yulran @ 2024-12-09 13:37 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

Hi Julien, thank you! That does work.

So if I understand correctly, #$ doesn't only escape #~ but also unquotes quoted lists. That's good to know! It's possible a good fraction of my recurring troubles with gexps came from not realizing that.

On Mon, Dec 09 2024, Julien Lepiller wrote:

> Hi Yulran,
>
> I think this is related to how gexps are expanded. In your first gexp, you use #$accounts, which expands to ("account1" "account2"), and it's interpreted as a procedure call.
>
> Untested, but '#$accounts should work.
>
> It might be easier to work with a single gexp, like so:
>
> #~(job '(next-second (range 1 61 10))
>   (lambda ()
>     (let ((accounts …))
>       …
>       (system …))))
>
> Le 9 décembre 2024 13:36:45 GMT+01:00, Yulran <yulran@posteo.net> a écrit :
>>Hi guix,
>>
>>I'm having trouble with nesting g-expressions when defining a mcron job. I want the job to run the same "mastodon-archive" commands for several accounts, so I define a list of accounts and use 'map' to build the complete command. This works well when there are only strings involved, but I can't make it work with gexps.
>>
>>Here's a simplified example with only strings:
>>
>>--8<---------------cut here---------------start------------->8---
>>(define succeeding-job
>>  (let* ((accounts '("account1" "account2"))
>>         (cmd (apply string-append
>>                     (map
>>                      (lambda (acct)
>>                        (string-append
>>                         "mastodon-archive archive " acct "; "))
>>                      accounts))))
>>    #~(job '(next-second (range 1 61 10))
>>           (lambda ()
>>             (system (string-append "echo '" #$cmd "'")))
>>           "mastodon-archive")))
>>--8<---------------cut here---------------end--------------->8---
>>
>>The job succeeds and the mcron log prints as expected "mastodon-archive archive account1; mastodon-archive archive account2;". Now to use the full path to the mastodon-archive binary, cmd must be a gexp:
>>
>>--8<---------------cut here---------------start------------->8---
>>(define failing-job
>>  (let* ((accounts '("account1" "account2"))
>>         (cmd #~(apply string-append
>>                       (map
>>                        (lambda (acct)
>>                          (string-append
>>                           #$mastodon-archive "/bin/mastodon-archive archive " acct "; "))
>>                        #$accounts))))
>>    #~(job '(next-second (range 1 61 10))
>>           (lambda ()
>>             (system (string-append "echo '" #$cmd "'")))
>>           "mastodon-archive")))
>>--8<---------------cut here---------------end--------------->8---
>>
>>The home configuration builds fine, but the mcron job fails with the error: (wrong-type-arg #f Wrong type to apply: ~S (account1) (account1))
>>
>>I played around with gexp-ing the string-append in the lambda, ungexp-ing acct, and trying every other combination of gexp/ungexp I could think of, but I could only make it worse.
>>
>>Any idea what I'm doing wrong?
>>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-09 13:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09 12:36 Nested gexps in mcron job definitions Yulran
2024-12-09 13:08 ` Julien Lepiller
2024-12-09 13:37   ` Yulran

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