unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* puzzling things
@ 2003-08-06 22:12 Andy Wingo
  2003-08-07 15:18 ` Paul Jarc
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Wingo @ 2003-08-06 22:12 UTC (permalink / raw)


Hey gang,

Why doesn't the following code work?

(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)

What's that all about? I poked around in the source but got lost in a
bunch of ilocs and glocs. What's an iloc anyway? Well. The first
question is the important one. Any insights?

regards,

wingo.


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: puzzling things
  2003-08-06 22:12 puzzling things Andy Wingo
@ 2003-08-07 15:18 ` Paul Jarc
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Jarc @ 2003-08-07 15:18 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-07 15:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-06 22:12 puzzling things Andy Wingo
2003-08-07 15:18 ` Paul Jarc

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).