Defining generated functions

Generated functions are functions that are prefixed by @generated at the function definition. These functions can return expression objects, just like macros. For example, we can define the doubled function as follows:

@generated function doubled(x)
return :( 2 * x )
end

Let's quickly run a test and make sure that it works:

The code works beautifully, as expected.

So defining generated functions is quite similar to defining macros. In both cases, we can create an expression object and return it, and we can expect the expression to be evaluated properly.

We have not, however, exercised the full power of generated functions yet. Next, we will look at how data type information can be made available and how it can be used within generated functions.

..................Content has been hidden....................

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