[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp and valid-sre?
- To: SRFI-115 discussion list <srfi-115@xxxxxxxxxxxxxxxxx>
- Subject: Re: regexp and valid-sre?
- From: Michael Montague <mikemon@xxxxxxxxx>
- Date: Tue, 26 Nov 2013 10:00:10 -0800
- Delivered-to: srfi-115@xxxxxxxxxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=f98xLEV7Sb+6N0T+2tieBTslEZfgmBh93z1d82sKDYE=; b=LGy8E455eiHdGlevnavCiombjY9WDYn7H6vs7t3NLIfDp1r7ElETR4s8gMfVV03L3W jiF7KfyS33j0knmaFXs5d7kZrfD21MQI5rHeiqw1nQePA9FX5jOFJOW9ARj842VwyTTb bWBtoY7P0ls8yrF+bbmDzN3M0AQIfLeH6/zpF+y4EwBkn+gi26LwPPhjE3YQYIkibL1C 21T+g3vZjqUuYj6dIDTYcpNLrSbRV743wQkJ6T1ieCWdb7edAKgfMO2tfAAVTSx3tXtI O4pWSsAAyMokU88xVLWWYaNMT1vBXEiufUefs13EKyYMNwi8MKXTKrsQjVDWW0++Zwvw GwVA==
- In-reply-to: <20131126141712.GC18148@frohike.xs4all.nl>
- References: <529416A8.email@example.com> <CAMMPzYO_nUTm2GwOV9hKMgkZCaQf8CR7_C7gnWtAGMpcLt=nRQ@mail.gmail.com> <20131126141712.GC18148@frohike.xs4all.nl>
- User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
On 11/26/2013 6:17 AM, Peter Bex wrote:
I don't think that these are strong arguments for having 'valid-sre?'.
An implementation for which compiling is expensive, could easily
internally do the "is it valid"-type check before compiling. Having it
in the interface adds no functionality that is not already easily available.
On Tue, Nov 26, 2013 at 09:44:27PM +0900, Alex Shinn wrote:
On Tue, Nov 26, 2013 at 12:34 PM, Michael Montague <mikemon@xxxxxxxxx>wrote:
Why can the procedure 'regexp' be called with an already compiled <re>
which is just returned?
Convenience, I'd say. That way you can create modules which have an
interface that accepts either SREs or regexp objects (like irregex does),
having it automatically compile SREs.
Why is the procedure 'valid-sre?' necessary? You could just call 'regexp'
and use 'guard' to check for any errors.
Indeed, in fact `valid-sre?' could be defined as:
(define (valid-sre? x)
(guard (else (exn #f)) (regexp x)))
Whether you want to test in advance or catch errors
after the fact is a matter of personal style.
And in some implementations compiling might be a lot more expensive than
simply checking, and if you're just providing on-the-fly feedback to a
user while building a regex dynamically (for example), it might be better
or more efficient to use valid-sre? instead of compiling.
I'm sure that in Irregex at least the DFA compilation is much more
expensive for complex regexes than a simple "is it valid"-type check
I propose dropping 'valid-sre?'.