3 The easiest way of getting started with SCL is to use SCL console that is included in almost all Simantics-based products. You can open the console by pressing ALT-SHIFT-q and then q and choosing "SCL Console" from the list of views.
5 SCL console works by executing commands you write into the input box in the bottom of the view. After the command has been written, it can be executed by pressing ENTER. However, this works only if the command contains no syntactic errors. Possible errors are highlighted in the input box and a description of the error is shown when you move mouse on top of the highlighted text.
7 Multiline commands can be written by pressing CTRL-ENTER (or just ENTER when the current command text contains errors). The command history can be browsed with CTRL-UP and CTRL-DOWN.
9 If the command you write into console results as an ordinary value, it is just printed to the console. Here are couple of examples you can try:
24 You can also declare local variables to be used in the commands:
35 Also new functions can be defined:
42 If you write a command that has side-effects, it is executed in the console:
45 > print "Hello" ; print "world!"
50 SCL is a dialect of Haskell and tutorials written for Haskell can be used for learning the details of the language. The main differences between the languages are the strict evaluation strategy used in SCL and somewhat different standard library. Some Haskell tutorials can be found at [https://wiki.haskell.org/Learning_Haskell](https://wiki.haskell.org/Learning_Haskell).
52 ## Extending SCL environment
54 The SCL values, data types etc. that are available in expressions and commands are defined in SCL modules. Currently all SCL modules must be part of the product plugins (in the future, you can also write modules inside the models). Each module is identified by a URI.
56 SCL module is a text file ending with extension ".scl". The recommended place for modules is scl/ folder under plugin root, but also other directories can be used:
61 fib :: Integer -> Integer
63 | otherwise = fib (x-1) + fib (x-2)
66 A directory is declared as a SCL package with the following kind of extension points defined in org.simantics.scl.runtime:
69 <extension point="org.simantics.scl.runtime.package">
70 <package URI="http://www.simantics.org/Tests"
75 The module is not automatically available in the console, but you must run an import declaration:
78 > import "http://www.simantics.org/Tests/Test1" as Test1
83 Import declaration can also be used in modules to refer other modules. Cyclic module dependencies are not allowed.
85 ## Importing functionality from Java
87 Java interfaces and classes can be imported from Java by declaring them inside importJava block:
90 importJava "java.util.regex.Pattern" where
93 importJava "java.util.List" where
97 Java methods, constructors and fields can be similarly imported by giving
98 their type annotations in importJava block:
101 importJava "java.util.regex.Pattern" where
103 compilePattern :: String -> Pattern
106 createMatcher :: Pattern -> String -> <Proc> Matcher
108 importJava "java.util.regex.Matcher" where
112 matcherMatches :: Matcher -> <Proc> Boolean
114 matches : Pattern -> String -> <Proc> Boolean
115 matches pattern text = do
116 matcherMatches (createMatcher pattern text)
122 importJava "java.util.ArrayList" where
124 createArrayList :: () -> <Proc> List a
127 createArrayListWithCapacity :: Integer -> <Proc> List a
130 sizeList :: List a -> <Proc> Integer
133 getList :: List a -> Integer -> <Proc> a
136 setList :: List a -> Integer -> a -> <Proc> ()
139 addList :: List a -> a -> <Proc> Boolean
142 Java constructor is referred with `<init>`. If Java method name and SCL name matches the annotation @JavaName can be left out. Java import mechanism tries to be quite flexible. It provides some arguments based on the effects the function has. It also ignores the return value of the Java method if return type is `()` in SCL.
144 A major functionality currently still missing is the ability to create new implementations of existing Java interfaces in SCL code or extend an existing class. This can be worked around currently by writing new implementations in Java.