Re: Re: Questions: Roadmap, Publicity/Groovy, Regexps
Daniel Bonniot <[email protected]> Tue, 01 Mar 2005 01:46:18 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
OK, so it would all be about performance? I imagined the reason to want
regexps in the language might be to have static typing support, like:
(x,y) = "123-4567" ~ /\(.*\)-\(.*\)/
That is, the compiler sees in the regexp that there are two groups, and so the
matching expression returns a couple.
> total = 0
> match_expression = Regexp.new("[a-df-h][aeiou]{2}")
> File.open( 'words', 'r' ) { |file|
> file.each_line { |line|
> word = line.chomp
> total +=1 if word =~ match_expression
> } } puts total
>
> Well that is perhaps more difficult to read, on the other hand if the
> match_expression variable has a name that indicates what the expression
> is then perhaps it is easier to read. The main point about having first
> class regular expressions is that they get instantiated exactly once and
> you don't have to worry about making sure they get instanced only once
> by making them a class wide field (read static data member in C++) or
> whatever. It's about making it easier for the programmer.
So I guess a regexp gets compiled once per syntactic appearance in the source,
right? What if the regexp creation method simply used caching? That should get
you equivalent performance.
In a compiled language, you can actually consider generating the matcher at
compile time (provided the regexp is known), if you have language support. The
question is, is there a strong demand for regexp support in Nice? Otherwise,
what I can see as a more generic enhancement, in the future, is support for
macros/templates/staged compilation, which would be a way to make it possible
to implement such features, and others, without hard-wiring them in the
compiler. I know Bryn Keller has given some thought to this, maybe he will
comment.
Daniel
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click