chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Usage of get-line-number


From: Felix
Subject: Re: [Chicken-users] Usage of get-line-number
Date: Wed, 14 Jul 2010 22:20:45 +0200 (CEST)

From: Christian Kellermann <address@hidden>
Subject: [Chicken-users] Usage of get-line-number
Date: Mon, 12 Jul 2010 15:27:54 +0200

> Hi Chickenistas,
> 
> Since I agree with Alejandro to the point that having more line
> information in assert is a nice thing to have I had a look at the
> code in chicken-syntax.scm.
> 
> Since assert is a macro that gets expanded it seems that macros
> don't get an entry in ##sys#line-number-database. Is that right?
> Also I could not come up with a usage case of (get-line-number EXP)
> that does return any number for me. How am I supposed to use that
> procedure?
> 
> I am sorry if I am  asking an obvious thing, it is too hot here to
> think...
> 

BTW, I have changed assert accordingly (experimental branch), see
attached patch.


cheers,
felix
diff --git a/chicken-syntax.scm b/chicken-syntax.scm
index 80a1fe6..088e117 100644
--- a/chicken-syntax.scm
+++ b/chicken-syntax.scm
@@ -149,20 +149,26 @@
 (##sys#extend-macro-environment
  'assert '()
  (##sys#er-transformer
-  (lambda (form r c)
-    (##sys#check-syntax 'assert form '#(_ 1))
-    (let* ((exp (cadr form))
-          (msg-and-args (cddr form))
-          (msg (if (eq? '() msg-and-args)
-                   `(##core#immutable '"assertion failed")
-                   (car msg-and-args) ) ) )
-      `(##core#if (##core#check ,exp)
-                 (##core#undefined)
-                 (##sys#error 
-                  ,msg 
-                  ,@(if (fx> (length msg-and-args) 1)
-                        (cdr msg-and-args)
-                        `((##core#quote ,(##sys#strip-syntax exp))))))))))
+  (let ((string-append string-append)
+       (get-line-number get-line-number))
+    (lambda (form r c)
+      (##sys#check-syntax 'assert form '#(_ 1))
+      (let* ((exp (cadr form))
+            (ln (get-line-number form))
+            (msg-and-args (cddr form))
+            (msg  (if (null? msg-and-args)
+                      "assertion failed"
+                      (car msg-and-args)))
+            (msg (if ln
+                     (string-append "(" ln ") " msg)
+                     msg)))
+       `(##core#if (##core#check ,exp)
+                   (##core#undefined)
+                   (##sys#error 
+                    ,msg 
+                    ,@(if (fx> (length msg-and-args) 1)
+                          (cdr msg-and-args)
+                          `((##core#quote ,(##sys#strip-syntax exp)))))))))))
 
 (##sys#extend-macro-environment
  'ensure

reply via email to

[Prev in Thread] Current Thread [Next in Thread]