chicken-hackers
[Top][All Lists]
Advanced

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

[Chicken-hackers] [PATCH] handle non-string argument in "assert"


From: Felix
Subject: [Chicken-hackers] [PATCH] handle non-string argument in "assert"
Date: Tue, 24 Apr 2012 12:40:16 +0200 (CEST)

The attached patch changes the "assert" macro to prepend the
line-number of the failed expression only if a literal string is given
as the second argument. A while ago Alaric submitted a different, more
general patch that checks at runtime whether a string is given. I
prefer this slightly more pragmatic solution, as it keeps the size
of the expansion small. 

Sorry for keeping this pending for so long.


cheers,
felix
>From 3f183c5c5ccc69c768835466cd5af8670c32661b Mon Sep 17 00:00:00 2001
From: felix <address@hidden>
Date: Tue, 24 Apr 2012 12:36:16 +0200
Subject: [PATCH] prepend line-number in error message generated by assert only 
if literal string is given

---
 chicken-syntax.scm |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/chicken-syntax.scm b/chicken-syntax.scm
index 2ea7072..968aab2 100644
--- a/chicken-syntax.scm
+++ b/chicken-syntax.scm
@@ -172,16 +172,11 @@
     (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"
-                       (let ((msg-str (car msg-and-args)))
-                         (##sys#check-string msg-str 'assert)
-                         msg-str)))
-            (msg (if ln
-                     (string-append "(" ln ") " msg)
-                     msg)))
+            (msg (optional msg-and-args "assertion failed")))
+       (when (string? msg)
+         (and-let* ((ln (get-line-number form)))
+           (set! msg (string-append "(" ln ") " msg))))
        `(##core#if (##core#check ,exp)
                    (##core#undefined)
                    (##sys#error 
-- 
1.6.0.4


reply via email to

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