From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: Adding wc to Bournish Date: Wed, 15 Jun 2016 15:56:43 +0200 Message-ID: <87shwed084.fsf@gnu.org> References: <20160524184720.GA27449@debian-netbook> <20160605124033.GB859@debian-netbook> <87eg8bpe2v.fsf@gnu.org> <20160607074155.GB32264@debian-netbook> <878tyfelf6.fsf@gnu.org> <20160614092713.GA2832@debian-netbook> <20160614102029.GB10636@debian-netbook> <20160614105037.GC10636@debian-netbook> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDBJc-0000lU-DA for guix-devel@gnu.org; Wed, 15 Jun 2016 09:57:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDBJZ-0005r6-53 for guix-devel@gnu.org; Wed, 15 Jun 2016 09:57:08 -0400 In-Reply-To: <20160614105037.GC10636@debian-netbook> (Efraim Flashner's message of "Tue, 14 Jun 2016 13:50:37 +0300") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Efraim Flashner Cc: guix-devel@gnu.org, David Thompson Efraim Flashner skribis: > From 09eef9cd841a7d212e024be0609168611923696b Mon Sep 17 00:00:00 2001 > From: Efraim Flashner > Date: Sun, 22 May 2016 14:56:06 +0300 > Subject: [PATCH] bournish: Add `wc' command. > > * guix/build/bournish.scm (lines+chars, only-files, wc-commands, > wc-command-implementation, wc-l-command-implementation, > wc-c-command-implementation): New variables. s/variables/procedures/ :-) > (%commands): Add wc command. [...] > +(define (only-files files) > + (filter (lambda (file) > + (catch 'system-error > + (lambda () > + (stat file)) > + (lambda args > + (let ((errno (system-error-errno args))) > + (format (current-error-port) "~a: ~a~%" > + file (strerror errno)) > + #f)))) > + files)) > + > +(define (wc-command-implementation . files) > + (for-each > + (lambda (file) > + (let-values (((lines chars) > + (call-with-input-file file lines+chars))) > + (format #t "~a ~a ~a~%" lines chars file))) > + ((@@ (guix build bournish) only-files) files))) I prefer the approach Ricardo suggested, I think it=E2=80=99s more concise = and clearer: https://lists.gnu.org/archive/html/guix-devel/2016-06/msg00525.html Also, note that @@ would not be needed here; @@ serves to access private bindings within a specific module: https://www.gnu.org/software/guile/manual/html_node/Using-Guile-Modules.h= tml Last, do not miss the bit about docstrings at: https://www.gnu.org/software/guix/manual/html_node/Formatting-Code.html :-) With these changes, we=E2=80=99re all set. Thanks! >From a GSoC viewpoint, I think we must move to the compilation part now. Specifically, I think the next step is to start parsing Bash code. For that we could use SILex + parse-lalr, but these are not the nicest tools for the job. Better tools would be =E2=80=9Cparsing expression gramm= ars=E2=80=9D (the (ice-9 peg) module in Guile 2.1) or parser combinators, though I don=E2=80=99t think there=E2=80=99s a directly usable Guile library for tha= t. Maybe Eric or David can comment? The goal is to have a parser that returns an abstract syntax tree (AST) as an sexp: (parse "(cd /foo; ls $HOME) && echo *.a ; echo done") =3D> '(sequence (success-sequence (subshell (sequence (command "cd" "/foo") (command "ls" (variable-ref "HOME")))) (command "echo" (glob "*.a"))) (command "echo" "done")) Thoughts? Ludo=E2=80=99.