[clean-list] questions
Jenda Krynicky
Jenda@Krynicky.cz
Mon, 24 Nov 2003 19:12:59 +0100
From: Fergus Henderson <fjh@cs.mu.oz.au>
> On 20-Nov-2003, Tomasz Zielonka <t.zielonka@zodiac.mimuw.edu.pl>
> wrote: > On Thu, Nov 20, 2003 at 05:26:36PM +0100, Jenda Krynicky
> wrote: > > > > If e.g. I want to make sure that the stuff entered by
> the user is a > > date in YYYY-MM-DD format I definitely do not want
> to spend twenty > > cryptic lines writing a parser where > >
> /^(\d{4})-(\d{1,2})-(\d{1,2})$/ > > suffices. (I know you need to
> make sure the month is between 1 and 12 > > and the day is reasonable,
> but you'd do that outside the parser as > > well.) > > date = do >
> yyyy <- count 4 digit > char '-' > mm <- count 2 digit >
> char '-' > dd <- count 2 digit > return (yyyy, mm, dd) > > Is
> it really so long and cryptic?
>
> No! "\d{4}" is cryptic! "yyyy <- count 4 digit" is elegant and
> reasonably concise without being cryptic.
It could have been \d\d\d\d. (Four digits)
/^(\d\d\d\d)-(\d\d?)-(\d\d?)$/
Anyway I guess the examples I found were not good, your code is not
half as bad as I expected.
If I had the choice I'd still use regexps though :-)
Everything looks cryptic if you are not used to it.
Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery