picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

commit 457b039b10ca2c830ad49fbd36a39b04b3127553
parent cbbed865e1fe454a4ddc3dcb7aacd1cd22c5eb3c
Author: Commit-Bot <unknown>
Date:   Fri, 18 Jun 2010 16:29:36 +0000

Automatic commit from picoLisp.tgz, From: Fri, 18 Jun 2010 16:29:36 GMT
Diffstat:
MCHANGES | 1+
Mdoc/ref.html | 1+
Mdoc/refA.html | 39+++++++++++++++++++++++++++++++++++++++
Mdoc/refT.html | 3++-
Mlib/misc.l | 8+++++++-
Msrc64/version.l | 2+-
6 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES @@ -1,4 +1,5 @@ * XXjun10 picoLisp-3.0.3 + 'assert' function 'round' function 'co', 'yield' and 'stack' coroutine functions 'sigio' function diff --git a/doc/ref.html b/doc/ref.html @@ -2468,6 +2468,7 @@ abbreviations: <a href="refP.html#pipe">pipe</a> <a href="refT.html#timeout">timeout</a> <a href="refM.html#mail">mail</a> + <a href="refA.html#assert">assert</a> <a href="refT.html#test">test</a> <a href="refB.html#bye">bye</a> </code> diff --git a/doc/refA.html b/doc/refA.html @@ -439,6 +439,45 @@ href="refM.html#mmeq">mmeq</a></code> and <a href="ref.html#cmp">Comparing</a>. -> (b . 7) </code></pre> +<dt><a name="assert"><code>(assert exe) -> prg | NIL</code></a> +<dd>When in debug mode (<code><a href="refD.html#*Dbg">*Dbg</a></code> is +non-<code>NIL</code>), <code>assert</code> returns a <code>prg</code> list which +tests <code>exe</code> and issues an error via <code><a +href="refQ.html#quit">quit</a></code> if the result is <code>NIL</code>. +Otherwise, <code>NIL</code> is returned. Used typically in combination with the +<code>~</code> tilde <code><a href="ref.html#macro-io">read-macro</a></code> to +insert the test code only when in debug mode. See also <code><a +href="refT.html#test">test</a></code>. + +<pre><code> +# Start in debug mode +$ ./dbg +: (de foo (N) + ~(assert (>= 90 N 10)) + (bar N) ) +-> foo +: (pp 'foo) +(de foo (N) + (unless (>= 90 N 10) # Assertion code exists + (quit "Assertion failed" '(>= 90 N 10)) ) + (bar N) ) +-> foo +: (foo 7) +(>= 90 N 10) -- Assertion failed +? + +# Start in non-debug mode +$ ./p +: (de foo (N) + ~(assert (>= 90 N 10)) + (bar N) ) +-> foo +: (pp 'foo) +(de foo (N) + (bar N) ) # Assertion code does not exist +-> foo +</code></pre> + <dt><a name="asserta"><code>(asserta 'lst) -> lst</code></a> <dd>Inserts a new <a href="ref.html#pilog">Pilog</a> fact or rule before all other rules. See also <code><a href="refB.html#be">be</a></code>, <code><a diff --git a/doc/refT.html b/doc/refT.html @@ -233,7 +233,8 @@ href="refR.html#rpc">rpc</a></code>. <dt><a name="test"><code>(test 'any . prg)</code></a> <dd>Executes <code>prg</code>, and issues an <code><a href="ref.html#errors">error</a></code> if the result does not <code><a -href="refM.html#match">match</a></code> the <code>any</code> argument. +href="refM.html#match">match</a></code> the <code>any</code> argument. See also +<code><a href="refA.html#assert">assert</a></code>. <pre><code> : (test 12 (* 3 4)) diff --git a/lib/misc.l b/lib/misc.l @@ -476,7 +476,13 @@ (out S (prinl "RCPT TO:" To "^M")) (pre? "250 " (in S (line T))) ) -### Testing ### +### Assertions ### +(de assert E + (when *Dbg + (cons + (list 'unless (car E) + (list 'quit "Assertion failed" (lit (car E))) ) ) ) ) + (de test (Pat . Prg) (bind (fish pat? Pat) (unless (match Pat (run Prg 1)) diff --git a/src64/version.l b/src64/version.l @@ -1,6 +1,6 @@ # 18jun10abu # (c) Software Lab. Alexander Burger -(de *Version 3 0 2 30) +(de *Version 3 0 2 31) # vi:et:ts=3:sw=3