core: add Char.alpha?, Char.num?, and Char.alphanum?

This commit is contained in:
hellerve 2019-03-06 16:35:29 +01:00
parent 555ea2fcf8
commit f470e17f99
3 changed files with 108 additions and 0 deletions

View File

@ -33,6 +33,18 @@
(doc upper-case? "tests whether a character is upper case.")
(defn upper-case? [c]
(and (<= \A c) (<= c \Z)))
(doc alpha? "tests whether a character is alphabetical.")
(defn alpha? [c]
(or (lower-case? c) (upper-case? c)))
(doc num? "tests whether a character is numerical.")
(defn num? [c]
(and (<= \0 c) (<= c \9)))
(doc alphanum? "tests whether a character is alphanumerical.")
(defn alphanum? [c]
(or (alpha? c) (num? c)))
)
(defmodule CharRef

View File

@ -214,6 +214,46 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#alpha?">
<h3 id="alpha?">
alpha?
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Char] Bool)
</p>
<pre class="args">
(alpha? c)
</pre>
<p class="doc">
<p>tests whether a character is alphabetical.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#alphanum?">
<h3 id="alphanum?">
alphanum?
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Char] Bool)
</p>
<pre class="args">
(alphanum? c)
</pre>
<p class="doc">
<p>tests whether a character is alphanumerical.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#copy">
<h3 id="copy">
@ -330,6 +370,26 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#num?">
<h3 id="num?">
num?
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Char] Bool)
</p>
<pre class="args">
(num? c)
</pre>
<p class="doc">
<p>tests whether a character is numerical.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#prn">
<h3 id="prn">

View File

@ -54,4 +54,40 @@
(assert-false test
(lower-case? \#)
"lower-case? works as expected III")
(assert-true test
(alpha? \a)
"alpha? works as expected I")
(assert-true test
(alpha? \A)
"alpha? works as expected II")
(assert-false test
(alpha? \#)
"alpha? works as expected III")
(assert-false test
(alpha? \0)
"alpha? works as expected III")
(assert-false test
(num? \a)
"num? works as expected I")
(assert-false test
(num? \A)
"num? works as expected II")
(assert-false test
(num? \#)
"num? works as expected III")
(assert-true test
(num? \0)
"num? works as expected III")
(assert-true test
(alphanum? \a)
"alphanum? works as expected I")
(assert-true test
(alphanum? \A)
"alphanum? works as expected II")
(assert-false test
(alphanum? \#)
"alphanum? works as expected III")
(assert-true test
(alphanum? \0)
"alphanum? works as expected III")
)