emacs-devel
[Top][All Lists]
Advanced

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

Re: "Raw" string literals for elisp


From: Alan Mackenzie
Subject: Re: "Raw" string literals for elisp
Date: Wed, 8 Sep 2021 16:01:46 +0000

Hello, Mattias.

On Wed, Sep 08, 2021 at 17:27:58 +0200, Mattias Engdegård wrote:
> 8 sep. 2021 kl. 16.31 skrev Anna Glasgall <anna@crossproduct.net>:

> > Cards on the table here: yes, regexes are 99.999% of the motivation
> > here

> Elisp actually has a much better regexp syntax than most other languages:

> > "\\(\\\\\\\\\\)\\(?:\\(\\\\\\\\\\)\\|\\((\\(?:\\?[0-9]*:\\)?\\|[|)]\\)\\)"

> Today that would be written

> (rx (group "\\\\")
>     (or (group "\\\\")
>         (group
>          (or (seq "("
>                   (? "?" (* digit) ":"))
>              (in ")|")))))

> which is much more readable and maintainable and less error-prone than
> what you would get with a new string syntax.

It is more readable in the same way Cobol was very readable; each small
grouping of text is immediately understandable.  But the thing as a
whole?  The rx form of that regexp takes up 6 lines, the string form 1
line.  If there are several regexps in a function rx can lead to a lot of
bloat.  Having the function fit entirely on one's screen contributes a
lot towards readability and maintainability.

It is true the rx form could be squashed onto 1 or 2 lines, but then that
readability is lost.

I have nothing against people who want to use rx, but personally, I
prefer the string form.  How much better a raw string form would be is
difficult to say.

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

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