[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: puzzling things
From: |
Paul Jarc |
Subject: |
Re: puzzling things |
Date: |
Thu, 07 Aug 2003 11:18:41 -0400 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) |
Andy Wingo <address@hidden> wrote:
> (define second-arg
> (procedure->syntax
> (lambda (x y) (cadr x))))
>
> ((lambda () (second-arg a b c d)))
>
> I get some kind of error like this:
>
> 18: 2* [cadr (address@hidden a b c d)]
>
> <unnamed port>:18:18: In procedure cadr in expression (cadr x):
> <unnamed port>:18:18: Wrong type argument in position 1: (address@hidden a b
> c d)
- Scheme Procedure: procedure->syntax code
- C Function: scm_makacro (code)
Return a macro which, when a symbol defined to this value appears
as the first symbol in an expression, returns the result of
applying CODE to the expression and the environment.
So when your macro is called, the first argument is the whole macro
expression, and the second is the local environment.
guile> (define foo
... (procedure->syntax
... (lambda args
... (format #t "~S\n" args)
... #f)))
guile> (foo a b c)
((foo a b c) (#<eval-closure 40255ea0>))
#f
guile> (define foo (procedure->syntax (lambda (expr env) (caddr expr))))
guile> (foo a b c)
b
guile> (define foo (procedure->macro (lambda (expr env) (caddr expr))))
guile> (foo a b c)
Backtrace:
In current input:
10: 0* (foo a b c)
?: 1 b
<unnamed port>: In expression b:
<unnamed port>: Unbound variable: b
ABORT: (unbound-variable)
guile> (define b 3)
guile> (foo a b c)
3
guile> (define-macro (foo . args) (cadr args))
guile> (foo a b c)
3
paul