[Block] set: [name] value: [object] | Manual

[Block] set: [name] value: [object]

Sets a variable in a block of code. This how you can get closure-like functionality.
Usage:


 shout := { Pen write: (my message + '!!!'). }.
 shout set: 'message' value: 'hello'.
 shout run.

 Here we assign a block to a variable named 'shout'.
 We assign the string 'hello' to the variable 'message' inside the block.
 When we invoke the block 'shout' by sending the run message without any
 arguments it will display the string: 'hello!!!'.

 Similarly, you could use this technique to create a block that returns a
 block that applies a formula (for instance simple multiplication) and then set the
 multiplier to use in the formula. This way, you could create a block
 building 'formula blocks'. This is how you implement use closures
 in Citrine.

back to homepage
back to manual menu

This API reference guide has been generated automatically from source code comments using the shtml.ctr script.