unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* utils: Improve docstrings.
@ 2014-11-25 20:52 "Taylan Ulrich Bayırlı/Kammer"
  2014-11-26 10:20 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: "Taylan Ulrich Bayırlı/Kammer" @ 2014-11-25 20:52 UTC (permalink / raw)
  To: guix-devel

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

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: utils: Improve docstrings.
  2014-11-25 20:52 utils: Improve docstrings "Taylan Ulrich Bayırlı/Kammer"
@ 2014-11-26 10:20 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2014-11-26 10:20 UTC (permalink / raw)
  To: taylanbayirli; +Cc: guix-devel

taylanbayirli@gmail.com ("Taylan Ulrich "Bayırlı/Kammer\"") skribis:

> 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*'.

Makes sense.  I’ve applied to patch to ‘core-updates’, since it’s a
full-rebuild change.

Thanks!

Ludo’.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-11-26 10:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-25 20:52 utils: Improve docstrings "Taylan Ulrich Bayırlı/Kammer"
2014-11-26 10:20 ` Ludovic Courtès

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).