guile-devel
[Top][All Lists]
Advanced

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

Re: Inconsistent behaviour of the pattern matcher


From: Mark H Weaver
Subject: Re: Inconsistent behaviour of the pattern matcher
Date: Sun, 28 Apr 2013 08:51:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Panicz Maciej Godek <address@hidden> writes:

> I've traced something that is not entirely a bug, but which was a
> little surprise for me. It has to do with the extensions that guile
> provides to the Scheme language -- namely, uniform vectors and arrays.
>
> The (ice-9 match) module offers the syntax
> (match #(1 2 3)
> (#(a b c)
> (list a b c)))
> ;===> (1 2 3)
>
> However, none of the following behaves as one could expect:
> (match #u8(1 2 3)
> (#u8(a b c)
> (list a b c)))

This can't work because a uniform numeric vector cannot hold symbols, so
#u8(a b c) cannot be represented in the source code.

> (match #2((1 2)(3 4))
> (#2((a b)(c d))
> (list a b c d)))

This could be made to work, but has not been implemented.

> (match #u8(1 2 3); this is perhaps questionable, but
> (#(a b c) ; i add it for a discussion
> (list a b c))) 

This should not work, IMO, because uniform numeric vectors are a
distinct type from normal vectors, and making the normal vector
accessors work with the other vector-like types would necessarily make
them much slower when we have native code generation.

If you want generic accessors, I guess the array accessors are what you
want.  Patches to extend the pattern matcher to handle arrays are
welcome :)

> After looking into the source of the pattern matcher, I've found out
> that the problem is probably situated deeper: while it is possible to
> define macros with regular vectors, like that:
>
> (define-syntax nv
> (syntax-rules ()
> ((nv #(v ...))
> (list v ...))))
>
> it doesn't work if we replace the #(v ...) with #u8(v ...), for
> instance.

Again, a #u8 vector cannot hold symbols, so this cannot work.

     Regards,
       Mark



reply via email to

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