aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/char.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/char.lux')
-rw-r--r--stdlib/source/lux/data/char.lux50
1 files changed, 25 insertions, 25 deletions
diff --git a/stdlib/source/lux/data/char.lux b/stdlib/source/lux/data/char.lux
index 28877ae34..0db90898e 100644
--- a/stdlib/source/lux/data/char.lux
+++ b/stdlib/source/lux/data/char.lux
@@ -9,48 +9,43 @@
## [Structures]
(struct: #export _ (Eq Char)
(def: (= x y)
- (_lux_proc ["jvm" "ceq"] [x y])))
+ (_lux_proc ["char" "="] [x y])))
(struct: #export _ (Hash Char)
(def: eq Eq<Char>)
- (def: hash
- (|>. []
- (_lux_proc ["jvm" "c2i"])
- []
- (_lux_proc ["jvm" "i2l"])
- int-to-nat)))
+ (def: (hash input)
+ (_lux_proc ["char" "to-nat"] [input])))
(struct: #export _ (ord;Ord Char)
(def: eq Eq<Char>)
- (do-template [<name> <op>]
- [(def: (<name> test subject)
- (_lux_proc ["jvm" <op>] [subject test]))]
+ (def: (< test subject)
+ (_lux_proc ["char" "<"] [subject test]))
- [< "clt"]
- [> "cgt"]
- )
+ (def: (<= test subject)
+ (or (_lux_proc ["char" "="] [subject test])
+ (_lux_proc ["char" "<"] [subject test])))
- (do-template [<name> <op>]
- [(def: (<name> test subject)
- (or (_lux_proc ["jvm" "ceq"] [subject test])
- (_lux_proc ["jvm" <op>] [subject test])))]
+ (def: (> test subject)
+ (_lux_proc ["char" "<"] [test subject]))
- [<= "clt"]
- [>= "cgt"]
- ))
+ (def: (>= test subject)
+ (or (_lux_proc ["char" "="] [test subject])
+ (_lux_proc ["char" "<"] [test subject])))
+ )
(struct: #export _ (Codec Text Char)
(def: (encode x)
(let [as-text (case x
#"\t" "\\t"
+ #"\v" "\\v"
#"\b" "\\b"
#"\n" "\\n"
#"\r" "\\r"
#"\f" "\\f"
#"\"" "\\\""
#"\\" "\\\\"
- _ (_lux_proc ["jvm" "invokevirtual:java.lang.Object:toString:"] [x]))]
+ _ (_lux_proc ["char" "to-text"] [x]))]
($_ Text/append "#\"" as-text "\"")))
(def: (decode y)
@@ -70,13 +65,13 @@
[(#;Some #"\\") (#;Some char)]
(case char
#"t" (#;Right #"\t")
+ #"v" (#;Right #"\v")
#"b" (#;Right #"\b")
#"n" (#;Right #"\n")
#"r" (#;Right #"\r")
#"f" (#;Right #"\f")
#"\"" (#;Right #"\"")
#"\\" (#;Right #"\\")
- #"t" (#;Right #"\t")
_ (#;Left (Text/append "Wrong syntax for Char: " y)))
_
@@ -84,14 +79,19 @@
(#;Left (Text/append "Wrong syntax for Char: " y))))))
## [Values]
-(def: #export (space? x)
+(def: #export (space? char)
{#;doc "Checks whether the character is white-space."}
(-> Char Bool)
- (_lux_proc ["jvm" "invokestatic:java.lang.Character:isWhitespace:char"] [x]))
+ (case char
+ (^or #"\t" #"\v" #" " #"\n" #"\r" #"\f")
+ true
+
+ _
+ false))
(def: #export (as-text x)
(-> Char Text)
- (_lux_proc ["jvm" "invokevirtual:java.lang.Object:toString:"] [x]))
+ (_lux_proc ["char" "to-text"] [x]))
(def: #export (char x)
(-> Nat Char)