From mboxrd@z Thu Jan 1 00:00:00 1970 From: Efraim Flashner Subject: Re: Adding wc to Bournish Date: Thu, 26 May 2016 22:27:55 +0300 Message-ID: <20160526192755.GB28047@debian-netbook> References: <20160524184720.GA27449@debian-netbook> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="V88s5gaDVPzZ0KCq" 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 1b60x6-0005Lg-QE for guix-devel@gnu.org; Thu, 26 May 2016 15:28:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b60x2-0006Hb-Hu for guix-devel@gnu.org; Thu, 26 May 2016 15:28:15 -0400 Content-Disposition: inline In-Reply-To: <20160524184720.GA27449@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: guix-devel@gnu.org, Ludovic =?utf-8?B?PT91dGYtOD9RP0NvdXJ0PUMzPUE4cz89?= , Eric Bavier --V88s5gaDVPzZ0KCq Content-Type: multipart/mixed; boundary="98e8jtXdkpgskNou" Content-Disposition: inline --98e8jtXdkpgskNou Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Here's where I'm currently at with 'wc'. Currently I'm getting an error about having the wrong number of arguments for lambda (I assume) ;;; /home/efraim/workspace/guix/guix/build/bournish.scm:143:2: warning: wrong number of arguments to `#' It's not ready as-is, but I wanted to show what I had so far :) --=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 --98e8jtXdkpgskNou Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-Bournish-Add-wc-command.patch" Content-Transfer-Encoding: quoted-printable =46rom f909c39530c727f414c8c827bdbccb2285ad1cc5 Mon Sep 17 00:00:00 2001 =46rom: 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-w-command, wc-l-command, wc-command): New variables. (%commands): Add wc command. --- guix/build/bournish.scm | 56 +++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/guix/build/bournish.scm b/guix/build/bournish.scm index 4022796..d133796 100644 --- a/guix/build/bournish.scm +++ b/guix/build/bournish.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2016 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2016 Efraim Flashner ;;; ;;; This file is part of GNU Guix. ;;; @@ -21,11 +22,13 @@ #:use-module (system base compile) #:use-module (system repl command) #:use-module (system repl common) + ;#:use-module (ice-9 streams) #:use-module (ice-9 rdelim) #:use-module (ice-9 match) #:use-module (ice-9 ftw) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-41) #:export (%bournish-language)) =20 ;;; Commentary: @@ -103,6 +106,56 @@ characters." ((@ (guix build utils) dump-port) port (current-output-port)) *unspecified*))) =20 +(define (file-size file) + (stat:size (stat file))) + +(define (wc-c-command file) + ;; Faster when only `wc -c' is called + (file-size file)) + +(define (wc-l-command file) + ;; Faster when only `wc -l' is called + (stream-length + (stream-filter + (lambda (chr) + (char=3D? chr #\newline)) + (port->stream (open-file file "r"))))) + +;(define (wc-l-command file) +; (call-with-input-file file +; (lambda (port) + +(define (lines+chars port) + ;; Return the number of lines and number of chars read from PORT. + (let loop ((lines 0) (words 0) (chars 0)) + (match (read-char port) + ((? eof-object?) ;done! + (values lines words chars)) + (#\newline ;recurse + (loop (1+ lines) (1+ words) (1+ chars))) + ((and (char-set<=3D ? char-set:blank) ; need to fix/replace the '?' + (char-set<=3D (peek-char port) char-set:graphic)) + (loop lines (1+ words) (1+ chars))) + (_ ;recurse + (loop lines words (1+ chars)))))) + +(define (wc-command file) + ((lambda (lines words chars) ; lambda doesn't like 3 variables + (format #t "~a ~a ~a ~a~%" lines words chars file)) + (call-with-input-file file lines+chars))) + +; let-values is undefined +; (let-values (((lines words chars) +; (call-with-input-file file lines+chars))) +; (format #t "~a ~a ~a ~a~%" lines chars words file))) + +;(define (wc-command file) +; (let ((wc-l (wc-l-command file)) +; (wc-w (wc-w-command file)) +; (wc-c (wc-c-command file))) +; (format #t "~{~a ~}\n" +; (list wc-l wc-w wc-c file)))) + (define (help-command . _) (display "\ Hello, this is Bournish, a minimal Bourne-like shell in Guile! @@ -129,7 +182,8 @@ commands such as 'ls' and 'cd'; it lacks globbing, pipe= s---everything.\n")) ("help" ,help-command) ("ls" ,ls-command) ("which" ,which-command) - ("cat" ,cat-command))) + ("cat" ,cat-command) + ("wc" ,wc-command))) =20 (define (read-bournish port env) "Read a Bournish expression from PORT, and return the corresponding Sche= me --=20 2.8.3 --98e8jtXdkpgskNou-- --V88s5gaDVPzZ0KCq Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCgAGBQJXR043AAoJEPTB05F+rO6T12AP/17Im9VcXtVaLTwLhtU7VJxw bglvEBKJjqBqc7HGFrZRbclmQlKOyBeuBkyAJvj2CFFwknvWJi27Z/Pnru0BBd0F TIoLboAUN4x22QpPu5K7lAv7A9XTNG51dI1mSHJAcAWKrwFYOBrGi1oH63xD3BUR VFEHgCiUgpTtmv2QUBfUiqpxQ1tn3gl4eBKtu8auv2LtE478Q4Puy3vsWjtylxeB qbplIAgQ1wjxkiAY89cOMJ0XvFs+CkaAYVoG8Re4H3ZceYc7K/Ri2zZ/8wQBocQ+ x8Wl5iBcNAp0X4II//rlRVb1FuD5NxAH1Dim/RbtBgdpJUkGVUmK74a7W5FG1TKs ozqgFbH7sNJEzgHEopl5a3vBPvnUs7/BctDZVpSbxm7gA0wz4zyctw+6zB2uVRGv 9qH8AuhW8UXm435k1DGnx7Amv/TmljKUE6SbO9D2vFQqbfCbPzw0JYkbk20EAmHD 98fcZPyFKw0QH114Z37Ts1c7G+iR6GR0s5HkxzMe302DmXC29E0GKAB9Uyl5VyPU 1AakjvsyyuLllpe9yYt+ZAAoRySQyCZ2CRQOlRS9ZsQQimaN+m7aLBoNexjQ5J0W 8ufHkSclx+I0p/VbytLLj2/9zx1U/I8JS25xMzbHckYOtS6APs6ZnlYrAIHfTn9d v8T2lfuv7FnL4JmVyU7Z =YdTx -----END PGP SIGNATURE----- --V88s5gaDVPzZ0KCq--