This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem using #!rest in defmacro


Are Meisfjord wrote:
C:\>java kawa.repl
#|kawa:1|# (defmacro foo (#!rest bar) `(list ,@bar))
#|kawa:2|# (foo 1 2 3)
<stdin>:2:2: no matching case while expanding foo

I am new to Scheme but the corresponding statement in Common Lisp
(using &rest instead of #!rest) works fine. Am I missing something?

When using lambda in scheme, you can pick up the 'rest arguments' with the tail of a dotted list.

So, the formal arguments to a lambda can (only) be one of:
* a list of variables -- (foo bar baz)
* a variable -- foo
* a dotted list -- (foo bar . baz)

In the first case, each of the arguments is bound with the corresponding calling operand, and if the numbers of arguments and operands don't match, there is an error.

In the second case the (single) argument is bound to a list containing all the parameters.

In the third case all the arguments before the '.' are treated as in the first case, and the remaining (single) argument is treated as in the second case.

So...

(defmacro foo bar `(list ,@bar))

- jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]