Search code examples
functionmodulevariadic-functionschicken-scheme

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


Is this a bug in 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)     <--

Solution

  • The dot (.) syntax for variadic functions is not available across modules; it's inside the scheme module. When you create a custom module, you have to explicitly import the scheme module to reenable variadic functions.

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