Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
intro_example:template_deps [2025/05/02 10:00] – created rajit | intro_example:template_deps [2025/05/07 18:26] (current) – rajit | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Dependent templates ====== | ====== Dependent templates ====== | ||
- | We've already seen how template parameters can be used to construct [[intro_example: | + | We've already seen how template parameters can be used to construct [[intro_example: |
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | defproc test(chan!(int) out) | ||
+ | { | ||
+ | chp { | ||
+ | (; i : N : out!data[i]) | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the example above, the process '' | ||
+ | |||
+ | <code act> | ||
+ | pint x[3]; | ||
+ | x[0] = 1; x[1] = 3; x[2] = 5; | ||
+ | test< | ||
+ | </ | ||
+ | |||
+ | In the above example, the CHP body for instance '' | ||
+ | <code act> | ||
+ | out!1; out!3; out!5 | ||
+ | </ | ||
+ | |||
+ | Dependent templates have //left to right// evaluation order. In the example above this means that '' | ||
+ | <code act> | ||
+ | template< | ||
+ | </ | ||
+ | < | ||
+ | -[ERROR]-> | ||
+ | </ | ||
+ | |||
+ | |||
+ | Parameters can be used in expressions as well. For example, the memory definition in the [[stdlib: | ||
+ | <code act> | ||
+ | export template< | ||
+ | defproc ram (chan? | ||
+ | | ||
+ | { | ||
+ | ... | ||
+ | } | ||
+ | </ | ||
+ | The first template parameter '' | ||