Return values

Finally, when a block returns a value, you can call its block variable like a function.

d​o​u​b​l​e​ ​(​^​d​i​v​B​l​o​c​k​)​(​d​o​u​b​l​e​,​d​o​u​b​l​e​)​ ​=​ ​^​(​d​o​u​b​l​e​ ​k​,​ ​d​o​u​b​l​e​ ​j​)​ ​{​
 ​ ​ ​ ​r​e​t​u​r​n​ ​k​/​j​;​
}​

In this code, you’ve declared divBlock as a block variable that returns a double and expects two doubles as arguments. Then you assigned it a value which includes the instruction to return the result of dividing the two arguments.

You can use this block like so:

d​o​u​b​l​e​ ​q​u​o​t​i​e​n​t​ ​=​ ​d​i​v​B​l​o​c​k​(​4​2​.​0​,​ ​1​2​.​5​)​;​
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset