mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 13:51:50 +03:00
63 lines
1.5 KiB
Plaintext
63 lines
1.5 KiB
Plaintext
(system-include "carp_char.h")
|
|
|
|
(defmodule Char
|
|
(register = (Fn [Char Char] Bool))
|
|
(register < (Fn [Char Char] Bool))
|
|
(register > (Fn [Char Char] Bool))
|
|
(register to-int (Fn [Char] Int))
|
|
(register from-int (Fn [Int] Char))
|
|
(register copy (Fn [&Char] Char))
|
|
|
|
(doc meaning "converts a numerical char into the appropriate number (e.g. from `\1` to `1`).")
|
|
(defn meaning [char-ref]
|
|
(cond
|
|
(= @char-ref \0) 0
|
|
(= @char-ref \1) 1
|
|
(= @char-ref \2) 2
|
|
(= @char-ref \3) 3
|
|
(= @char-ref \4) 4
|
|
(= @char-ref \5) 5
|
|
(= @char-ref \6) 6
|
|
(= @char-ref \7) 7
|
|
(= @char-ref \8) 8
|
|
(= @char-ref \9) 9
|
|
-1))
|
|
|
|
(defn /= [a b]
|
|
(not (= (the Char a) b)))
|
|
|
|
(doc lower-case? "tests whether a character is lower case.")
|
|
(defn lower-case? [c]
|
|
(and (<= \a c) (<= c \z)))
|
|
|
|
(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
|
|
(defn = [a b]
|
|
(Char.= @a @b))
|
|
(defn /= [a b]
|
|
(Char./= @a @b))
|
|
(defn < [a b]
|
|
(Char.< @a @b))
|
|
(defn > [a b]
|
|
(Char.> @a @b))
|
|
)
|
|
|
|
(defmodule PtrChar
|
|
(register str (Fn [(Ptr Char)] String)))
|