You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== iclosure ==
Copy Code
The output would be:
Copy Code
The output would be:
Copy Code
The output would be:
Returns a scope isolated closure on the provided code. An iclosure is a datatype that represents some code as code, not the results of some code after it is run. Code placed in an iclosure can be used as a string, or executed by other functions using the execute() function. If a closure is "to string'd" it will not necessarily look like the original code, but will be functionally equivalent. The current environment is "snapshotted" and stored with the closure, however, this information is only stored in memory, it isn't retained during a serialization operation. However, the variable table of the parent scope is not retained, thus making this closure "isolated" from the parent code. The special variable @arguments is automatically created for you, and contains an array of all the arguments passed to the closure, much like procedures. See the wiki article on [[Closures|closures]] for more details and examples.
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| iclosure
|-
! scope="row" | Returns
| iclosure
|-
! scope="row" | Usages
| [params...], code
|-
! scope="row" | Throws
|
|-
! scope="row" | Since
| 3.3.1
|-
! scope="row" | Restricted
| Yes
|-
! scope="row" | Optimizations
| None
|}
=== Usages ===
iclosure([params...], code)=== Examples === ====Example 1==== Creates an iclosure Given the following code:
iclosure(){
msg('Hello World!');
};
Copy Code1 {{keyword|iclosure}}(){
2 {{function|msg}}('Hello World!');
3 };
NOWIKI====Example 2==== Executes an iclosure Given the following code:
execute(iclosure(){
msg('Hello World!');
});
Copy Code1 {{function|execute}}({{keyword|iclosure}}(){
2 {{function|msg}}('Hello World!');
3 });
Hello World!====Example 3==== Shows scoping Given the following code:
@a = 'variable';
msg('Outside of iclosure: '.reflect_pull('varlist'));
// Note that this is an iclosure
execute('val1', iclosure(@b){
msg('Inside of iclosure: '.reflect_pull('varlist'));
});
// Note that this is a regular closure
execute('val2', closure(@c){
msg('Insider of closure: '.reflect_pull('varlist'));
});
Copy Code1 @a = 'variable';
2 {{function|msg}}('Outside of iclosure: '.{{function|reflect_pull}}('varlist'));
3 // Note that this is an iclosure
4
5 {{function|execute}}('val1', {{keyword|iclosure}}(@b){
6 {{function|msg}}('Inside of iclosure: '.{{function|reflect_pull}}('varlist'));
7 });
8 // Note that this is a regular closure
9
10 {{function|execute}}('val2', {{keyword|closure}}(@c){
11 {{function|msg}}('Insider of closure: '.{{function|reflect_pull}}('varlist'));
12 });
Outside of iclosure: {@a} Inside of iclosure: {@b, @arguments} Insider of closure: {@a, @c, @arguments}===See Also=== [[Closures|Learning Trail: Closures]]
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)