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: Alaric Snell-Pym
Subject: Re: [Chicken-hackers] [PATCH] Allow assert to accept an arbitrary expression as the message
Date: Mon, 12 Mar 2012 16:39:10 +0000
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11

-----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?

>
> cheers,
> felix
>

ABS

- --
Alaric Snell-Pym
http://www.snell-pym.org.uk/alaric/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9eJq4ACgkQRgz/WHNxCGrFugCggRidwCXfiohizwhAGTIaWwOC
WSMAmQGI5fQ5r1oeoPlQ4xoxZ6jYIaw6
=+9p/
-----END PGP SIGNATURE-----

Attachment: 0001-Rather-than-requiring-assert-s-message-to-statically.patch
Description: Text Data


reply via email to

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