From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Adding wc to Bournish Date: Tue, 14 Jun 2016 13:08:54 +0200 Message-ID: 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]:47620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCmDU-0001Qm-UK for guix-devel@gnu.org; Tue, 14 Jun 2016 07:09:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCmDO-0005Er-I3 for guix-devel@gnu.org; Tue, 14 Jun 2016 07:09:07 -0400 Received: from venus.bbbm.mdc-berlin.de ([141.80.25.30]:48562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCmDO-0005Cj-42 for guix-devel@gnu.org; Tue, 14 Jun 2016 07:09:02 -0400 In-Reply-To: <20160614105037.GC10636@debian-netbook> 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 writes: >> It's already calling `((@@ (guix build bournish) >> wc-l-command-implementation) ,@(delete "-l" args)), I could try changi= ng >> the ,@(delete part to ,@((@@ (guix build bournish) only-files) ,@(dele= te >> "-l" args)) and then the various implementation functions will be just >> printing the results >>=20 > > It turns out I forgot that calling only-files from wc-commands would > make it evaluate too soon, so I stuck it inside the different > implementations. Factoring out the check if a file exists or not could > also apply to the ls-command-implementation too later. I don=E2=80=99t understand this (but don=E2=80=99t let this delay you). = I don=E2=80=99t see any =E2=80=9Conly-files=E2=80=9D in your patch. To delay evaluation you can = always wrap expressions in =E2=80=9C(lambda _ ...)=E2=80=9D. I was thinking of a first simplification like this: (define (existing-files 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)))) (define (wc-print file) (let-values (((lines chars) (call-with-input-file file lines+chars))) (format #t "~a ~a ~a~%" lines chars file))) (define (wc-l-print file) (let-values (((lines chars) (call-with-input-file file lines+chars))) (format #t "~a ~a~%" lines file))) (define (wc-c-print file) (let-values (((lines chars) (call-with-input-file file lines+chars))) (format #t "~a ~a~%" chars file))) (define (wc-command-implementation files) (for-each wc-print (filter existing-files files))) (define (wc-l-command-implementation files) (for-each wc-l-print (filter existing-files files))) (define (wc-c-command-implementation files) (for-each wc-c-print (filter existing-files files))) Even at this point there=E2=80=99s a lot of repetition that we could get = rid of, but maybe that=E2=80=99s too zealous. Note that I didn=E2=80=99t follow = this whole discussion, so I could be completely off target. ~~ Ricardo