chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATCH] Allow assert to accept an arbitrary expres


From: Felix
Subject: Re: [Chicken-hackers] [PATCH] Allow assert to accept an arbitrary expression as the message
Date: Fri, 16 Mar 2012 08:37:23 +0100 (CET)

From: Alaric Snell-Pym <address@hidden>
Subject: Re: [Chicken-hackers] [PATCH] Allow assert to accept an arbitrary 
expression as the message
Date: Mon, 12 Mar 2012 16:39:10 +0000

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 03/12/2012 02:03 PM, Felix wrote:
> 
>>> Tell you what, shall I make it say (if (string? msg) msg "<no valid
>>> assertion message was supplied>") or something like that? I'll think of
>>> better wording.
>>
>> At run-time (I'd not recommend this, as it produces more code than necessary)
>> or at expansion time? The latter is ok, I guess.
> 
> Ah, but my whole goal was to allow one to put an arbitrary expression in
> "msg" and have it evaluated at run-time if the assertion fails. In
> Ugarit, I've written things like (excuse wrapping):
> 
> (assert (or (eq? type leaf-type) (eq? type ks-type))
>         (sprintf
>    "unlink-sexpr-stream!: Invalid block type (expected ~a)"
>        (list leaf-type ks-type)) type)
> 
> I use sprintf to make up a more meaningful assertion failure message!
> 
> Ok, how about we ditch the checks at all, but still allow expressions in
> the message position.
> 
> Attached is a patch that produces the following behaviour in csi:
> 
> #;3> ,x (assert some-expression (sprintf "Some expression has failed")
> foo bar baz)
> (##core#if
>   (##core#check some-expression)
>   (##core#undefined)
>   (##sys#error (sprintf "Some expression has failed") foo bar baz))
> 
> 
> ...and if I fudge in a fake get-line-number:
> 
> #;6> ,x (assert some-expression (sprintf "Some expression has failed")
> foo bar baz)
> (##core#if
>   (##core#check some-expression)
>   (##core#undefined)
>   (##sys#error
>     (string-append "(foo.scm:1) " (sprintf "Some expression has failed"))
>     foo
>     bar
>     baz))
> 
> Does that make you happy?

Sorry, no. If the "msg" argument is not a string, there will be an
error message that will only confuse the user.  I'll try to come up
with something else.


cheers,
felix



reply via email to

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