core: document string, remove string-join

This commit is contained in:
hellerve 2018-06-15 16:38:34 +02:00
parent 5ba320a0d4
commit c82916612a
8 changed files with 18 additions and 24 deletions

View File

@ -24,7 +24,7 @@
(doc from-chars "Creates a pattern that matches a group of characters from a list of those characters.")
(defn from-chars [chars]
(Pattern.init &(string-join @"[" (String.from-chars chars) @"]")))
(Pattern.init &(str* @"[" (String.from-chars chars) @"]")))
)
(defmodule String

View File

@ -36,10 +36,12 @@
(set! str (append &str inpt)))
str)))
(doc pad-left "Pads the left of a string with len bytes using the padding pad.")
(defn pad-left [len pad s]
(let [x (Int.max 0 (- len (length s)))]
(append &(from-chars &(Array.replicate x &pad)) s)))
(doc pad-right "Pads the right of a string with len bytes using the padding pad.")
(defn pad-right [len pad s]
(let [x (Int.max 0 (- len (length s)))]
(append s &(from-chars &(Array.replicate x &pad)))))
@ -75,7 +77,7 @@
(defn starts-with? [s sub]
(= sub &(prefix-string s (length sub))))
(doc starts-with? "Check if the string `s` ends with the string `sub`.")
(doc ends-with? "Check if the string `s` ends with the string `sub`.")
(defn ends-with? [s sub]
(= sub &(suffix-string s (- (length s) (length sub)))))
@ -147,6 +149,8 @@
(defmodule StringCopy
(register append (Fn [String String] String))
(defn str [s] (the String s))
(defn = [a b]
(String.= &a &b))
@ -154,15 +158,6 @@
(String./= &a &b))
)
(defdynamic string-join- [strs]
(if (= (length strs) 0)
'(String.copy "")
(list 'StringCopy.append (car strs) (string-join- (cdr strs)))))
;; TODO: Remove this function and replace uses with 'str*'
(defmacro string-join [:rest strs]
(string-join- strs))
(defmodule Bool
(register str (Fn [Bool] String))
(register format (Fn [&String Bool] String))

View File

@ -51,15 +51,15 @@
(if (op expected actual)
(do
(IO.color "green")
(IO.println &(string-join @"Test '" @descr @"' passed"))
(IO.println &(str* @"Test '" @descr @"' passed"))
(IO.color "reset")
(State.update-passed (State.copy state) Int.inc))
(do
(IO.color "red")
(IO.println &(string-join @"Test '" @descr @"' failed:"))
(IO.print &(string-join @"\tExpected " @what @": '"))
(IO.println &(str* @"Test '" @descr @"' failed:"))
(IO.print &(str* @"\tExpected " @what @": '"))
(IO.print &(str expected))
(IO.println &(string-join @"', actual value: '" (str actual) @"'"))
(IO.println &(str* @"', actual value: '" (str actual) @"'"))
(IO.color "reset")
(State.update-failed (State.copy state) Int.inc))))

View File

@ -17,7 +17,7 @@
(V2.set-y o v))
(defn to-string [o]
(string-join @"Vector2(" (str @(V2.x o)) @", " (str @(V2.y o)) @")"))
(str* @"Vector2(" (str @(V2.x o)) @", " (str @(V2.y o)) @")"))
(defn zero []
(V2.init 0.0 0.0))
@ -120,8 +120,8 @@
(V3.init x y z))
(defn to-string [o]
(string-join @"Vector3(" (str @(V3.x o)) @", " (str @(V3.y o))
@", " (str @(V3.z o)) @")"))
(str* @"Vector3(" (str @(V3.x o)) @", " (str @(V3.y o))
@", " (str @(V3.z o)) @")"))
(defn zero []
(V3.init 0.0 0.0 0.0))
@ -233,8 +233,7 @@
(defn to-string [o]
(string-join @"VectorN(dim=" (str @(VN.n o)) @", vals=" (str (VN.v o))
@")"))
(str* @"VectorN(dim=" (str @(VN.n o)) @", vals=" (str (VN.v o)) @")"))
(defn zip- [f a b]
(let [total []]

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<html><head><meta charset="UTF-8"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"><link href="carp_style.css" rel="stylesheet"></head><body><div class="content"><div class="logo"><a href="http://github.com/carp-lang/Carp"><img src="logo.png"></a><div class="title">core</div><div class="index"><ul><li><a href="Dynamic.html">Dynamic</a></li><li><a href="Int.html">Int</a></li><li><a href="Long.html">Long</a></li><li><a href="Bool.html">Bool</a></li><li><a href="Float.html">Float</a></li><li><a href="Double.html">Double</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="V2.html">V2</a></li><li><a href="Vector3.html">Vector3</a></li><li><a href="V3.html">V3</a></li><li><a href="VectorN.html">VectorN</a></li><li><a href="VN.html">VN</a></li><li><a href="Geometry.html">Geometry</a></li><li><a href="Statistics.html">Statistics</a></li><li><a href="String.html">String</a></li><li><a href="Char.html">Char</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="Array.html">Array</a></li><li><a href="IO.html">IO</a></li><li><a href="System.html">System</a></li><li><a href="Debug.html">Debug</a></li><li><a href="Test.html">Test</a></li><li><a href="Bench.html">Bench</a></li><li><a href="Map.html">Map</a></li></ul></div></div><h1>Test</h1><div class="binder"><a href="#State" class="anchor"><h3 id="State">State</h3></a><div class="description">module</div><p class="sig">Module</p><p class="doc"></p></div><div class="binder"><a href="#assert-equal" class="anchor"><h3 id="assert-equal">assert-equal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, a, &amp;String] State)</p><p class="doc">Assert that x and y are equal. Equality needs to be implemented for their type.</p></div><div class="binder"><a href="#assert-exit" class="anchor"><h3 id="assert-exit">assert-exit</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Int, (λ [] ()), &amp;String] State)</p><p class="doc">Assert that function f aborts with OS signal signal.</p></div><div class="binder"><a href="#assert-false" class="anchor"><h3 id="assert-false">assert-false</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Bool, &amp;String] State)</p><p class="doc">Assert that x is false.</p></div><div class="binder"><a href="#assert-not-equal" class="anchor"><h3 id="assert-not-equal">assert-not-equal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, a, &amp;String] State)</p><p class="doc">Assert that x and y are not equal. Equality needs to be implemented for their type.</p></div><div class="binder"><a href="#assert-op" class="anchor"><h3 id="assert-op">assert-op</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, b, &amp;String, (λ [a, b] Bool)] State)</p><p class="doc">Assert that op returns true when given x and y.</p></div><div class="binder"><a href="#assert-signal" class="anchor"><h3 id="assert-signal">assert-signal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Int, (λ [] ()), &amp;String] State)</p><p class="doc"></p></div><div class="binder"><a href="#assert-true" class="anchor"><h3 id="assert-true">assert-true</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Bool, &amp;String] State)</p><p class="doc">Assert that x is true.</p></div><div class="binder"><a href="#print-test-results" class="anchor"><h3 id="print-test-results">print-test-results</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State)] State)</p><p class="doc">Print test results.</p></div><div class="binder"><a href="#reset" class="anchor"><h3 id="reset">reset</h3></a><div class="description">defn</div><p class="sig">(λ [State] State)</p><p class="doc">Reset test state.</p></div></div></body></html>
<html><head><meta charset="UTF-8"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"><link href="carp_style.css" rel="stylesheet"></head><body><div class="content"><div class="logo"><a href="http://github.com/carp-lang/Carp"><img src="logo.png"></a><div class="title">core</div><div class="index"><ul><li><a href="Dynamic.html">Dynamic</a></li><li><a href="Int.html">Int</a></li><li><a href="Long.html">Long</a></li><li><a href="Bool.html">Bool</a></li><li><a href="Float.html">Float</a></li><li><a href="Double.html">Double</a></li><li><a href="Vector2.html">Vector2</a></li><li><a href="V2.html">V2</a></li><li><a href="Vector3.html">Vector3</a></li><li><a href="V3.html">V3</a></li><li><a href="VectorN.html">VectorN</a></li><li><a href="VN.html">VN</a></li><li><a href="Geometry.html">Geometry</a></li><li><a href="Statistics.html">Statistics</a></li><li><a href="String.html">String</a></li><li><a href="Char.html">Char</a></li><li><a href="Pattern.html">Pattern</a></li><li><a href="Array.html">Array</a></li><li><a href="IO.html">IO</a></li><li><a href="System.html">System</a></li><li><a href="Debug.html">Debug</a></li><li><a href="Test.html">Test</a></li><li><a href="Bench.html">Bench</a></li><li><a href="Map.html">Map</a></li></ul></div></div><h1>Test</h1><div class="binder"><a href="#State" class="anchor"><h3 id="State">State</h3></a><div class="description">module</div><p class="sig">Module</p><p class="doc"></p></div><div class="binder"><a href="#assert-equal" class="anchor"><h3 id="assert-equal">assert-equal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, a, &amp;b] State)</p><p class="doc">Assert that x and y are equal. Equality needs to be implemented for their type.</p></div><div class="binder"><a href="#assert-exit" class="anchor"><h3 id="assert-exit">assert-exit</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Int, (λ [] ()), &amp;a] State)</p><p class="doc">Assert that function f aborts with OS signal signal.</p></div><div class="binder"><a href="#assert-false" class="anchor"><h3 id="assert-false">assert-false</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Bool, &amp;a] State)</p><p class="doc">Assert that x is false.</p></div><div class="binder"><a href="#assert-not-equal" class="anchor"><h3 id="assert-not-equal">assert-not-equal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, a, &amp;b] State)</p><p class="doc">Assert that x and y are not equal. Equality needs to be implemented for their type.</p></div><div class="binder"><a href="#assert-op" class="anchor"><h3 id="assert-op">assert-op</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), a, b, &amp;c, (λ [a, b] Bool)] State)</p><p class="doc">Assert that op returns true when given x and y.</p></div><div class="binder"><a href="#assert-signal" class="anchor"><h3 id="assert-signal">assert-signal</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Int, (λ [] ()), &amp;a] State)</p><p class="doc"></p></div><div class="binder"><a href="#assert-true" class="anchor"><h3 id="assert-true">assert-true</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State), Bool, &amp;a] State)</p><p class="doc">Assert that x is true.</p></div><div class="binder"><a href="#print-test-results" class="anchor"><h3 id="print-test-results">print-test-results</h3></a><div class="description">defn</div><p class="sig">(λ [(Ref State)] State)</p><p class="doc">Print test results.</p></div><div class="binder"><a href="#reset" class="anchor"><h3 id="reset">reset</h3></a><div class="description">defn</div><p class="sig">(λ [State] State)</p><p class="doc">Reset test state.</p></div></div></body></html>

View File

@ -18,7 +18,7 @@
(defn main []
(do
(print &(string-join @"P4\n" (str w) @" " (str h) @"\n"))
(print &(str* @"P4\n" (str w) @" " (str h) @"\n"))
(let [iter 50
limit 2.0
byte_acc 0

View File

@ -34,7 +34,7 @@
(exit!)))))
(defn guess-again [low-or-high]
(do (println &(string-join @"Too " @low-or-high @"."))
(do (println &(str* @"Too " @low-or-high @"."))
(print "\nPlease guess again: ")))
(defn main []