2018-01-24 18:08:18 +03:00
|
|
|
(system-include "carp_char.h")
|
2018-01-24 17:53:18 +03:00
|
|
|
|
2021-07-05 15:48:35 +03:00
|
|
|
(doc Char "is the single character data type.")
|
2017-06-26 12:15:03 +03:00
|
|
|
(defmodule Char
|
2017-11-29 17:28:21 +03:00
|
|
|
(register = (Fn [Char Char] Bool))
|
2018-06-26 10:05:53 +03:00
|
|
|
(register < (Fn [Char Char] Bool))
|
|
|
|
(register > (Fn [Char Char] Bool))
|
2017-11-14 20:33:03 +03:00
|
|
|
(register to-int (Fn [Char] Int))
|
|
|
|
(register from-int (Fn [Int] Char))
|
2021-03-16 13:14:16 +03:00
|
|
|
(register to-byte (Fn [Char] Byte))
|
|
|
|
(register from-byte (Fn [Byte] Char))
|
2017-11-22 18:25:05 +03:00
|
|
|
(register copy (Fn [&Char] Char))
|
2017-12-28 20:10:38 +03:00
|
|
|
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements < Char.<)
|
|
|
|
(implements > Char.>)
|
|
|
|
(implements = Char.=)
|
|
|
|
(implements copy Char.copy)
|
|
|
|
(implements to-int Char.to-int)
|
|
|
|
(implements from-int Char.from-int)
|
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc meaning "converts a numerical char into the appropriate number (e.g. from `\1` to `1`).")
|
2017-12-01 14:02:36 +03:00
|
|
|
(defn meaning [char-ref]
|
2019-10-28 19:19:31 +03:00
|
|
|
(let [c @char-ref]
|
|
|
|
(case c
|
|
|
|
\0 0
|
|
|
|
\1 1
|
|
|
|
\2 2
|
|
|
|
\3 3
|
|
|
|
\4 4
|
|
|
|
\5 5
|
|
|
|
\6 6
|
|
|
|
\7 7
|
|
|
|
\8 8
|
|
|
|
\9 9
|
|
|
|
-1)))
|
2018-01-02 20:13:52 +03:00
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc lower-case? "tests whether a character is lower case.")
|
2018-09-25 17:40:02 +03:00
|
|
|
(defn lower-case? [c]
|
2018-09-25 17:14:38 +03:00
|
|
|
(and (<= \a c) (<= c \z)))
|
|
|
|
|
2019-02-15 16:48:49 +03:00
|
|
|
(doc upper-case? "tests whether a character is upper case.")
|
2018-09-25 17:40:02 +03:00
|
|
|
(defn upper-case? [c]
|
2018-09-25 17:14:38 +03:00
|
|
|
(and (<= \A c) (<= c \Z)))
|
2019-03-06 18:35:29 +03:00
|
|
|
|
|
|
|
(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)))
|
2019-06-14 14:02:03 +03:00
|
|
|
|
2020-01-29 13:48:31 +03:00
|
|
|
(defn zero [] (the Char (from-int 0)))
|
2020-05-09 19:59:47 +03:00
|
|
|
(implements zero Char.zero)
|
2017-11-14 20:33:03 +03:00
|
|
|
)
|
2018-03-12 14:11:33 +03:00
|
|
|
|
|
|
|
(defmodule CharRef
|
|
|
|
(defn = [a b]
|
2018-06-26 10:05:53 +03:00
|
|
|
(Char.= @a @b))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements = CharRef.=)
|
2018-06-26 10:05:53 +03:00
|
|
|
(defn < [a b]
|
|
|
|
(Char.< @a @b))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements < CharRef.<)
|
2018-06-26 10:05:53 +03:00
|
|
|
(defn > [a b]
|
|
|
|
(Char.> @a @b))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements > CharRef.>)
|
2018-06-26 10:05:53 +03:00
|
|
|
)
|
2018-03-18 16:40:49 +03:00
|
|
|
|
|
|
|
(defmodule PtrChar
|
2020-05-10 20:32:22 +03:00
|
|
|
(register str (Fn [(Ptr Char)] String))
|
|
|
|
(implements str PtrChar.str))
|