Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#487 closed defect (fixed)

matchable: crash matching a symbol when a production contains |...|

Reported by: Alan Post Owned by:
Priority: major Milestone: 4.9.0
Component: extensions Version: 4.6.x
Keywords: Cc:
Estimated difficulty:

Description

The following program:

(use matchable)

(pretty-print (map
  (match-lambda
    ((x ... y) `(,x ,y))
    (x         x))
  '((a c) (a b c) (a b b c) (a) (c) a)))
(exit)

Generates the following error message:

Error: (length) bad argument type - not a proper list: a

        Call history:

        <eval>    (#%= n109 tail-len102)
        <eval>    (#%reverse p-ls56)
        <eval>    (#%pair? ls104)
        <eval>    (#%null? (#%cdr ls104))
        <eval>    (#%cdr ls104)
        <eval>    (#%car ls104)
        <eval>    (##sys#cons x (##sys#cons y (##core#quote ())))
        <eval>    (##sys#cons y (##core#quote ()))
        <eval>    (#%length (quote103 (y)))
        <eval>    (#%length ls104)      <--

I would expect the output of the program to instead be:

(((a) c) ((a b) c) ((a b b) c) (() a) (() c) a)

The error message is being generated by the final element in the map, the symbol |a|. It seems to be a caused by the |...| operator in matchable.

With the following variation (substituted a single |.| for the |...|):

(use matchable)

(pretty-print (map
  (match-lambda
    ((x . y) `(,x ,y))
    (x         x))
  '((a c) (a b c) (a b b c) (a) (c) a)))
(exit)

The program does not generate the error message. It does generate a slightly different result, of course:

((a (c)) (a (b c)) (a (b b c)) (a ()) (c ()) a)

I'm running Chicken experimental de033aef6860a4b76d388810e73d3927fd553e95 on OpenBSD 4.8 in a VMWare virtual machine.

Change History (5)

comment:1 Changed 13 years ago by felix winkelmann

I don't think this is a bug, to be honest. The pattern (x ... y) is not legal in matchable, AFAIK. In fact, `a' shouldn't match at all, since it is not a list, not even a pair.

comment:2 in reply to:  1 Changed 13 years ago by Alan Post

Replying to felix:

I don't think this is a bug, to be honest. The pattern (x ... y) is not legal in matchable, AFAIK. In fact, `a' shouldn't match at all, since it is not a list, not even a pair.

That is the only way I know for matchable to match the end of a list. How do you make matchable match "a list ending in x, y, and z"? It seems like the ... operator is doing just that, and it that isn't legal what does one use instead?

comment:3 Changed 13 years ago by Alex Shinn

Resolution: fixed
Status: newclosed

Fixed.

comment:4 Changed 13 years ago by felix winkelmann

Milestone: 4.7.04.8.0

Milestone 4.7.0 deleted

comment:5 Changed 12 years ago by felix winkelmann

Milestone: 4.8.04.9.0

Milestone 4.8.0 deleted

Note: See TracTickets for help on using tickets.