#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 follow-up: 2 Changed 14 years ago by
comment:2 Changed 14 years ago by
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?
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.