Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

#### Formal Parameter Exception

The pattern-matching facility is not applied to ordinary formal function parameters . In other words, f(x,y,z)=expression is treated as a function having three formal parameters that are expected to appear literally in expression (e.g., an expression such as x*y+z). This interpretation is in contrast to a function whose input is three parallel block diagrams of arbitrary generality. As a result of this exception, the mere number of formal parameters does not contribute to the uniqueness of a pattern. For example, the following program generates a compile-time error:

```  f(x,y) = f(x) + f(y);  // (x,y) => f(x),f(y):+
f(x) = 2*x;            // (x) => 2,x:*
process = f(3,5);
```
The compiler-error triggered is ``inconsistent number of parameters in pattern-matching rule: (x) => 2,x:*; previous rule was (x,y) => f(x),f(y):+''. On the other hand, the following program outputs the constant signal 16:
```  f((x,y)) = f(x) + f(y);
f(x) = 2*x;
process = f((3,5));
```
The extra parentheses distinguish the pattern (x,y) from formal parameters x,y in this case.

As another example, the following program also outputs the constant signal 16:

```  f(x*y) = f(x) + f(y);
f(x) = 2*x;
process = f(3*5);
```
Since the expression x*y does not look like a list of formal parameters, it doesn't need additional parentheses.

Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search