From mboxrd@z Thu Jan 1 00:00:00 1970 From: Efraim Flashner Subject: Re: Adding wc to Bournish Date: Tue, 14 Jun 2016 13:20:29 +0300 Message-ID: <20160614102029.GB10636@debian-netbook> 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> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cmJC7u66zC7hs+87" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bClSh-0005oy-1M for guix-devel@gnu.org; Tue, 14 Jun 2016 06:20:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bClSc-0003vF-17 for guix-devel@gnu.org; Tue, 14 Jun 2016 06:20:46 -0400 Content-Disposition: inline In-Reply-To: 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: Ricardo Wurmus Cc: guix-devel@gnu.org --cmJC7u66zC7hs+87 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jun 14, 2016 at 11:57:26AM +0200, Ricardo Wurmus wrote: >=20 > Efraim Flashner writes: >=20 > > +(define wc-command-implementation > > + (lambda files > > + (let ((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))) > > + (for-each > > + (lambda (file) > > + (let-values (((lines chars) > > + (call-with-input-file file lines+chars))) > > + (format #t "~a ~a ~a~%" lines chars file))) > > + files)))) > > + > > +(define wc-l-command-implementation > > + (lambda files > > + (let ((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))) > > + (for-each > > + (lambda (file) > > + (let-values (((lines chars) > > + (call-with-input-file file lines+chars))) > > + (format #t "~a ~a~%" lines file))) > > + files)))) > > + > > +(define wc-c-command-implementation > > + (lambda files > > + (let ((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))) > > + (for-each > > + (lambda (file) > > + (let-values (((lines chars) > > + (call-with-input-file file lines+chars))) > > + (format #t "~a ~a~%" chars file))) > > + files)))) >=20 > It looks to me that the filter function is the same in all of these > procedures. Even the actual implementation, i.e. the for-each over the > resulting files is almost exactly the same. >=20 > This could be simplified. If only the format expression differs then > you could abstract this difference away. You could still have three > different procedures, but they can be the result of evaluating a > higher-order function. >=20 > It also seems to me that you could use syntactic sugar to simplify > =E2=80=9C(define something (lambda ...))=E2=80=9D to =E2=80=9C(define (so= mething ...))=E2=80=9D. >=20 > ~~ Ricardo It's already calling `((@@ (guix build bournish) wc-l-command-implementation) ,@(delete "-l" args)), I could try changing the ,@(delete part to ,@((@@ (guix build bournish) only-files) ,@(delete "-l" args)) and then the various implementation functions will be just printing the results --=20 Efraim Flashner =D7=90=D7=A4=D7=A8=D7=99=D7=9D = =D7=A4=D7=9C=D7=A9=D7=A0=D7=A8 GPG key =3D A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351 Confidentiality cannot be guaranteed on emails sent or received unencrypted --cmJC7u66zC7hs+87 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJXX9pqAAoJEPTB05F+rO6TOt8P/jx7FYXcMtG3YUrrsh6x6uSq ANpB7lkQ/mFPdgUQRlTSUHPHxrj7nbdgq3lN2gljGF4e41keBjutuY1Kdgzq4v6u toFncmgO0av32N0uxlHYqwYtFHgpJAzZPm4AqRnTSxSPfgioBk6Uyb+VuoQ8QJ1B I25LDQ4J0MsdPIRBUEXrCOsDBrn1CJevD8nLWHvQ/cB4fYWrafySG2g5E8+mZN40 n/9YjZNF/MtWkL2uiizMAp1KJdQg4qZt/xRufIzIvrZw0JYOuqYFtqOOo1QZqznw tLX+OzBj4S3FD7GTCnyFgifpXtTmAlObKr4oESaQbNy4Tk7ynP1q8bPp98BOc3vd pHrHqH1EuUF7K6Pb9BAP7VIEDruUqboxG7+qcI8JwX/ymcq7CyHRnImG2lixsokz YQi96ZPKhXYaiqUzGYa6ewGG4F8BEe23W7799AJqMr4UGvum1wRi0EgChGRk5Bx7 RTYiHBaDisqQ4GOE7jXRFaZxwlZ7qLazMyiA1BmHv0vWme2QBbFs6SegLE0bID7c lhO1KRW+hrTG1tMB1JDjyZ5+hs3UlIy9cR+yLEuUoYE2hpF39aVyfVpniyirV0qo pfDP3mMB6WD+V33AcJxiWikesuFN3lUT2EoMqlqWhrOXdPzt+CuU2aa2sZsLA/gj Drr8rNyZbC/ztcTCpO6i =1XMC -----END PGP SIGNATURE----- --cmJC7u66zC7hs+87--