Location information is not preserved by "define-macro" type macros because the macro transformer is given, and gives back, a plain s- expression which has been stripped of the location information. To preserve the location information, either use a syntax-case macro transformer or use the (undocumented) ##define-syntax form (there are a couple of examples of this in the Gambit library source code... basically the macro transformer receives an s-expression which is decorated with location information).
Here's a simple example of ##define-syntax:
% gsi Gambit v4.5.2
(##define-syntax flip
(lambda (sexpr) `(list ,(caddr (##source-code sexpr)) ,(cadr (##source-code sexpr)))))
(flip (+ 1 2) (+ 3 4))
(7 3)
(flip (begin
1 2 3 4 (/ 1 0) 5) "hello") *** ERROR IN (console)@11.1 -- Divide by zero (/ 1 0) 1>
Marc
On 2009-10-15, at 9:42 PM, lowly coder wrote:
take a look at:
cat test.scm; gsi test.scm (define-macro (for var start end . body) `(do ((,var ,start (+ ,var 1))) ((= ,var ,end)) ,@body))
(for i 0 2 (display i) (newline))
(for i 0 2 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing (/ i a) 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing 'this-line-does-nothing )
0 1 *** ERROR IN #<procedure #2>, "test.scm"@12.1 -- Unbound variable: a
ignore the fact taht ,end is evaluated twice:
note that the error is on line "12", which is the (for i 0 2 line ... not the (/ i a) line; i can understand that since the macro expansion happens before the code is run, the entire 'chunk' gets grouped to the line where the macro is expanded at
however, is there anyway I can have the "LINE_NUMBER" information passed along with define-macro?
thanks! _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list