]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.tutorial/scl/Tutorial/4.01 Other language features.md
Import org.simantics.scl.tutorial from incubator SVN repo
[simantics/platform.git] / bundles / org.simantics.scl.tutorial / scl / Tutorial / 4.01 Other language features.md
diff --git a/bundles/org.simantics.scl.tutorial/scl/Tutorial/4.01 Other language features.md b/bundles/org.simantics.scl.tutorial/scl/Tutorial/4.01 Other language features.md
new file mode 100644 (file)
index 0000000..39ddf64
--- /dev/null
@@ -0,0 +1,79 @@
+## Importing functionality from Java\r
+\r
+Java interfaces and classes can be imported from Java by declaring them inside `importJava` block:\r
+\r
+~~~\r
+importJava "java.util.regex.Pattern" where\r
+    data Pattern\r
+\r
+importJava "java.util.List" where\r
+    data List a\r
+~~~\r
+\r
+Java methods, constructors and fields can be similarly imported by giving\r
+their type annotations in `importJava` block:\r
+\r
+~~~\r
+importJava "java.util.regex.Pattern.compile" where\r
+    @JavaName compile\r
+    compilePattern :: String -> Pattern\r
+\r
+    @JavaName matcher\r
+    createMatcher :: Pattern -> String -> <Proc> Matcher\r
+\r
+importJava "java.util.regex.Matcher" where\r
+    data Matcher\r
+\r
+    @JavaName matches\r
+    matcherMatches :: Matcher -> <Proc> Boolean\r
+\r
+matches : Pattern -> String -> <Proc> Boolean\r
+matches pattern text = do\r
+    matcherMatches (createMatcher pattern text)\r
+~~~\r
+\r
+Another example:\r
+\r
+~~~\r
+importJava "java.util.ArrayList" where\r
+    @JavaName "<init>"\r
+    createArrayList :: () -> <Proc> List a\r
+\r
+    @JavaName "<init>"\r
+    createArrayListWithCapacity :: Integer -> <Proc> List a\r
+\r
+    @JavaName size\r
+    sizeList :: List a -> <Proc> Integer\r
+\r
+    @JavaName get\r
+    getList :: List a -> Integer -> <Proc> a\r
+\r
+    @JavaName set\r
+    setList :: List a -> Integer -> a -> <Proc> ()\r
+\r
+    @JavaName add\r
+    addList :: List a -> a -> <Proc> Boolean\r
+~~~\r
+\r
+Java constructor is referred with `"<init>"`. If Java method name and SCL name matches the annotation `@JavaName`\r
+can be left out. Java import mechanism tries to be quite flexible. It provides some arguments based on the effects\r
+the function has. It also ignores the return value of the Java method if the return type is `()` in SCL. \r
+\r
+A major functionality currently still missing is the ability to create new implementations of existing Java interfaces\r
+in SCL code or extend an existing class. This can be worked around currently by writing new implementations in Java.\r
+\r
+## Relational sublanguage \r
+\r
+* Select, when, enforce\r
+* Transformations\r
+\r
+## Other language features\r
+\r
+* Defining data types\r
+* Defining type classes\r
+* Defining effects \r
+* Restricted imports\r
+* Documentation strings\r
+* Private definitions\r
+* Binary operator precedence\r
+\r