From: prj@po.cwru.edu (Paul Jarc)
Subject: Re: puzzling things
Date: Thu, 07 Aug 2003 11:18:41 -0400 [thread overview]
Message-ID: <m3ekzxsdg8.fsf@multivac.cwru.edu> (raw)
In-Reply-To: <20030806221246.GA16455@lark>
Andy Wingo <wingo@pobox.com> 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 (#@second-arg 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: (#@second-arg 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
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
prev parent reply other threads:[~2003-08-07 15:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-06 22:12 puzzling things Andy Wingo
2003-08-07 15:18 ` Paul Jarc [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3ekzxsdg8.fsf@multivac.cwru.edu \
--to=prj@po.cwru.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).