* assert()ing in elisp
@ 2006-06-29 10:05 lalit mohan tripathi
2006-06-29 13:14 ` Kevin Rodgers
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: lalit mohan tripathi @ 2006-06-29 10:05 UTC (permalink / raw)
[-- Attachment #1.1: Type: text/plain, Size: 124 bytes --]
Hi Everyone,
I was wondering how I could write assert(condition) in elisp code, as I
can do in C by including assert.h?
[-- Attachment #1.2: Type: text/html, Size: 146 bytes --]
[-- Attachment #2: Type: text/plain, Size: 152 bytes --]
_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: assert()ing in elisp
2006-06-29 10:05 assert()ing in elisp lalit mohan tripathi
@ 2006-06-29 13:14 ` Kevin Rodgers
2006-06-29 13:26 ` Eric Hanchrow
[not found] ` <mailman.3510.1151588330.9609.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2006-06-29 13:14 UTC (permalink / raw)
lalit mohan tripathi wrote:
> I was wondering how I could write assert(condition) in elisp code, as
> I can do in C by including assert.h?
(require 'cl)
(assert CONDITION)
--
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: assert()ing in elisp
2006-06-29 10:05 assert()ing in elisp lalit mohan tripathi
2006-06-29 13:14 ` Kevin Rodgers
@ 2006-06-29 13:26 ` Eric Hanchrow
[not found] ` <mailman.3510.1151588330.9609.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 4+ messages in thread
From: Eric Hanchrow @ 2006-06-29 13:26 UTC (permalink / raw)
Here's one example:
(defun assert= (expected actual)
(when (not (string-equal expected actual))
(error "expected %S; got %S" expected actual)))
--
There is such a thing as American-ness. ... [H]ackers ... come
closest of any group I know to embodying it. Closer, probably, than
the men running our government.
-- Paul Graham
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: assert()ing in elisp
[not found] ` <mailman.3510.1151588330.9609.help-gnu-emacs@gnu.org>
@ 2006-06-29 17:12 ` Giorgos Keramidas
0 siblings, 0 replies; 4+ messages in thread
From: Giorgos Keramidas @ 2006-06-29 17:12 UTC (permalink / raw)
On Thu, 29 Jun 2006 06:26:09 -0700, Eric Hanchrow <offby1@blarg.net> wrote:
> Here's one example:
> (defun assert= (expected actual)
> (when (not (string-equal expected actual))
> (error "expected %S; got %S" expected actual)))
Or you could use a macro, which can print the assertion
that failed too:
,----------------------------------------------------------------
| (defmacro assert (test-form)
| `(when (not ,test-form)
| (error "Assertion failed: %s" (format "%s" ',test-form))))
|
| (assert (equal t nil))
| =>
| Debugger entered--Lisp error: (error "Assertion failed: (equal t nil)")
| signal(error ("Assertion failed: (equal t nil)"))
| error("Assertion failed: %s" "(equal t nil)")
| (progn (error "Assertion failed: %s" (format "%s" ...)))
| (if (not (equal t nil)) (progn (error "Assertion failed: %s" ...)))
| (when (not (equal t nil)) (error "Assertion failed: %s" (format "%s" ...)))
| (assert (equal t nil))
| eval((assert (equal t nil)))
| eval-last-sexp-1(nil)
| eval-last-sexp(nil)
| call-interactively(eval-last-sexp)
`----------------------------------------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-06-29 17:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-29 10:05 assert()ing in elisp lalit mohan tripathi
2006-06-29 13:14 ` Kevin Rodgers
2006-06-29 13:26 ` Eric Hanchrow
[not found] ` <mailman.3510.1151588330.9609.help-gnu-emacs@gnu.org>
2006-06-29 17:12 ` Giorgos Keramidas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).