Thanks for your suggestion, Stuart, and yes, that's one obvious chice:
the AIML interpreter in question - Program D - is written in Java, so
why not just learn enough Java to fix the stack, and be done? In fact,
this was my first consideration.

However, that would be myopic. The reason I have this problem is that
the original AIML pattern matching algorithm is not suited for what I
want to do (conversations with lots of state, and lots of references
to past states to compute present and future output), so I changed it,
using the language itself. While it was fun and amazing to learn that
I could do this - from what I've read, this seems like a quite "lispy"
thing to do -, I have reason to suspect that it's very inefficient (I
do about 30-40 recursions and 10 topic/context switches on an average
input, simply because recursion and one contextual extension of the
match path is all I have to work with). So I know that I can't "fake
it" by somewhat modifying an existing program, and I'm up for a lot of
learning. My current questions are:

1. What would be a good way to learn about how to do matching and
string processing in Clojure?
2. Would it be better (or even possible) to learn about matching and
string processing in general, independent of the programming language?

I know about regex, but that's not enough: I need to learn about
"matching in context", where "context" means "more matching", or even
something like "explicit non-matches" (hope you can divine my meaning
here).

Dirk

On 6 Mai, 03:29, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> Hi Dirk, welcome to Clojure!
>
> I don't know much about Scala, but I know that Lisp-like languages
> have long been popular for this sort of language manipulation, so
> Clojure may be a good one to look at.
>
> Some caveats: Clojure does not have a direct equivalent to the pattern/
> template style of AIML.  Clojure also does not support the structural
> pattern-matching style found in some other functional languages like
> Haskell and ML.  Multimethods cannot dispatch on composite arguments
> like [* foo *], although this is an open research area.  On the other
> hand, Clojure has good support for regular expressions, which might be
> an adequate alternative for text processing.  Clojure does not support
> continuations natively, although Clojure code can still be written in
> a continuation-passing style.
>
> And don't forget Java!  There are implementations of AIML (and
> doubtless other pattern-matching libraries) in Java that you could use
> from Clojure.
>
> -Stuart Sierra
>
> On May 5, 12:16 pm, dhs827 <scheur...@gmail.com> wrote:
>
> > Hi,
>
> > my name is Dirk Scheuring, I'm a writer based in Cologne, Germany, and
> > I want to write something about AI that can only be expressed by using
> > AI technology and technique. You could say that what I aim for is a
> > chatbot, but it's a bot that works quiet different from the norm; at
> > it's core, there is a functional program, and on the fringe, there's
> > lots of state information.
>
> > I have a working prototype, written in AIML, the language in which the
> > famous Alicebot was written. Most bots written in AIML use a simple
> > stimulus-response conception of dialogue, without using (sequences of)
> > state, self-reflection, or other advanced concepts. So some people who
> > have only cursory knowledge of this language think that it's too
> > simple to be doing anything with that might be computationally
> > interesting. I know this to be false.
>
> > AIML is sort of a micro-version of a Lisp, with String being the only
> > type, and recursion over everything (powerful and dangerous). You can
> > write serious functions with it [1], but you have to abuse it. And I
> > heavily abused the language to make it do what I want. I managed to
> > build a prototype that does something interesting, but only does it
> > for like ten conversational strokes, because then the interpreter's
> > stack overflows, causing an infinite loop.
>
> > I need to implement my ideas in a different language - one that I
> > don't have to abuse to do complex stuff. I've looked at various
> > functional languages, and have now installed two, Scala and Clojure,
> > doing a couple tutorials at the respective REPLs. I have a hunch that
> > Clojure might turn out to be closer to what I already have in AIML,
> > but I'm not sure yet. Maybe you can help me decide.
>
> > AIML is an XML dialect; its most important construct is the <category/>, 
> > which has a <pattern/> and a <template/>. This is a default
>
> > <category/>, which matches any string:
>
> > <category>
> >   <pattern>*</pattern>
> >   <template>
> >     <srai>SOMEFUNCTION</srai>
> >   </template>
> > </category>
>
> > The <srai/> element in the <template/> means that I invoke the pattern
> > matcher recursivly to match SOMEFUNCTION. How can I express this in
> > Clojure?
>
> > The next primitive construction I need to translate is substitution:
>
> > <category>
> >   <pattern>* RAN *</pattern>
> >   <template>
> >     <srai><star index="1"/> RUNNING <star index="2"/></srai>
> >   </template>
> > </category>
>
> > This code matches the substring RAN in the middle of a set of other
> > substrings, and substitutes it for RUNNING, leaving the values before
> > and after it untouched for the next recursion. And I need to know how
> > to do:
>
> > <category>
> >   <pattern>* MADONNA *</pattern>
> >   <template>
> >     <think>
> >       <set name="celebrity">Madonna</set>
> >     </think>
> >     <srai><star index="1"/> <star index="2"/></srai>
> >   </template>
> > </category>
>
> > The above category "extracts" a substring from the input and saves it
> > to a (global) variable; the other substrings are up for another round
> > of pattern matching. Another important low-level one is:
>
> > <topic name="* MYTOPIC *">
> >   <category>
> >     <pattern>*</pattern>
> >     <template>
> >       <srai>SOMEOTHERFUNCTION</srai>
> >     </template>
> >   </category>
> > </topic>
>
> > This is again the catch-all <*> pattern, but in a context, represented
> > by the substring MYTOPIC in between these other substrings. So in this
> > case, the default <pattern/> has a <template/> that calls
> > SOMEOTHERFUNCTION. Is this something I would do with Multimethods in
> > Clojure?
>
> > There's lots more, but this is the primitive stuff that I need to
> > comprehend first. My model does what I call "semantic compression" -
> > it transforms and analytically stores (parts of) the input string -,
> > then finds a matching object which has methods to generate facts and
> > rules, the core of an output, which might then be extended front and
> > back, depending on what's in the input and what's in the current state
> > (that's "semantic expansion")...and finally, the first letter of the
> > output is cast to uppercase, a dot or bang or questionmark is put at
> > the end, and a special object writes the formated output (say, to a
> > webpage, or to an IRC channel). I know how to do this in AIML, at
> > least up to the point when the interpreter crashes, because I used the
> > language in a way it wasn't designed to be used (but it's valid AIML -
> > the spec allows some unmentioned things; plus it is functional, with
> > continuation-passing to boot). I want to learn how to do this in
> > Clojure, and appreciate any pointers and tips.
>
> > Best regards,
>
> > Dirk Scheuring
>
> > [1] Simple FP example in 
> > AIML:http://list.alicebot.org/pipermail/alicebot-style/2002-September/0002...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to