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, 08 Jun 2016 17:43:09 +0200 Message-ID: <878tyfelf6.fsf@gnu.org> References: <20160524184720.GA27449@debian-netbook> <20160605124033.GB859@debian-netbook> <87eg8bpe2v.fsf@gnu.org> <20160607074155.GB32264@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]:50796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAfdY-00088b-Aa for guix-devel@gnu.org; Wed, 08 Jun 2016 11:43:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAfdW-0008JX-4k for guix-devel@gnu.org; Wed, 08 Jun 2016 11:43:19 -0400 In-Reply-To: <20160607074155.GB32264@debian-netbook> (Efraim Flashner's message of "Tue, 7 Jun 2016 10:41:55 +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 Efraim Flashner skribis: > On Sun, Jun 05, 2016 at 10:37:12PM +0200, Ludovic Court=C3=A8s wrote: [...] >> I=E2=80=99ll commit a couple of fixes for bugs I just found and that pre= vent us >> from doing: >>=20 >> (compile "ls" #:from %bournish-language #:to 'scheme). (This should be be =E2=80=98read-and-compile=E2=80=99, not =E2=80=98compile= =E2=80=99.) Done in f82c58539e1f7b9b864e68ea2ab0c6a17c15fbb5. Take a look at tests/bournish.scm for examples of what is expected. > From ebce5076177314bfd17a53019b3f6b6888762b01 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 (file-size, wc-c-command, wc-l-command, > lines+chars, wc-command, wc-command-implementation): New variables. > (%commands): Add wc command. [...] > +(define* (wc-command-implementation filelist #:optional args) =E2=80=98files=E2=80=99, not =E2=80=98filelist=E2=80=99. > + (let ((files (filter (lambda (file) > + (catch 'system-error > + (lambda () > + (lstat file)) > + (lambda args > + (let ((errno (system-error-errno args))) > + (format (current-error-port) "~a: ~a~%" > + file (strerror errno)) > + #f)))) =E2=80=98stat=E2=80=99 rather than =E2=80=98fstat=E2=80=99. > + (for-each > + (lambda (file) > + (let-values (((lines chars) > + (call-with-input-file file lines+chars))) > + (match args > + (#\l > + (format #t "~a ~a~%" lines file)) > + (#\c > + (format #t "~a ~a~%" chars file)) > + (_ > + (format #t "~a ~a ~a~%" lines chars file))))) > + files))) OK. > +(define (wc-command args . rest) > + (let* ((flags (cond ((string=3D? args "-l") #\l) > + ((string=3D? args "-c") #\c) > + (else #\nul)))) ; no flags, "args" is a file I=E2=80=99d rather make it: (define (wc-commands . args) (cond ((member "-l" args) =E2=80=A6) ((member "-c" args) =E2=80=A6) (else =E2=80=A6))) Instead of the #\nul thing, I think it=E2=80=99d be best to have separate procedures for -l, -c, and the other case. > + ((@@ (guix build bournish) wc-command-implementation) > + (if (char=3D? flags #\nul) (cons args rest) rest) flags))) This is still not emitting code. :-) IOW, there should be a quasiquote here. You can see that by running: (use-modules (system base compile) (guix build bournish)) (read-and-compile (open-input-string "wc -l foo") #:from %bournish-language #:to 'scheme) This should return something like: `((@ (guix build bournish) wc-l-command-implementation) '("foo")) Makes sense? We=E2=80=99re almost done. Please take a look at to make the last review super fast. ;-) Thank you! Ludo=E2=80=99.