-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 27
-
Component/s: hotspot
Currently, name bindings with #-replacement are local to a single template and do not flow into nested templates.
Consider the following:
```java
var outer = Template.make("tmp", (ZeroArg tmp) -> scope(
let("x", 42),
"assert #x == 42",
tmp.asToken()
));
var inner = Template.make(() -> scope("x = #x;");
var token = outer.asToken(inner);
```
This fails because #x has no binding in the inner template.
Therefore, I propose §-replacement, which works exactly like #-replacement with the sole difference that it flows into nested templates.
Consider the example above adopting §-replacement:
```java
var outer = Template.make("tmp", (ZeroArg tmp) -> scope(
letPara("x", 42),
"assert §x == 42",
tmp.asToken()
));
var inner = Template.make(() -> scope("x = §x;");
var token = outer.asToken(inner);
```
The main use for §-replacement is to save on arguments to templates when we want to control the names of variables.
Challenges:
- do #-names and §-names conflict?
- how do we introduce §-bindings (letPara in the example above; other options are promotion of #-bindings to §-bindings)
- is it really nessecary? We have not yet developed idioms for templates. It might turn out that we find other ways of passing names to inner templates to obviate §-bindings.
Consider the following:
```java
var outer = Template.make("tmp", (ZeroArg tmp) -> scope(
let("x", 42),
"assert #x == 42",
tmp.asToken()
));
var inner = Template.make(() -> scope("x = #x;");
var token = outer.asToken(inner);
```
This fails because #x has no binding in the inner template.
Therefore, I propose §-replacement, which works exactly like #-replacement with the sole difference that it flows into nested templates.
Consider the example above adopting §-replacement:
```java
var outer = Template.make("tmp", (ZeroArg tmp) -> scope(
letPara("x", 42),
"assert §x == 42",
tmp.asToken()
));
var inner = Template.make(() -> scope("x = §x;");
var token = outer.asToken(inner);
```
The main use for §-replacement is to save on arguments to templates when we want to control the names of variables.
Challenges:
- do #-names and §-names conflict?
- how do we introduce §-bindings (letPara in the example above; other options are promotion of #-bindings to §-bindings)
- is it really nessecary? We have not yet developed idioms for templates. It might turn out that we find other ways of passing names to inner templates to obviate §-bindings.
- relates to
-
JDK-8344942 Template-Based Testing Framework
-
- Resolved
-