[mercury-users] Leveraging Perl
Ralph Becket
rbeck at microsoft.com
Tue May 1 19:47:54 AEST 2001
> From: Peter Schachte [mailto:schachte at cs.mu.OZ.AU]
>
> You can do anything in Mercury. I think you should ask what you can't
do *as
> easily* in Mercury.
Sorry, that's what I meant to say.
> One thing you can't do as easily in Mercury is write a simple text
file
> filter. For example, take a .html file containing cities and their
current
> weather observations as a big table, and extract and print out the
> information for a particular city. This is the kind of thing that's
pretty
> quick and easy to hack together in Perl.
>
> I think Mercury could be good at this sort of thing with the right
libraries.
> I don't really know what these libraries would be, but I'd like to
have
> them....
>
> Another thing Mercury is not as good at as Perl is rapid prototyping.
If
> you were writing a text processing application in a speed programming
> contest, would you choose Perl or Mercury? I'd take Perl every time.
I'm an Awk man myself, but either way Mercury is not a domain specific
language so I doubt we'd ever manage to be quite as concise as Awk/Perl
for programs below a page of code or two.
I've often thought I could use a sensible, simple text file munging
library. We probably have most of what we need already. The
following will turn a string (say, a line read in from a file) into
an array with the standard Awk form ($0 for the whole line, $1, $2 etc.
for the `words' in the line):
array([String | string__words(char__is_whitespace, String)])
A library with something like the following would give you the standard
Awk file processing mechanism:
process_file(P) -->
io__read_line_as_string(Result),
( { Result = error(_) }, ...
; { Result = eof }
; { Result = ok(Line),
{ Words = array([Line | string__words(...)]) },
P(Words),
process_file(P)
).
The extras/lex library could be used to write a standard regexp string
parser.
This probably wouldn't be too much work. The regexp string parser would
be non-trivial, but not too taxing.
I'm too busy right now, but I could knock something together in the near
future unless someone else beats me to it.
-- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list