guile-user
[Top][All Lists]
Advanced

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

Re: regex-case


From: Ludovic Courtès
Subject: Re: regex-case
Date: Mon, 08 Feb 2016 15:29:39 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Matt Wette <address@hidden> skribis:

>  (regex-case str
>    (("^([a-z]+)\\(([0-9]+)\\)$" v i)
>     (list v i))
>    (("^([a-z]+)$" v)
>     (list v "1”)))

Sounds useful and convenient!

> (let ((t-292 (make-regexp "^([a-z]+)\\(([0-9]+)\\)$"))
>       (t-293 (make-regexp "^([a-z]+)$")))
>   (cond ((regexp-exec t-292 str)
>          =>
>          (lambda (m)
>            (let ((v (match:substring m 1))
>                  (i (match:substring m 2)))
>              (list v i))))
>         ((regexp-exec t-293 str)
>          =>
>          (lambda (m)
>            (let ((v (match:substring m 1))) (list v "1"))))))

When the ‘else’ clause is missing, I think it would be best to throw an
error like ‘match’ does—it’s rarely helpful to return #unspecified in
those cases.

Ludo’.




reply via email to

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