From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: A simple battery level alert mcron job for your Guix, v2 Date: Wed, 31 Jul 2019 17:23:16 +0200 Message-ID: <87sgqmtehx.fsf@elephly.net> References: <877e8axtu4.fsf@gmail.com> <87a7ctbvdy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:54987) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hsqRx-0007YI-1b for help-guix@gnu.org; Wed, 31 Jul 2019 11:23:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hsqRu-0002gW-CF for help-guix@gnu.org; Wed, 31 Jul 2019 11:23:32 -0400 Received: from sender4-of-o53.zoho.com ([136.143.188.53]:21305) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hsqRt-0002az-7e for help-guix@gnu.org; Wed, 31 Jul 2019 11:23:30 -0400 In-reply-to: <87a7ctbvdy.fsf@gmail.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+gcggh-help-guix=m.gmane.org@gnu.org Sender: "Help-Guix" To: Maxim Cournoyer Cc: help-guix@gnu.org Maxim Cournoyer writes: > The following mcron job accomplish this. I've implemented it in Guile > Scheme this time around and was puzzled that I had to use program-file > to make it work, otherwise srfi-26's cut would error on undefined symbol > '<>'. > > The problem was that passing the code as a lambda would have the syntax > imported not a the top level, which is the only valid place to > define/import syntax definitions, per the Guile manual. Using > `program-file' works around that, by placing the logic at the top level > of a standalone script, while allowing you to define everything at the > level of your Guix config file. Ah, thanks for investigating this. When you first asked about this I was really quite puzzled. > (let* ((input-pipe (open-pipe* OPEN_READ > #$(file-append acpi "/bin/acpi"))) > (output (get-string-all input-pipe)) > (m (string-match "Discharging, ([0-9]+)%" output)) > (level (and=> m (compose string->number > (cut match:substring <> 1))))) > (when (and=> level (cut <= <> %min-level)) > (format #t "warning: Battery level is low (~a%)~%" level) > (invoke #$(file-append beep "/bin/beep") "-r5"))))))) Perhaps and-let* (SRFI 2) would be of interest here. -- Ricardo