Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Announce] CL-AWK (Common Lisp AWK library)

141 views
Skip to first unread message

Michael Parker

unread,
Feb 11, 2002, 9:52:26 PM2/11/02
to

I've written a text-processing library that I call CLAWK. It's a pretty
feature-complete implementation of AWK in common lisp, splits, matches,
etc, as well as a defawk macro that lets you write some awfully awk-ish
looking programs.

For example, here's the password-file-checker from "The AWK Programming
Language", in AWK.

BEGIN {
FS = ";" }
NF != 7 {
printf("line %d, does not have 7 fields: %s\n", NR, $0)}
$1 ~ /[^A-Za-z0-9]/ {
printf("line %d, nonalphanumeric user id: %s\n", NR, $0)}
$2 == "" {
printf("line %d, no password: %s\n", NR, $0)}
$3 ~ /[^0-9]/ {
printf("line %d, nonnumeric user id: %s\n", NR, $0)}
$4 ~ /[^0-9]/ {
printf("line %d, nonnumeric group id: %s\n", NR, $0)}
$6 !~ /^\// {
printf("line %d, invalid login directory: %s\n", NR, $0)}

And here's the same program written in CLAWK:

(defawk checkpass ()
(BEGIN
(setq *FS* ";"))
((/= *NF* 7)
(format t "~%line ~D, does not have 7 fields: ~S" *NR* $0))
((~ $1 #/[^A-Za-z0-9]/)
(format t "~%line ~D, nonalphanumeric user id: ~S" *NR* $0))
(($== $2 "")
(format t "~%line ~D, no password: ~S" *NR* $0))
((~ $3 #/[^0-9]/)
(format t "~%line ~D, nonnumeric user id: ~S" *NR* $0))
((~ $4 #/[^0-9]/)
(format t "~%line ~D, nonnumeric group id: ~S" *NR* $0))
((!~ $6 #/^\//)
(format t "~%line ~D, invalid login directory: ~S" *NR* $0)) )

The interesting thing about the library, from the CL point of view,
is probably the regex matcher, and the utility library that the AWK
stuff is built on, the match, split, scan, and such, since that's
all available without using the funky defawk macro.

I've been using it on my (sadly) AWK-free lispm, but I've tested it
and it works on clisp and Lispworks 4.2 as well.


at http://www.geocities.com/mparker762

Marco Antoniotti

unread,
Feb 12, 2002, 10:19:35 AM2/12/02
to

Thanks. It looks very good.

I have not checked the code thourougly yet. However, if you do not do
fancy READTABLE tricks, CLAWK will bomb in MCL, since that
implementation uses (or at least it did) #\$ for something pathname
related. This is why the INFIX package uses #I(..) instead of the TeXy $..$.

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488
719 Broadway 12th Floor fax +1 - 212 - 995 4122
New York, NY 10003, USA http://bioinformatics.cat.nyu.edu
"Hello New York! We'll do what we can!"
Bill Murray in `Ghostbusters'.

wis...@inetmi.com

unread,
Feb 17, 2002, 4:06:06 PM2/17/02
to
Marco Antoniotti <mar...@cs.nyu.edu> writes:

> I have not checked the code thourougly yet. However, if you do not
> do fancy READTABLE tricks, CLAWK will bomb in MCL, since that
> implementation uses (or at least it did) #\$ for something pathname
> related. This is why the INFIX package uses #I(..) instead of the
> TeXy $..$.

MCL has a readmacro #$, which is used to look up the equivalent of
foreign constants from a database.

Symbols that start with $ should be fine (though the #$ macro creates
symbols whose names start with $, they are all in the CCL package).


John Wiseman

Marco Antoniotti

unread,
Feb 19, 2002, 10:55:13 AM2/19/02
to

wis...@inetmi.com writes:

Oh well. I guess they must have changed that.

0 new messages