Chicken编译器中的模式匹配编译错误,但鸡解释器中没有

时间:2016-05-25 10:41:19

标签: scheme chicken-scheme

我试图让模式匹配工作,但我只能在Chicken解释器中使用它 - 而不是编译器。

以下是解释器中的示例:

CHICKEN
(c) 2008-2015, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.10.0 (rev b259631)
freebsd-unix-clang-x86-64 [ 64bit manyargs dload ptables ]
compiled 2015-08-04 on yves.more-magic.net (Linux)

#;1> (use matchable)
; loading /usr/local/lib/chicken/7/matchable.import.so ...
; loading /usr/local/lib/chicken/7/chicken.import.so ...
; loading /usr/local/lib/chicken/7/lolevel.import.so ...
; loading /usr/local/lib/chicken/7/matchable.so ...
#;2> (match '((1 2) (3 4)) [(a . b) b] [() 0])
((3 4))
#;3>

以下是编译版本:

(declare (uses matchable))

(match '((1 2) (3 4))
       [(a . b) b]
       [() 0])

失败(csc src/test.scm):

Syntax error: (src/test.scm:4) - malformed expression: (a . b)
inside expression `(match ...)'


Expansion history:

<syntax>          (##core#begin (match (quote ((1 2) (3 4))) ((a . b) b) (() 0)))
<syntax>          (match (quote ((1 2) (3 4))) ((a . b) b) (() 0))
<syntax>          (quote ((1 2) (3 4)))
<syntax>          (##core#quote ((1 2) (3 4)))
<syntax>          ((a . b) b)
<syntax>          (##core#let ((g0 (a . b))) (g0 b))
<syntax>          (a . b)       <--

我错过了什么?

1 个答案:

答案 0 :(得分:3)

您需要在编译时加载导入库。 declare语句只是说它在运行时依赖于matchable

只需在解释器中执行相同操作:(use matchable)而不是(declare (uses matchable))