Created Import statement (markdown)
18
Import-statement.md
Normal file
18
Import-statement.md
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
SMNP comes with some predefined modules that make up the standard library.
|
||||||
|
Even though modules will be covered in later chapter, there is need to say something about importing them before moving ahead.
|
||||||
|
|
||||||
|
Modules can be imported with `import` statement, which can be placed only at the top-level of script.
|
||||||
|
It is recommended to use them at the beginning of the script, however it is not required.
|
||||||
|
The `import` statement expects a canonical name of module, which is a sequence of dot-separated identifiers (similar to Java or Python).
|
||||||
|
It is also possible to pass a string literal - it will go through the parser without any errors, however evaluator will throw one. That's because there are plans to enable importing local modules as a simple scripts with SMNP code, which is not supported yet.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
import smnp.io;
|
||||||
|
import smnp.collection;
|
||||||
|
|
||||||
|
println([[1, 2], [3, 4, [5, 6], 7]])
|
||||||
|
```
|
||||||
|
|
||||||
|
All code snippets at the documentation get rid of `import` statements for the sake of readability. Please keep in mind, that if you want to use functions and methods which come from standard library, you need to import correct module, even if it is not presented in the snippet.
|
||||||
|
For example, in order to use `println` or `print` functions, you need to import `smnp.io` module.
|
||||||
Reference in New Issue
Block a user