emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find-file-noselect needs save-match-data


From: Herbert Euler
Subject: Re: find-file-noselect needs save-match-data
Date: Sun, 10 Jun 2007 08:05:41 +0800

> It's quite the opposite IMO.  "safe" can mean many things, whereas
> "nodata" clearly indicates that it doesn't set (or modify) match-data.

"-nodata" is good.

> But in practice, we should have a macro to encapsulate calls:
>
>     (preserve-match-data (string-match ...))

This would violate referential transparency.  Consider

(defvar foobar "foobar")

(defun foo ()
  (string-match "foo" foobar)
  (match-string 0 foobar))

(defun bar ()
  (string-match "bar" foobar)
  (preserve-match-data
   (foo)))

Since most applications do not use the match data in practice, I think
if an application use the match data, it should require it explicitly.
I.e., please take a look at the following:

   ;; Normal applications (no use of match data).
   (if (string-match "foo" bar)
       ;; True branch.
     ;; False branch.)
   (foo-bar)

   ;; Applications that use match-data.
   (if (string-match "foo" bar)
       (with-match-data (match-data)
         ;; True branch.)
     ;; No need to use `with-match-data' here, since there is no
     ;; match data.
     ;; False branch.)
   (foo-bar)

IMO, if we can adapt to this model easily, we can make least changes
to existing code.

Regards,
Guanpeng Xu

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]