Odd Behavior

2011-01-31 Thread Noah Lavine
Hello all,

I ran into an error message in Guile, and I'm not sure how to track
down the cause of it. I used a file called test.scm with the following
contents:

#!guile
!#

(define (codegen)
  #`(let ((message hello, world!\n))
  (display message)))

(define-syntax test
  (lambda (x)
(syntax-case x ()
  (_ (codegen)

(test)

Then I opened guile and did (load test.scm), and got this:

;;; compiling test.scm
;;; WARNING: compilation of test.scm failed:
;;; key wrong-type-arg, throw_args (#f Wrong type to apply: ~S (#f) (#f))
hello, world!

As far as I can tell, this means that Guile tried to compile test.scm,
failed, and then interpreted it correctly. Is that right? If so, is
there a way to get more information about where the wrong-type-arg
error was thrown?

I'd also love to know any way to get more information about errors
that happen during macroexpansion in general. I've been having quite a
bit of trouble figuring out what is going wrong at different points in
peg.scm, while I'm trying to convert it to syntax-case.

Thanks,
Noah



Re: Odd Behavior

2011-01-31 Thread Noah Lavine
Hello again,

I tried finding the error by running compile-file, but I got the
following Guile session:

scheme@(guile-user) (compile-file test.scm)
ice-9/boot-9.scm:119:21: Wrong type to apply: #f

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) ,bt
Nothing to debug.

boot-9.scm:119 is in the definition of custom-throw-handler, which is
part of the implementation of catch.

Noah

On Mon, Jan 31, 2011 at 1:44 PM, Noah Lavine noah.b.lav...@gmail.com wrote:
 Hello all,

 I ran into an error message in Guile, and I'm not sure how to track
 down the cause of it. I used a file called test.scm with the following
 contents:

 #!guile
 !#

 (define (codegen)
  #`(let ((message hello, world!\n))
      (display message)))

 (define-syntax test
  (lambda (x)
    (syntax-case x ()
      (_ (codegen)

 (test)

 Then I opened guile and did (load test.scm), and got this:

 ;;; compiling test.scm
 ;;; WARNING: compilation of test.scm failed:
 ;;; key wrong-type-arg, throw_args (#f Wrong type to apply: ~S (#f) (#f))
 hello, world!

 As far as I can tell, this means that Guile tried to compile test.scm,
 failed, and then interpreted it correctly. Is that right? If so, is
 there a way to get more information about where the wrong-type-arg
 error was thrown?

 I'd also love to know any way to get more information about errors
 that happen during macroexpansion in general. I've been having quite a
 bit of trouble figuring out what is going wrong at different points in
 peg.scm, while I'm trying to convert it to syntax-case.

 Thanks,
 Noah




Re: Odd Behavior

2011-01-31 Thread Andy Wingo
On Mon 31 Jan 2011 19:44, Noah Lavine noah.b.lav...@gmail.com writes:

 (define (codegen)
   #`(let ((message hello, world!\n))
   (display message)))

 (define-syntax test
   (lambda (x)
 (syntax-case x ()
   (_ (codegen)

 (test)

 Guile tried to compile test.scm, failed, and then interpreted it
 correctly. Is that right?

Yep; as mentioned in the NEWS entry, ** Functions needed by macros at
expand-time need to be present at expand-time.  I'm sure you know that
already, and your real question:

 is there a way to get more information about where the wrong-type-arg
 error was thrown?

There are several ways this could be improved:

  * The exception should be about an unbound variable, not about
applying #f.  I'll see what I can do there.

  * The exception could be printed with an appropriate printer.  See
http://thread.gmane.org/gmane.lisp.guile.devel/11066/focus=11158.

  * You should see the source location of the error and the containing
forms.

Probably that thread is the best bet for making a start at this.

Regards,

Andy
-- 
http://wingolog.org/



Re: Odd Behavior

2011-01-31 Thread Andy Wingo
On Mon 31 Jan 2011 19:44, Noah Lavine noah.b.lav...@gmail.com writes:

 ;;; compiling test.scm
 ;;; WARNING: compilation of test.scm failed:
 ;;; key wrong-type-arg, throw_args (#f Wrong type to apply: ~S (#f) (#f))
 hello, world!

Now it does:

scheme@(guile-user) (load /tmp/test.scm)
;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
;;;   or pass the --no-autocompile argument to disable.
;;; compiling /tmp/test.scm
;;; WARNING: compilation of /tmp/test.scm failed:
;;; key unbound-variable, throw_args (#f Unbound variable: ~S (codegen) 
#f)
hello, world!

Still ugly, but better.  Thanks for the example.

A
-- 
http://wingolog.org/



Re: Odd Behavior

2011-01-31 Thread Noah Lavine
Wow, great!

On Mon, Jan 31, 2011 at 3:12 PM, Andy Wingo wi...@pobox.com wrote:
 On Mon 31 Jan 2011 19:44, Noah Lavine noah.b.lav...@gmail.com writes:

 ;;; compiling test.scm
 ;;; WARNING: compilation of test.scm failed:
 ;;; key wrong-type-arg, throw_args (#f Wrong type to apply: ~S (#f) (#f))
 hello, world!

 Now it does:

    scheme@(guile-user) (load /tmp/test.scm)
    ;;; note: autocompilation is enabled, set GUILE_AUTO_COMPILE=0
    ;;;       or pass the --no-autocompile argument to disable.
    ;;; compiling /tmp/test.scm
    ;;; WARNING: compilation of /tmp/test.scm failed:
    ;;; key unbound-variable, throw_args (#f Unbound variable: ~S (codegen) 
 #f)
    hello, world!

 Still ugly, but better.  Thanks for the example.

 A
 --
 http://wingolog.org/