Importing Sheets¶
Once you start creating lots and lots of functions and subroutines, you’ll want to start using them in other sheets you create as well. Why create it multiple times when you can create it once and use it elsewhere?
This is why the Include
property exists. With it, you can include another
sheet by using either it’s absolute path, or it’s path relative to the sheet
including it. Once you do, you then have access to all of the sheet’s
functions, subroutines, and variables.
> my_math.dc
[Function(IsEven, "Check if an integer is even.")]
[FunctionInput(IsEven, num, Integer, 0, "The number to check.")]
[FunctionOutput(IsEven, even, Boolean, "Is the number even?")]
Define(IsEven)~#1
Mod(#1, 2)~#2
Return(IsEven, #2)
[Function(IsOdd, "Check if an integer is odd.")]
[FunctionInput(IsOdd, num, Integer, 0, "The number to check.")]
[FunctionOutput(IsOdd, odd, Boolean, "Is the number odd?")]
Define(IsOdd)~#3
IsEven(#3)~#4
Not(#4)~#5
Return(IsOdd, #5)
[Variable(PI, Float, 3.14159, "You know, THAT number?")]
[Subroutine(AreaOfCircle, "Print the area of a circle, given it's radius.")]
[FunctionInput(AreaOfCircle, radius, Float, 1.0, "The radius of the circle.")]
Define(AreaOfCircle)~#10, #11
PI~#12
Multiply(#11, #11, #12)~#13
Print(#10, "Given a circle with radius:")~#14
Print(#14, #11)~#15
Print(#15, "It's area is:")~#16
Print(#16, #13)
> main.dc
[Include("my_math.dc")]
Start~#1
IsEven(6)~#2
IsOdd(6)~#3
Print(#1, #2)~#4
Print(#4, #3)~#5
Print(#5, "PI is approximately:")~#6
PI~#7
Print(#6, #7)~#8
AreaOfCircle(#8, 2.5)
$ decision main.dc
true
false
PI is approximately:
3.14159
Given a circle with radius:
2.5
It's area is:
19.6349