chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Syntactic sugar for regular expressions and URIs


From: Arto Bendiken
Subject: [Chicken-users] Syntactic sugar for regular expressions and URIs
Date: Wed, 27 Jun 2007 10:31:00 +0200

Howdy all,

I've uploaded a couple of new eggs called `regex-literals' and
`uri-literals' which provide some syntactic sugar [1] that I've used
for a while now, and am curious to see if anyone else is interested
in.

First, the `regex-literals' egg [2] provides precompiled regular
expression literals of the
form `#/[a-z0-9]+/i', the Perl-like #/.../[ixu] syntax sure to be
instantly familiar to most everyone:

 #;1> (use regex-literals)

 #;2> #/[A-Za-z0-9]+/
 #<regexp>

 #;3> ,x #/^[a-z0-9]+$/i
 (regexp "^[a-z0-9]+$" #t #f #f)

 #;4> (string-match #/^(\d{2}):(\d{2})(..)/ "11:59pm")
 ("11:59pm" "11" "59" "pm")

Next, the `uri-literals' egg [3] allows facile use of URIs delimited
by '<' and '>', a natural form already familiar from URL use in
plain-text media:

 #;1> (use uri-literals)

 #;2> #<http://www.call-with-current-continuation.org/>
 #<http://www.call-with-current-continuation.org/>

 #;3> (car (uri-path #<mailto:address@hidden>))
 "address@hidden"

(I've been making heavy use of this to represent URIs in
S-expression-based RDF triples, lately.)

As a reminder, there's also a third sugar-added egg, `date-literals'
[4], that I announced earlier and which provides an SRFI-19 date/time
literal syntax:

 #;1> (use date-literals)

 #;2> (current-date)
 address@hidden:55:54Z

 #;3> address@hidden:59:59Z
 address@hidden:59:59Z

 #;4> ,d address@hidden
 structure of type `date'

 #;5> ,x address@hidden
 (make-date 0 0 0 0 31 12 2007 7200)

(I plan to extend this to also take Unix timestamps directly, like so:
address@hidden'.)

Now, I know that marring the purity of Scheme with arguably gratuitous
syntax won't appeal to everyone, and sure doesn't help much with
portability to other Scheme systems. Still, I've enjoyed the extra
convenience of the aforementioned syntactic forms when working
interactively at the REPL, and hopefully others may too.

Any thoughts and constructive criticism would be most appreciated,
Arto

[1] http://en.wikipedia.org/wiki/Syntactic_sugar
[2] http://chicken.wiki.br/regex-literals
[3] http://chicken.wiki.br/uri-literals
[4] http://chicken.wiki.br/date-literals

--
Arto Bendiken | http://bendiken.net/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]