== Extending SCL environment == 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. 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: scl/Test1.scl:
fib :: Integer -> Integer fib x | x <= 1 = 1 | otherwise = fib (x-1) + fib (x-2)A directory is declared as a SCL package with the following kind of extension points defined in org.simantics.scl.runtime:
The module is not automatically available in the console, but you must run an import declaration:
> import "http://www.simantics.org/Tests/Test1" as Test1 > Test1.fib 13 377Import declaration can also be used in modules to refer other modules. Cyclic module dependencies are not allowed. == Importing functionality from Java == Java interfaces and classes can be imported from Java by declaring them inside importJava block:
importJava "java.util.regex.Pattern" where data Pattern importJava "java.util.List" where data List aJava methods, constructors and fields can be similarly imported by giving their type annotations in importJava block:
importJava "java.util.regex.Pattern.compile" where @JavaName compile compilePattern :: String -> Pattern @JavaName matcher createMatcher :: Pattern -> String ->Another example:Matcher importJava "java.util.regex.Matcher" where data Matcher @JavaName matches matcherMatches :: Matcher -> Boolean matches : Pattern -> String -> Boolean matches pattern text = do matcherMatches (createMatcher pattern text)
importJava "java.util.ArrayList" where @JavaName "Java constructor is referred with "" createArrayList :: () -> List a @JavaName " " createArrayListWithCapacity :: Integer -> List a @JavaName size sizeList :: List a -> Integer @JavaName get getList :: List a -> Integer -> a @JavaName set setList :: List a -> Integer -> a -> () @JavaName add addList :: List a -> a -> Boolean