简体   繁体   English

您如何在Chicken Scheme模块中定义可变函数?

[英]How do you define a variadic function in a Chicken Scheme module?

Is this a bug in Chicken Scheme? 这是Chicken Scheme中的错误吗?

#;1> (define (foo x . y) x)
#;2> (foo 1 2 3)
1
#;3> (module bar (import scheme chicken) (define (foo x . y) x))

Error: invalid syntax in macro form: (foo x . y)

        Call history:

        <syntax>                (module bar (import scheme chicken) (define (foo x . y) x))
        <syntax>                (##core#module bar (import scheme chicken) (define (foo x . y) x))
        <syntax>                (define (foo x . y) x)
        <syntax>                (foo x . y)     <--

Your module syntax is missing the list of symbols to export from the module. 您的模块语法缺少要从模块导出的符号列表。 Try this: 尝试这个:

#1;> (module bar (foo) (import scheme chicken) (define (foo x . y) x))
#2;> (import bar)
#3;> (foo 1 2 3)
1

Notice the (foo) after declaring the module name. 声明模块名称后,请注意(foo)。

I'll add that the mailing list and irc channel (#chicken on freenode) are very active. 我将添加邮件列表和irc频道(在freenode上的#chicken)非常活跃。 If you have questions about chicken they are the best places to get them answered. 如果您对鸡肉有疑问,那么它们是回答它们的最佳场所。

The dot ( . ) syntax for variadic functions is not available across modules; 可变参数函数的点( . )语法在模块之间不可用; it's inside the scheme module. 它在scheme模块中。 When you create a custom module, you have to explicitly import the scheme module to reenable variadic functions. 创建自定义模块时,必须显式导入scheme模块以重新启用可变参数功能。

#1;> (module bar (foo) (import scheme chicken) (define (foo x . y) x))
#2;> (import bar)
#3;> (foo 1 2 3)
1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM