# GSiril

### Dynamic assignments

Dynamic assignments were an extension added to the language to make it easier to enter touches in a more natural manner. For example, it would be nice if it were possible to define the symbols, `Cm`, `Pr` and `b` such that the Parker splice between Cambridge and Primrose Surprise Minor could be proved with the following statement.

`prove 3( Cm,b,Cm,Pr,Pr,Cm,Cm,b,Cm,Pr,Pr,Cm,b );`

This is done by allowing the assignment operator (`=`) to be used within expressions being proved. The assignment operator has higher precedence than the comma operator, and it is right-to-left associative (i.e. the expression `a=b=c` is equivalent to `a=(b=c)`.) The assignment only takes effect when the expression is executed during the proof process, and at the end of the proof, all dynamic assignments are reset.

For example, in the following it is used to switch the meaning of the symbol `p` depending on whether the method has a 2nds or 6ths place lead head.

```6 bells;

b = +4;
Cm = &-3-4-2-3-4-5, (p = +2);
Pr = &-3-4-2-3-4-5, (p = +6);

prove 3(Cm,b,Cm,p,Pr,p,Pr,p,Cm,p,Cm,b,Cm,p,Pr,p,Pr,p,Cm,b);```

### A longer example

This syntax can be made more natural by making the `p` symbol optional in the previous example. This is done using another level of dynamic assignments in conjunction with the `final` built-in symbol.

This is done by making the `p` and `b` symbols set the `lh` variable to the lead head change. The `lh` symbol is then evaluated at the start of the next lead. The `final` symbol is used to ensure that the last lead head is included in the composition.

```6 bells;

lh = "\";

start  = "  @ \";
finish = lh, "\n";

p2lh = +2,   "  @ \";
p6lh = +6,   "  @ \";
blh  = +4,   "- @ \";

lh2 = (p = lh=p2lh), (b = lh=blh), (lh=p2lh);
lh6 = (p = lh=p6lh), (b = lh=blh), (lh=p6lh);

Cm = lh, &-3-4-2-3-4-5, lh2, "Cm"; // Cambridge
Pr = lh, &-3-4-2-3-4-5, lh6, "Pr"; // Primrose

prove 3( Cm,b,Cm,Pr,Pr,Cm,Cm,b,Cm,Pr,Pr,Cm,b );
```