Harlowe currently has no built-in method for adding custom TwineScript based macros, the best you do is to place that code in a child passage and then use the (display:) macro to 'execute' that code.
The following example is written using Twee Notation.
:: Parent Passage
(set: $length to 10)
(set: $width to 10)
(display: "Calculate Area")
:: Calculate Area
(set: $area to $length * $width)
One downside of the above technique is that any visual output of the child passage will be added to the visual output of the parent passage, this includes any line-breaks used to format the child passage's code. One way to get around this side-effect is to wrap the (display:) macro call in a named hook and then use CSS to hide all visual contents of that named hook.
a. Change the (display:) macro call to something like the following:
|macro>[(display: "Calculate Area")]
b. Add CSS like the following, that uses a selector based on the above macro named hook, to the Story Stylesheet area of your story.