all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: taylanbayirli@gmail.com ("Taylan Ulrich Bayırlı/Kammer")
To: guix-devel@gnu.org
Subject: utils: Improve docstrings.
Date: Tue, 25 Nov 2014 21:52:13 +0100	[thread overview]
Message-ID: <87bnnv80le.fsf@taylan.uni.cx> (raw)

I just spend half an hour trying to find the bug in the following:

(substitute* "Makefile.in"
  (("^(prefix=[[:blank:]]*)/usr/local$" all prefix)
   (string-append prefix (assoc-ref outputs "out"))))

until I realized the lines of the file are represented as newline
terminated strings and a $ in the regexp won't match a newline by
default.

The behavior could be changed, but it seems like it was explicitly
programmed to work this way, and does make sense in a way, so I
decided to add a warning about this into the docstrings of
`substitute' and `substitute*'.

WDYT?


===File
/home/tub/media/src/guix/0001-utils-Improve-docstrings.patch===
From 3f472e56c3fd9482e42fe8eecee5a857dbd2b8cc Mon Sep 17 00:00:00 2001
From: Taylan Ulrich B <taylanbayirli@gmail.com>
Date: Tue, 25 Nov 2014 21:25:16 +0100
Subject: [PATCH] utils: Improve docstrings.

* guix/build/utils.scm (substitute): Clarify first sentence of
  docstring and add warning to the docstring about using '$' to match
  an end of line.
  (substitute*): Add warning to the docstring about using '$' to match
  an end of line.
---
 guix/build/utils.scm | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index cda4fb1..d93366d 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -365,10 +365,11 @@ PROC's result is returned."
         (false-if-exception (delete-file template))))))
 
 (define (substitute file pattern+procs)
-  "PATTERN+PROCS is a list of regexp/two-argument procedure.  For each line
-of FILE, and for each PATTERN that it matches, call the corresponding PROC
-as (PROC LINE MATCHES); PROC must return the line that will be written as a
-substitution of the original line."
+  "PATTERN+PROCS is a list of regexp/two-argument-procedure pairs.  For each
+line of FILE, and for each PATTERN that it matches, call the corresponding
+PROC as (PROC LINE MATCHES); PROC must return the line that will be written as
+a substitution of the original line.  Be careful about using '$' to match the
+end of a line; by itself it won't match the terminating newline of a line."
   (let ((rx+proc  (map (match-lambda
                         (((? regexp? pattern) . proc)
                          (cons pattern proc))
@@ -428,7 +429,10 @@ When one of the MATCH-VAR is `_', no variable is bound to the corresponding
 match substring.
 
 Alternatively, FILE may be a list of file names, in which case they are
-all subject to the substitutions."
+all subject to the substitutions.
+
+Be careful about using '$' to match the end of a line; by itself it won't
+match the terminating newline of a line."
     ((substitute* file ((regexp match-var ...) body ...) ...)
      (let ()
        (define (substitute-one-file file-name)
-- 
2.1.2

============================================================

             reply	other threads:[~2014-11-25 20:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 20:52 "Taylan Ulrich Bayırlı/Kammer" [this message]
2014-11-26 10:20 ` utils: Improve docstrings Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bnnv80le.fsf@taylan.uni.cx \
    --to=taylanbayirli@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.