1

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

这是解释器中的一个示例:

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)       <--

我错过了什么?

4

1 回答 1

3

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

只需在解释器中做同样的事情:(use matchable)而不是(declare (uses matchable)).

于 2016-05-25T11:35:47.967 回答