mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
fe2e3fb9c8
* numbers are no longer auto converted to booleans, use to_boolean or != 0
* booleans are no longer auto converted to numbers, use to_int
* strings will soon no longer be auto converted to numbers, use to_int
Added version information ("since 0.3.7") to documentation
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1006 0fc631ac-6414-0410-93d0-97cfa31319b6
42 lines
1.9 KiB
Plaintext
42 lines
1.9 KiB
Plaintext
Default arguments
|
|
|
|
DOC_MSE_VERSION: since 0.3.7
|
|
|
|
It is possible to declare default arguments for functions using the @@@@ operator.
|
|
> function := { "argument was: " + arg }@(arg:"default")
|
|
If this function is called without the @arg@ argument, then the default value @"default"@ is used instead.
|
|
For example:
|
|
> function() == "argument was: default"
|
|
> function(arg: "something else") == "argument was: something else"
|
|
|
|
For determining whether the argument is set only explicit arguments count, not everything in scope, so
|
|
> arg := "something else"
|
|
> function() == "argument was: default"
|
|
|
|
Defaults are evaluated at the time the @@@@ operator is evaluated, they will not be overriden later
|
|
> default := "old default"
|
|
> function := { "argument was: " + arg }@(arg: default)
|
|
> default := "new default"
|
|
> function() == "argument was: old default"
|
|
|
|
--Rule functions--
|
|
|
|
DOC_MSE_VERSION: until 0.3.6
|
|
|
|
In earlier versions of MSE some functions were available in a special ''rule form''.
|
|
A call to for example @replace_rule(match:"abc",replace:"xyz")@ is equivalent to @replace@@(match:"abc",replace:"xyz")@ .
|
|
For backwards compatability these functions are still available, but they should not be used for new templates.
|
|
|
|
Programming in a ''rule style'' is still very useful.
|
|
A rule is like a normal function with all parameters given, except for the @input@.
|
|
These rules can then be combined using the @+@ operator, for example:
|
|
> # First all "a"s are replaced, then all "b"s.
|
|
> remove_as_and_bs := replace@(match: "a", replace: "") +
|
|
> replace@(match: "b", replace: "")
|
|
>
|
|
> text_with_as_and_bs := "bla bla bla"
|
|
> text_without_as_and_bs := remove_as_and_bs(text_with_as_and_bs)
|
|
|
|
|
|
<div style="text-align:right;">previous: <a href="functions">← Functions</a> | next: <a href="control_structures">Control structures →</a></div>
|