guile-devel
[Top][All Lists]
Advanced

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

Pattern matching


From: Ludovic Courtès
Subject: Pattern matching
Date: Tue, 13 Apr 2010 18:22:59 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Hi,

[Cc: guile-devel.]

Stefan <address@hidden> writes:

> On Apr 13, 2010, at 1:55 PM, Ludovic Courtès wrote:

>> stefan <address@hidden> writes:

[...]

> Actually I have some experience in coding unification. Done a version
> for SBCL that is similar to the one suggested that clocks 10x faster
> and on par with gprolog for the coded example.

Heh, SBCL compiles to well-optimized native code.  We’re not there yet,
for sure.

> So this is what I have tried. I defined some hotspot elements in C,
> and coded the logic in scheme. So in a sense I have tried to do what
> you suggest. You could code prolog with these elements if you like and
> 99% of the code would be scheme. But I did not code a full version in
> scheme just to see how it compares, I'll chew on that,

OK, you know what you’re doing very well so you may well be taking the
right approach.  :-)

> I'll very much like to code using pattern matching techniques, I'll
> notice there are some similar tools in your bag here. Can I have a
> short intro intro the possibilities?

In terms of pattern matching, Guile has (ice-9 match), a classical
pattern matcher for Scheme by Andrew K. Wright, and pmatch by Oleg
Kiselyov et al.  These work well but have limitations, such as the fact
that they don’t work on records; well, in theory (ice-9 match) does work
on records but in practice that doesn’t work, notably because it wants
you to use its own record infrastructure.

Because of that the compiler uses its own macro, ‘record-case’, to match
records that are used to represent elements of the various intermediate
languages.  However, it’s pretty limited in that it doesn’t allow you to
match nested elements.  And it doesn’t match types other than records.

So if you’re in pattern matching, you could look into extending, say,
(ice-9 match) to support pattern matching on SRFI-9 records.  It should
be doable since ‘define-structure’ in (ice-9 match) is a syntactic
record API, similar in spirit to SRFI-9.  (There’s a 1995 paper called
“Pattern Matching for Scheme” by Wright et al.)

What do you think?

Thanks,
Ludo’.




reply via email to

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