]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
Add undocumented functions in Prelude.scl to Prelude.md
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index 818c5054307e95d5ad67bd3b211882fd9dc9befb..f2c24276510635390abee532e46f960547e381e9 100644 (file)
@@ -123,6 +123,7 @@ uncurry3 f (x, y, z) = f x y z
 flip :: (a -> b -> <e> c) -> b -> a -> <e> c
 flip f x y =  f y x
 
+"Swaps the order of elements of a pair (2-tuple)."
 swap :: (a,b) -> (b,a)
 swap (x,y) = (y,x)
 
@@ -1065,6 +1066,15 @@ mapEither f list = runProc do
         Right v -> addArrayList r v)
     (Java.unsafeCoerce l, Java.unsafeCoerce r)
 
+"`replicate n v` returns a list of length `n` such that each element is a copy of `v`."
+@inline
+replicate :: Integer -> a -> [a]
+replicate n v = build (\empty cons ->
+    let aux 0 l = l
+        aux i l = aux (i-1) (cons l v)
+    in aux n empty 
+    )
+
 /// FunctorM ///
 
 class (Functor f) => FunctorM f where
@@ -1408,6 +1418,17 @@ instance Read String where
 splitString :: String -> String -> [String]
 splitString source pattern = arrayToList $ splitString_ source pattern
 
+"""
+`split pattern text` splits `text` around matches of the given regular expression `pattern`.
+
+This function works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
+
+The string "boo:and:foo", for example, yields the following results with these expressions:
+
+    Regex   Result
+    :       { "boo", "and", "foo" }
+    o       { "b", "", ":and:f" }
+"""
 split :: String -> String -> [String]
 split pattern text = arrayToList $ splitString_ text pattern
 
@@ -2123,7 +2144,7 @@ importJava "org.simantics.scl.runtime.procedure.Procedures" where
     
     "Executes the given expression and catches certain class of exceptions (specified by the catch handler that is given as a second parameter.)"
     @JavaName catch_
-    catch :: VecComp ex => (<e> a) -> (ex -> <e> a) -> <e> a
+    catch :: VecComp ex => (<e,Exception> a) -> (ex -> <e> a) -> <e> a
 
 importJava "java.lang.Throwable" where
     data Throwable