On Sat, Mar 19, 2011 at 4:33 AM, Peter Otten <span dir="ltr"><__<a href="mailto:peter__@web.de">peter__@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
<div class="im">Could the same be achieved without new regex syntax? I'm thinking of reusing</div>named groups:<br><br>re.findall(r"\b(?P<number>\d+)\b", text,<br> number=lambda s: 1 <= int(s) <= 10)</blockquote>
<div><br></div><div>I like this alternative. (1) the function can simply operate on a string rather than a regex object. (2) it makes the function optional, enabling verification and testing of the regex to be separated from testing the function. (3) it would make it easier to port code that uses this to other languages and perhaps make it more likely to be adopted by other languages.</div>
<div><br></div><div> </div><div class="gmail_quote">On Sat, Mar 19, 2011 at 9:35 AM, Calvin Spealman <span dir="ltr"><<a href="mailto:ironfroggy@gmail.com">ironfroggy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I am -1 on the whole idea.<div><br></div><div>However, for the sake of argument, I'll say that if it was done I would not bind the callbacks at match time.</div><div><br></div><div>Instead, they would be part of the compiled regex objects.</div>
<div><br></div><div>r = re.compile(r"foo:(?C<check_bounds>\d+)", check_bounds=lambda d: 1 <= int(d) <= 100)</div><div><br></div><div>and then r could be used like any other regex, and you don't need to know about the callbacks when actually using it, just to build it.</div>
</blockquote><div><br></div><div>I'd want to understand likely use cases before deciding on early/late binding of the callbacks. And I'm not sure the expressive power of this is worth the effort.</div><div><br></div>
</div><div>--- Bruce<div><div>New Puzzazz newsletter: <a href="http://j.mp/puzzazz-news-2011-03" target="_blank">http://j.mp/puzzazz-news-2011-03</a></div><div>Make your web app more secure: <a href="http://j.mp/gruyere-security" target="_blank">http://j.mp/gruyere-security</a></div>
</div><br></div>