[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: String#split converts string args to regexes -- ?
From: "Marcin 'Qrczak' Kowalczyk" <qrczak () knm ! org ! pl>
Date: 2002-07-09 14:53:16
[Download RAW message or body]
Tue, 9 Jul 2002 23:06:58 +0900, Stepan Kasal <kasal@matsrv.math.cas.cz> pisze:
> 1) gsub() ... the parameter has to be regex, so I see no reason for
> accepting (and automatically converting) strings.
It's a pity that "convert a string to regexp" means "compile it".
I would expect it to mean "make a regexp recognizing that string".
Now I must explicitly quote it. If I wanted to have a regexp, I would
have used // instead of ""...
Quoting and unquoting is ugly and error-prone - look at tcl or sh.
I don't know tcl much but I saw results of poorly written scripts
caused by quoting.
> 2) split() ... one-character strings and regular expressing are
> absolutely necessery. Automatic conversion of anything to regexp obfuscates
> split(), I think. So I'd suggest either interpreting long strings as strings
> or forbidding them completely.
Me too; preferably interpreting them as strings. A pity that we can't
change gsub behavior.
I recently used s.gsub(/\{ident\}/) {ident} instead of more
straightforward s.gsub('{ident}') {ident}.
And a pity that I can't say s.gsub('{ident}', ident) because it will
work *almost always*, but break when ident contains backslashes.
Another quoting case that I don't like, although I understand the
reasons... I'm just using the block version unless the target is
a constant.
--
__("< Marcin Kowalczyk
\__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic