2018-02-27 16:14:14 +03:00
(system-include "carp_string.h")
2021-06-16 10:45:32 +03:00
(system-include "ctype.h")
(defmodule Byte
(hidden tolower-) ; helper func for String.ascii-to-lower
(register tolower- (Fn [Byte] Byte) "tolower")
(hidden toupper-) ; helper func for String.ascii-to-upper
(register toupper- (Fn [Byte] Byte) "toupper")
)
2021-07-05 15:48:35 +03:00
(doc String "is the string data type for representing text.")
2017-06-26 12:15:03 +03:00
(defmodule String
2017-12-12 14:57:13 +03:00
2017-10-20 18:00:47 +03:00
(register = (Fn [&String &String] Bool))
2018-06-26 09:00:33 +03:00
(register > (Fn [&String &String] Bool))
(register < (Fn [&String &String] Bool))
2018-05-20 07:04:47 +03:00
(register append (Fn [&String &String] String))
2017-10-20 18:00:47 +03:00
(register delete (Fn [String] ()))
(register copy (Fn [&String] String))
2018-05-20 10:57:51 +03:00
(register length (Fn [&String] Int))
2020-05-11 17:10:35 +03:00
(register cstr (Fn [&String] (Ptr CChar)))
(register from-cstr (Fn [(Ptr CChar)] String))
2017-10-20 18:00:47 +03:00
(register str (Fn [&String] String))
2018-02-06 20:37:15 +03:00
(register prn (Fn [&String] String))
2018-05-20 11:25:13 +03:00
(register index-of (Fn [&String Char] Int))
2018-05-20 11:41:36 +03:00
(register index-of-from (Fn [&String Char Int] Int))
2017-12-18 18:19:29 +03:00
(register char-at (Fn [&String Int] Char))
2017-10-20 18:00:47 +03:00
(register chars (Fn [&String] (Array Char)))
2018-03-12 16:56:05 +03:00
(register from-chars (Fn [&(Array Char)] String))
2017-12-04 17:25:18 +03:00
(register tail (λ [(Ref String)] String))
2017-12-30 22:16:31 +03:00
(register format (Fn [&String &String] String))
2020-05-10 20:32:22 +03:00
(implements format String.format)
2018-05-19 09:49:48 +03:00
(register string-set! (Fn [&String Int Char] ()))
2018-05-20 06:53:30 +03:00
(register string-set-at! (Fn [&String Int &String] ()))
2018-05-20 11:47:27 +03:00
(register allocate (Fn [Int Char] String))
2021-06-17 18:33:10 +03:00
(doc allocated? "checks if a String returned by String.allocate is not NULL. This is a safeguard against out-of-memory conditions.")
2021-06-08 22:05:51 +03:00
(defn allocated? [s]
(not (null? (cstr s))) )
2020-07-08 21:39:50 +03:00
(register from-bytes (Fn [&(Array Byte)] String))
2020-05-13 18:15:26 +03:00
(register to-bytes (Fn [&String] (Array Byte)))
2017-10-20 18:00:47 +03:00
2020-05-09 19:59:47 +03:00
(implements < String.<)
(implements > String.>)
(implements = String.=)
(implements copy String.copy)
(implements prn String.prn)
(implements str String.str)
2020-12-20 23:21:14 +03:00
(implements delete String.delete)
2020-05-09 19:59:47 +03:00
2018-05-19 06:09:54 +03:00
(doc head "Returns the character at start of string.")
2017-12-18 18:06:17 +03:00
(defn head [s]
(char-at s 0))
2017-10-20 18:00:47 +03:00
2018-05-19 06:09:54 +03:00
(doc repeat "Returns a new string which is `inpt` repeated `n` times.")
2017-10-20 18:00:47 +03:00
(defn repeat [n inpt]
2019-10-28 20:13:40 +03:00
(let [l (length inpt)
str (String.allocate (* n l) \0)]
2017-10-20 18:00:47 +03:00
(do
(for [i 0 n]
2019-10-28 20:13:40 +03:00
(string-set-at! &str (* i l) inpt))
2017-12-23 16:30:45 +03:00
str)))
2017-12-04 00:30:48 +03:00
2018-06-15 17:38:34 +03:00
(doc pad-left "Pads the left of a string with len bytes using the padding pad.")
2017-11-29 23:33:35 +03:00
(defn pad-left [len pad s]
2020-04-10 20:52:01 +03:00
(let [x (max 0 (- len (length s)))]
2018-05-20 07:04:47 +03:00
(append &(from-chars &(Array.replicate x &pad)) s)))
2017-11-29 23:33:35 +03:00
2018-06-15 17:38:34 +03:00
(doc pad-right "Pads the right of a string with len bytes using the padding pad.")
2017-11-29 23:33:35 +03:00
(defn pad-right [len pad s]
2020-04-10 20:52:01 +03:00
(let [x (max 0 (- len (length s)))]
2018-05-20 07:04:47 +03:00
(append s &(from-chars &(Array.replicate x &pad)))))
2017-12-18 17:46:25 +03:00
2018-05-19 06:09:54 +03:00
(doc count-char "Returns the number of occurrences of `c` in the string `s`.")
2017-12-18 17:46:25 +03:00
(defn count-char [s c]
(let-do [n 0]
2018-05-20 10:57:51 +03:00
(for [i 0 (length s)]
2017-12-18 18:19:29 +03:00
(when (= c (char-at s i))
2018-02-02 09:19:10 +03:00
(set! n (Int.inc n))))
2017-12-18 17:46:25 +03:00
n))
2018-05-19 06:09:54 +03:00
(doc reverse "Produce a new string which is `s` reversed.")
2017-12-18 17:46:25 +03:00
(defn reverse [s]
2018-03-12 16:56:05 +03:00
(from-chars &(Array.reverse (chars s))))
2017-11-29 23:33:35 +03:00
2018-05-19 06:09:54 +03:00
(doc empty? "Check if the string is the empty string.")
2017-11-29 23:33:35 +03:00
(defn empty? [s]
2018-05-20 10:57:51 +03:00
(Int.= (length s) 0))
2021-01-20 11:54:08 +03:00
(implements empty? String.empty?)
2017-12-28 20:10:38 +03:00
2020-11-19 00:53:13 +03:00
(doc slice "Return part of a string, beginning at index `a` and ending at index `b`.")
2020-02-11 11:09:30 +03:00
(defn slice [s a b]
(from-chars &(Array.slice &(chars s) a b)))
2020-05-09 19:59:47 +03:00
(implements slice String.slice)
2018-01-02 20:13:52 +03:00
2020-02-11 11:09:30 +03:00
(doc prefix "Return the first `a` characters of the string `s`.")
(defn prefix [s a]
2020-11-18 01:42:03 +03:00
(from-chars &(Array.prefix &(chars s) a)))
2018-01-02 20:13:52 +03:00
2020-11-18 01:42:03 +03:00
(doc suffix "Returns the suffix string starting at the `b`th character.")
2020-02-11 11:09:30 +03:00
(defn suffix [s b]
2020-11-18 01:42:03 +03:00
(from-chars &(Array.suffix &(chars s) b)))
2018-01-02 20:13:52 +03:00
2018-05-19 06:09:54 +03:00
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
2018-01-02 20:13:52 +03:00
(defn starts-with? [s sub]
2020-02-12 19:22:03 +03:00
(let [ls (length sub)]
(and (>= (length s) ls) (= sub &(prefix s ls)))))
2018-01-02 20:13:52 +03:00
2018-06-15 17:38:34 +03:00
(doc ends-with? "Check if the string `s` ends with the string `sub`.")
2020-02-12 19:22:03 +03:00
(defn ends-with? [s sub]
(let [ls (length s)
lsub (length sub)]
(and (>= ls lsub) (= sub &(suffix s (- ls lsub))))))
2018-05-19 06:09:54 +03:00
(doc zero "The empty string.")
2018-01-29 00:54:59 +03:00
(defn zero [] @"")
2020-05-09 19:59:47 +03:00
(implements zero String.zero)
2018-03-11 17:09:30 +03:00
2018-05-20 10:57:51 +03:00
(doc sum-length "Returns the sum of lengths from an array of Strings.")
(defn sum-length [strings]
2018-05-20 09:48:20 +03:00
(let-do [sum 0
2018-05-20 10:57:51 +03:00
lstrings (Array.length strings)]
2018-05-20 09:48:20 +03:00
(for [i 0 lstrings]
2019-10-31 12:23:23 +03:00
(set! sum (+ sum (String.length (Array.unsafe-nth strings i)))))
2018-05-20 09:48:20 +03:00
sum))
2018-05-19 09:02:03 +03:00
(doc concat "Returns a new string which is the concatenation of the provided `strings`.")
(defn concat [strings]
2018-05-20 09:48:20 +03:00
;; This is using a StringBuilder pattern to only perform one allocation and
;; to only copy each of the incoming strings once.
2018-05-20 10:57:51 +03:00
;; This currently performs wasted String.length calls, as we call it for each
;; string once here and once in sum-length.
2018-05-20 09:48:20 +03:00
(let-do [j 0
2018-05-20 10:57:51 +03:00
lstrings (Array.length strings)
result (String.allocate (sum-length strings) \ )]
2018-05-20 09:56:51 +03:00
(for [i 0 lstrings]
2019-10-31 12:23:23 +03:00
(let-do [str (Array.unsafe-nth strings i)
2018-05-20 10:57:51 +03:00
len (String.length str)]
2018-05-20 09:56:51 +03:00
(string-set-at! &result j str)
(set! j (+ j len))))
result))
2018-05-19 06:17:06 +03:00
2018-05-20 10:11:26 +03:00
(doc join "Returns a new string which is the concatenation of the provided `strings` separated by string `sep`.")
2018-05-19 09:02:03 +03:00
(defn join [sep strings]
2018-05-20 10:11:26 +03:00
(let-do [j 0
2018-05-20 10:57:51 +03:00
lstrings (Array.length strings)
2019-09-10 22:49:00 +03:00
num-seps (max 0 (- lstrings 1))
2019-09-16 21:22:01 +03:00
sep-length (String.length sep)
2018-05-20 10:11:26 +03:00
seps-size (* num-seps sep-length)
2018-05-20 10:57:51 +03:00
result (String.allocate (+ seps-size (sum-length strings)) \ )]
2018-05-20 10:11:26 +03:00
(for [i 0 lstrings]
2019-10-31 12:23:23 +03:00
(let-do [str (Array.unsafe-nth strings i)
2018-05-20 10:57:51 +03:00
len (String.length str)]
2018-05-20 10:11:26 +03:00
(when (> i 0)
(do
2019-09-16 21:22:01 +03:00
(string-set-at! &result j sep)
2018-05-20 10:11:26 +03:00
(set! j (+ j sep-length))))
(string-set-at! &result j str)
(set! j (+ j len))))
result))
(doc join-with-char "Returns a new string which is the concatenation of the provided `strings` separated by char `sep`.")
(defn join-with-char [sep strings]
;; (= (join-with-char \ ["Hello" "world"]) (join " " ["Hello" "world"]))
(let-do [j 0
2018-05-20 10:57:51 +03:00
lstrings (Array.length strings)
2019-09-10 22:49:00 +03:00
sep-length (max 0 (- lstrings 1))
2018-05-20 10:57:51 +03:00
result (String.allocate (+ sep-length (sum-length strings)) \ )]
2018-05-20 10:11:26 +03:00
(for [i 0 lstrings]
2019-10-31 12:23:23 +03:00
(let-do [str (Array.unsafe-nth strings i)
2018-05-20 10:57:51 +03:00
len (String.length str)]
2018-05-19 06:17:06 +03:00
(when (> i 0)
2018-05-20 10:11:26 +03:00
(do
(string-set! &result j sep)
(set! j (+ j 1))))
(string-set-at! &result j str)
(set! j (+ j len))))
2018-03-11 17:09:30 +03:00
result))
2019-03-23 20:41:08 +03:00
(doc contains? "Checks whether the string `s` contains the character `c`.")
(defn contains? [s c] (> (index-of s c) -1))
2021-06-16 10:45:32 +03:00
(doc ascii-to-lower "converts each character in this string to lower case using tolower() from standard C library. Note: this will only work for ASCII characters.")
(defn ascii-to-lower [s]
(String.from-bytes &(Array.endo-map &(fn [c] (Byte.tolower- c)) (String.to-bytes s))) )
(doc ascii-to-upper "converts each character in this string to upper case using toupper() from standard C library. Note: this will only work for ASCII characters.")
(defn ascii-to-upper [s]
(String.from-bytes &(Array.endo-map &(fn [c] (Byte.toupper- c)) (String.to-bytes s))) )
2017-11-29 23:33:35 +03:00
)
2017-10-20 18:00:47 +03:00
2017-12-22 13:17:19 +03:00
(defmodule StringCopy
2018-06-15 17:38:34 +03:00
(defn str [s] (the String s))
2017-12-22 13:17:19 +03:00
(defn = [a b]
(String.= &a &b))
2020-05-09 19:59:47 +03:00
(implements = StringCopy.=)
2017-12-19 19:53:27 +03:00
2018-06-26 10:20:39 +03:00
(defn < [a b]
(String.< &a &b))
2020-05-10 20:32:22 +03:00
(implements < StringCopy.<)
2018-06-26 10:20:39 +03:00
(defn > [a b]
(String.> &a &b))
2020-05-10 20:32:22 +03:00
(implements > StringCopy.>)
2018-08-07 10:30:06 +03:00
(defn prn [s]
(prn &(the String s)))
2020-05-10 20:32:22 +03:00
(implements prn StringCopy.prn)
2018-08-07 10:30:06 +03:00
(defn str [s]
(str &(the String s)))
2020-05-09 19:59:47 +03:00
(implements str StringCopy.str)
2017-12-22 13:17:19 +03:00
)
2017-10-20 18:00:47 +03:00
2018-02-27 16:49:06 +03:00
(defmodule Bool
(register str (Fn [Bool] String))
2020-05-10 20:32:22 +03:00
(implements str Bool.str)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Bool] String))
2020-05-09 19:59:47 +03:00
(implements format Bool.format)
2018-02-27 16:49:06 +03:00
)
(defmodule Int
(register str (Fn [Int] String))
2020-05-10 20:32:22 +03:00
(implements str Int.str)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Int] String))
2020-05-09 19:59:47 +03:00
(implements format Int.format)
2020-05-12 19:02:30 +03:00
(private from-string-internal)
(hidden from-string-internal)
(register from-string-internal (λ [&String &Int] Bool))
(defn from-string [s]
(let [res 0]
(if (from-string-internal s &res)
(Maybe.Just res)
(Maybe.Nothing))))
2020-05-09 19:59:47 +03:00
(implements from-string Int.from-string)
2018-02-27 16:49:06 +03:00
)
2019-10-24 12:23:38 +03:00
(defmodule Byte
(register str (Fn [Byte] String))
2020-05-10 20:32:22 +03:00
(implements str Byte.str)
2019-10-24 12:23:38 +03:00
(register format (Fn [&String Byte] String))
2020-05-09 19:59:47 +03:00
(implements format Byte.format)
2020-05-12 19:02:30 +03:00
(private from-string-internal)
(hidden from-string-internal)
(register from-string-internal (λ [&String &Byte] Bool))
(defn from-string [s]
(let [res 0b]
(if (from-string-internal s &res)
(Maybe.Just res)
(Maybe.Nothing))))
2020-05-09 19:59:47 +03:00
(implements from-string Byte.from-string)
2019-10-24 12:23:38 +03:00
)
2018-02-27 16:49:06 +03:00
(defmodule Float
(register str (Fn [Float] String))
2020-05-10 20:32:22 +03:00
(implements str Float.str)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Float] String))
2020-05-09 19:59:47 +03:00
(implements format Float.format)
2020-05-12 19:02:30 +03:00
(private from-string-internal)
(hidden from-string-internal)
(register from-string-internal (λ [&String &Float] Bool))
(defn from-string [s]
(let [res 0.0f]
(if (from-string-internal s &res)
(Maybe.Just res)
(Maybe.Nothing))))
2020-05-09 19:59:47 +03:00
(implements from-string Float.from-string)
2018-02-27 16:49:06 +03:00
)
(defmodule Long
(register str (Fn [Long] String))
2020-05-10 20:32:22 +03:00
(implements str Long.str)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Long] String))
2020-05-09 19:59:47 +03:00
(implements format Long.format)
2020-05-12 19:02:30 +03:00
(private from-string-internal)
(hidden from-string-internal)
(register from-string-internal (λ [&String &Long] Bool))
(defn from-string [s]
(let [res 0l]
(if (from-string-internal s &res)
(Maybe.Just res)
(Maybe.Nothing))))
2020-05-09 19:59:47 +03:00
(implements from-string Long.from-string)
2018-02-27 16:49:06 +03:00
)
(defmodule Double
(register str (Fn [Double] String))
2020-05-10 20:32:22 +03:00
(implements str Double.str)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Double] String))
2020-05-09 19:59:47 +03:00
(implements format Double.format)
2020-05-12 19:02:30 +03:00
(private from-string-internal)
(hidden from-string-internal)
(register from-string-internal (λ [&String &Double] Bool))
(defn from-string [s]
(let [res 0.0]
(if (from-string-internal s &res)
(Maybe.Just res)
(Maybe.Nothing))))
2020-05-09 19:59:47 +03:00
(implements from-string Double.from-string)
2018-02-27 16:49:06 +03:00
)
(defmodule Char
(register str (Fn [Char] String))
2020-05-10 20:32:22 +03:00
(implements str Char.str)
2018-05-20 19:28:45 +03:00
(register prn (Fn [Char] String))
2020-05-09 19:59:47 +03:00
(implements prn Char.prn)
2018-02-27 16:49:06 +03:00
(register format (Fn [&String Char] String))
2020-05-09 19:59:47 +03:00
(implements format Char.format)
2018-02-27 16:49:06 +03:00
)
2018-02-27 17:30:22 +03:00
2020-05-09 19:59:47 +03:00
(defmodule Int (defn prn [x] (Int.str x)) (implements prn Int.prn))
2018-12-12 09:20:20 +03:00
(defmodule IntRef
(defn prn [x] (Int.str @x))
2020-05-09 19:59:47 +03:00
(implements prn IntRef.prn)
2018-12-12 09:20:20 +03:00
(defn str [x] (Int.str @x))
2020-05-10 20:32:22 +03:00
(implements str IntRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Int.format s @x))
(implements format IntRef.format)
2020-05-12 16:03:47 +03:00
)
2019-06-14 16:24:25 +03:00
2021-01-15 12:48:34 +03:00
(defmodule Bool (defn prn [x] (Bool.str x)) (implements prn Bool.prn))
2019-06-14 16:24:25 +03:00
(defmodule BoolRef
(defn prn [x] (Bool.str @x))
2020-05-09 19:59:47 +03:00
(implements prn BoolRef.prn)
2020-05-10 20:32:22 +03:00
(defn str [x] (Bool.str @x))
(implements str BoolRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Bool.format s @x))
(implements format BoolRef.format)
2020-05-12 16:03:47 +03:00
)
2018-12-12 09:20:20 +03:00
2020-05-12 16:03:47 +03:00
(defmodule Byte (defn prn [x] (Byte.str x)) (implements prn Byte.prn))
2019-10-24 13:08:49 +03:00
(defmodule ByteRef
(defn prn [x] (Byte.str @x))
2020-05-09 19:59:47 +03:00
(implements prn ByteRef.prn)
2019-10-24 13:08:49 +03:00
(defn str [x] (Byte.str @x))
2020-05-10 20:32:22 +03:00
(implements str ByteRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Byte.format s @x))
(implements format ByteRef.format)
2020-05-12 16:03:47 +03:00
)
2019-10-24 13:08:49 +03:00
2020-05-09 19:59:47 +03:00
(defmodule Long (defn prn [x] (Long.str x)) (implements prn Long.prn))
2020-05-12 16:03:47 +03:00
(defmodule LongRef
(defn prn [x] (Long.str @x))
2020-05-12 17:01:42 +03:00
(implements prn LongRef.prn)
2020-05-12 16:03:47 +03:00
(defn str [x] (Long.str @x))
2020-05-12 17:01:42 +03:00
(implements str LongRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Long.format s @x))
(implements format LongRef.format)
2020-05-12 16:03:47 +03:00
)
2020-05-09 19:59:47 +03:00
(defmodule Float (defn prn [x] (Float.str x)) (implements prn Float.prn))
2020-05-12 16:03:47 +03:00
(defmodule FloatRef
(defn prn [x] (Float.str @x))
2020-05-12 17:01:42 +03:00
(implements prn FloatRef.prn)
2020-05-12 16:03:47 +03:00
(defn str [x] (Float.str @x))
2020-05-12 17:01:42 +03:00
(implements str FloatRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Float.format s @x))
(implements format FloatRef.format)
2020-05-12 16:03:47 +03:00
)
2020-05-09 19:59:47 +03:00
(defmodule Double (defn prn [x] (Double.str x)) (implements prn Double.prn))
2020-05-12 16:03:47 +03:00
(defmodule DoubleRef
(defn prn [x] (Double.str @x))
2020-05-12 17:01:42 +03:00
(implements prn DoubleRef.prn)
2020-05-12 16:03:47 +03:00
(defn str [x] (Double.str @x))
2020-05-12 17:01:42 +03:00
(implements str DoubleRef.str)
2021-01-15 12:48:34 +03:00
(defn format [s x] (Double.format s @x))
(implements format DoubleRef.format)
2020-05-12 16:03:47 +03:00
)
2020-05-09 19:59:47 +03:00
(defmodule Array (defn prn [x] (Array.str x)) (implements prn Array.prn))
2020-10-26 22:14:50 +03:00
(defmodule Int8
(register str (λ [Int8] String))
(implements str Int8.str)
(defn prn [a] (Int8.str a))
(implements prn Int8.prn)
)
(defmodule Int8Extra
(defn str [a] (Int8.str @a))
(implements str Int8Extra.str)
(defn prn [a] (Int8.prn @a))
(implements prn Int8Extra.prn)
)
(defmodule Int16
(register str (λ [Int16] String))
(implements str Int16.str)
(defn prn [a] (Int16.str a))
(implements prn Int16.prn)
)
(defmodule Int16Extra
(defn prn [a] (Int16.prn @a))
(implements prn Int16Extra.prn)
(defn str [a] (Int16.str @a))
(implements str Int16Extra.str)
)
(defmodule Int32
(register str (λ [Int32] String))
(implements str Int32.str)
(defn prn [a] (Int32.str a))
(implements prn Int32.prn)
)
(defmodule Int32Extra
(defn str [a] (Int32.str @a))
(implements str Int32Extra.str)
(defn prn [a] (Int32.prn @a))
(implements prn Int32Extra.prn)
)
(defmodule Int64
(register str (λ [Int64] String))
(implements str Int64.str)
(defn prn [a] (Int64.str a))
(implements prn Int64.prn)
)
(defmodule Int64Extra
(defn str [a] (Int64.str @a))
(implements str Int64Extra.str)
(defn prn [a] (Int64.prn @a))
(implements prn Int64Extra.prn)
)
(defmodule Uint8
(register str (λ [Uint8] String))
(implements str Uint8.str)
(defn prn [a] (Uint8.str a))
(implements prn Uint8.prn)
)
(defmodule Uint8Extra
(defn str [a] (Uint8.str @a))
(implements str Uint8Extra.str)
(defn prn [a] (Uint8.prn @a))
(implements prn Uint8Extra.prn)
)
(defmodule Uint16
(register str (λ [Uint16] String))
(implements str Uint16.str)
(defn prn [a] (Uint16.str a))
(implements prn Uint16.prn)
)
(defmodule Uint16Extra
(defn prn [a] (Uint16.prn @a))
(implements prn Uint16Extra.prn)
(defn str [a] (Uint16.str @a))
(implements str Uint16Extra.str)
)
(defmodule Uint32
(register str (λ [Uint32] String))
(implements str Uint32.str)
(defn prn [a] (Uint32.str a))
(implements prn Uint32.prn)
)
(defmodule Uint32Extra
(defn str [a] (Uint32.str @a))
(implements str Uint32Extra.str)
(defn prn [a] (Uint32.prn @a))
(implements prn Uint32Extra.prn)
)
(defmodule Uint64
(register str (λ [Uint64] String))
(implements str Uint64.str)
(defn prn [a] (Uint64.str a))
(implements prn Uint64.prn)
)
(defmodule Uint64Extra
(defn str [a] (Uint64.str @a))
(implements str Uint64Extra.str)
(defn prn [a] (Uint64.prn @a))
(implements prn Uint64Extra.prn)
)
2020-11-05 18:45:33 +03:00
(defmodule Pointer
2020-12-09 08:19:07 +03:00
(register strp (Fn [(Ptr a)] String) "Pointer_strp")
(defn str [a] (Pointer.strp a))
2020-11-05 18:45:33 +03:00
(implements str Pointer.str)
2020-12-09 08:19:07 +03:00
(defn prn [a] (Pointer.strp a))
(implements prn Pointer.prn)
2020-11-11 08:58:41 +03:00
)
2020-11-28 14:53:18 +03:00
(defndynamic build-str* [forms]
(if (= (length forms) 0)
2021-01-21 08:20:03 +03:00
'("")
2020-11-28 14:53:18 +03:00
(if (= (length forms) 1)
2021-01-21 08:20:03 +03:00
`&(str %(car forms))
`&(String.append &(str %(car forms)) %(build-str* (cdr forms))))))
2020-11-28 14:53:18 +03:00
(defmacro str* [:rest forms]
2021-01-21 08:20:03 +03:00
`(copy %(build-str* forms)))
2021-03-15 18:22:10 +03:00
(defmodule Dynamic
(defmodule String
(defndynamic empty? [s]
(= (String.length s) 0))
(defndynamic to-list [s]
(if (String.empty? s)
'()
(cons (String.head s) (String.to-list (String.tail s)))))
)
)
2021-06-16 10:45:32 +03:00