From: Philip Haddad
Subject: pregexp vs. read
Date: 
Message-ID: <ba57c4f9.0410191244.60b5af51@posting.google.com>
Hello all
I recently downloaded the Pregexp library, which is based off of Perl
regex's, and I was wondering if it is indeed more powerful than Lisp's
built-in IO functions such as read or with-open-file, etc. The idea
for me is to be able to pick out "key phrases" from input and base the
program's output on that "key" input. Also would Pregexp be faster
than read? Just thought I'd ask since Pregexp is documentated
informally, and I am as of yet not to familer with some of the Lisp IO
functions.

-- 
Certum quod factum.
Philip Haddad

From: Matthew Danish
Subject: Re: pregexp vs. read
Date: 
Message-ID: <87y8i2wg54.fsf@mapcar.org>
·············@gmail.com (Philip Haddad) writes:
> I recently downloaded the Pregexp library, which is based off of Perl
> regex's, and I was wondering if it is indeed more powerful than Lisp's
> built-in IO functions such as read or with-open-file, etc. The idea
> for me is to be able to pick out "key phrases" from input and base the
> program's output on that "key" input. Also would Pregexp be faster
> than read? Just thought I'd ask since Pregexp is documentated
> informally, and I am as of yet not to familer with some of the Lisp IO
> functions.

Well, I don't know about Pregexp in particular, but I do know about
Edi's CL-PPCRE (similar idea).  What you are asking is a bit confused
because all these operators are for different purposes.

WITH-OPEN-FILE -- open file for stream operations, close it when done
READ -- Parse Lisp expressions from a stream
READ-CHAR -- Read a single character from a stream
READ-LINE -- Read a single line from a stream
READ-BYTE -- Read a single byte from a binary stream
READ-SEQUENCE -- Read a block of data into a sequence from a stream
...

As you can imagine, READ is a much higher-level operator than the
others, because it performs recursive-descent parsing based on a
read-table.  I would call it a higher-level operator than a regular
expression matcher, but more constrained in many ways, because it has
a very specific purpose: parse Lisp.

Regular expression libraries are good at matching.  If that's what you
need, go for it.  If you need a parser, READ might do; or not, since
it can only parse a limited subset of grammars.  Otherwise you should
start looking into things like Zebu which offers an LALR
parser-generator.

-- 
;; Matthew Danish -- user: mrd domain: cmu.edu
;; OpenPGP public key: C24B6010 on keyring.debian.org
From: Philip Haddad
Subject: Re: pregexp vs. read
Date: 
Message-ID: <ba57c4f9.0410201348.6a13a66f@posting.google.com>
Matthew Danish <··········@cmu.edu> wrote in message news:<··············@mapcar.org>...
> ·············@gmail.com (Philip Haddad) writes:
> Well, I don't know about Pregexp in particular, but I do know about
> Edi's CL-PPCRE (similar idea).  What you are asking is a bit confused
> because all these operators are for different purposes.
> 
> WITH-OPEN-FILE -- open file for stream operations, close it when done
> READ -- Parse Lisp expressions from a stream
> READ-CHAR -- Read a single character from a stream
> READ-LINE -- Read a single line from a stream
> READ-BYTE -- Read a single byte from a binary stream
> READ-SEQUENCE -- Read a block of data into a sequence from a stream
> ...
> 
> As you can imagine, READ is a much higher-level operator than the
> others, because it performs recursive-descent parsing based on a
> read-table.  I would call it a higher-level operator than a regular
> expression matcher, but more constrained in many ways, because it has
> a very specific purpose: parse Lisp.
> 
> Regular expression libraries are good at matching.  If that's what you
> need, go for it.  If you need a parser, READ might do; or not, since
> it can only parse a limited subset of grammars.  Otherwise you should
> start looking into things like Zebu which offers an LALR
> parser-generator.

Well, I guess I won't use READ then. I didn't realize that it was a
compelte parser for Lisp code... interesting. What I need to do is get
patterns from a stream of input and base output on the input. This is
for a IRC bot I have started to work on. I will be using cl-irc for
irc bindings and so forth. The goal of the bot is for it to carry on
fairly decent converations with its user. Since the user won't be
inputing strings of Lisp code (usually ;-)), I don't see now why I
should use builtin functions like read. I may use something like
with-open-file to get the stream open faster though... would that
work? Than I might as well use something like Edi's library or
Pregexp.

-- 
Certum quod factum.
Philip Haddad
From: Matthew Danish
Subject: Re: pregexp vs. read
Date: 
Message-ID: <87hdopvwdy.fsf@mapcar.org>
·············@gmail.com (Philip Haddad) writes:
> The goal of the bot is for it to carry on fairly decent converations
> with its user. Since the user won't be inputing strings of Lisp code
> (usually ;-)), I don't see now why I should use builtin functions
> like read. I may use something like with-open-file to get the stream
> open faster though... would that work? Than I might as well use
> something like Edi's library or Pregexp.

Well, you would use WITH-OPEN-FILE if you had to open files, which
this doesn't sound like.  Socket libraries usually provide a stream
interface.  But the regular expressions will probably help you
construct a parser for natural language, at least the simple parts.

-- 
;; Matthew Danish -- user: mrd domain: cmu.edu
;; OpenPGP public key: C24B6010 on keyring.debian.org
From: Jeff
Subject: Re: pregexp vs. read
Date: 
Message-ID: <ceCdd.293561$3l3.132710@attbi_s03>
Philip Haddad wrote:

> Matthew Danish <··········@cmu.edu> wrote in message
> news:<··············@mapcar.org>...
> > ·············@gmail.com (Philip Haddad) writes:
> >
> > Regular expression libraries are good at matching.  If that's what
> > you need, go for it.  If you need a parser, READ might do; or not,
> > since it can only parse a limited subset of grammars.  Otherwise
> > you should start looking into things like Zebu which offers an LALR
> > parser-generator.
> 
> What I need to do is get patterns from a stream of input and base
> output on the input. This is for a IRC bot I have started to work
> on....

Like an IRC version of Eliza? ;)

Perhaps my regular expression parser (if that's what you decide to use)
might be of help to you. It doesn't have /everything/ that others do,
but it does hit 90%+ of all regular expressions, and is only a few
hundred lines of code -- all self-contained. I use it for program
parsing, so I have a built in macro FLEX that builds a function for
parsing a text string. For example:

(setq token-parser 
  (regex:flex
    (#/\a[_\w]*/  (read-from-string $0))
    (#/\d+/       (parse-integer $0))
    (#/0x(\x+)/   (parse-integer $1 :radix 16))
    (#/'([^']*)'/ $1)
    (#/=/         :assign)
    (#/\s+/       nil)))

(funcall token-parser "foo_bar=0x1234abcd  12  'Hello, world!'")
 ==> (FOO_BAR :ASSIGN 305441741 12 "Hello, world!")
     T

Not sure if that would be beneficial to your end goal as much as coming
up with a different method of parsing, but if you think it would be,
drop me an email.

-- 
`(:mail-to ,(concatenate 'string (symbol-name 'massung) 
                                 (string (code-char 64)) 
                                 (string-upcase "gmail.com")))
From: Rahul Jain
Subject: Re: pregexp vs. read
Date: 
Message-ID: <87is96tmoq.fsf@nyct.net>
·············@gmail.com (Philip Haddad) writes:

> Hello all
> I recently downloaded the Pregexp library, which is based off of Perl
> regex's, and I was wondering if it is indeed more powerful than Lisp's
> built-in IO functions such as read or with-open-file, etc. The idea
> for me is to be able to pick out "key phrases" from input and base the
> program's output on that "key" input. Also would Pregexp be faster
> than read? Just thought I'd ask since Pregexp is documentated
> informally, and I am as of yet not to familer with some of the Lisp IO
> functions.

READ is not an IO function. It is an extensible parser for Lisp code. If
you want perl regex (my condolences), you can use CL-PPCRE, which is an
implementation of perl's regex, but faster. If you want something that
can be used for real parsing without causing severe mental anguish,
please indicate what kind of syntax you have in mind. I'm not sure how
you can compare opening a file for IO to parsing a stream using regex,
tho... but WITH-OPEN-FILE is more powerful than any similar construct in
any other language that I've seen.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Philip Haddad
Subject: Re: pregexp vs. read
Date: 
Message-ID: <ba57c4f9.0410201351.6fbbe983@posting.google.com>
> If
> you want perl regex (my condolences), you can use CL-PPCRE, which is an
> implementation of perl's regex, but faster. If you want something that
> can be used for real parsing without causing severe mental anguish,

What's so anguishing about Perl regexs'? I've used them for a few
years, and I like them. Is there some speed issue with them? Or do you
prefer a different syntax?

-- 
Certum quod factum.
Philip Haddad
From: Rahul Jain
Subject: Re: pregexp vs. read
Date: 
Message-ID: <874qkolnq6.fsf@nyct.net>
·············@gmail.com (Philip Haddad) writes:

>> If
>> you want perl regex (my condolences), you can use CL-PPCRE, which is an
>> implementation of perl's regex, but faster. If you want something that
>> can be used for real parsing without causing severe mental anguish,
>
> What's so anguishing about Perl regexs'? I've used them for a few
> years, and I like them. Is there some speed issue with them? Or do you
> prefer a different syntax?

I prefer something more powerful and organized. It's like the difference
between machine code and structured programming. Even if all you needed
were regular expressions (along with all the crap needed to make them
applicable to parsing), Something that just _looked_ more like BNF would
lead to less write-only coding.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Edi Weitz
Subject: Re: pregexp vs. read
Date: 
Message-ID: <u3c09dnjf.fsf@agharta.de>
On 20 Oct 2004 14:51:08 -0700, ·············@gmail.com (Philip Haddad) wrote:

> What's so anguishing about Perl regexs'? I've used them for a few
> years, and I like them. Is there some speed issue with them? Or do
> you prefer a different syntax?

The problem is: "If all you have is a hammer, everything starts to
look like a nail." People coming from a Perl background tend to think
that every problem can and should be attacked with regular
expressions. That's wrong. Regular expressions are fine for a certain
area but that's about it. Also, complicated regular expressions are
very hard to read, understand, maintain, and debug.

Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")