Skip to content

Commit f55e62b

Browse files
committed
fixed escaped in RAP12
1 parent cdafb29 commit f55e62b

File tree

1 file changed

+17
-11
lines changed
  • courses/RascalAmendmentProposals/RAP12

1 file changed

+17
-11
lines changed

courses/RascalAmendmentProposals/RAP12/RAP12.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,26 @@ sidebar_position: 12
1414

1515
1. Visit behaves very differently on strings than on other values. Namely when a value of String is reached, it generates all tails of the string and executes all patterns on these tails.
1616
1. This is considerably different from the visit behavior on other “containers” such as lists, sets and maps. Visit simply traverses each element in isolation and not “all tails”.
17-
2. The fact that a string is treated as a container is inconsistent with other language feature such as the generator \`\<-\` syntax. There we do not iterate over all tails of a list, for example.
18-
3. The implementation in the interpreter switches to this special string behavior if the **dynamic typ**e of the \_subject\_ is a string. This contradicts compiler behavior which should select which kind of visit is necessary based on static information.
19-
4. If you are simply using visit to visit all sub-values, it can be very surprising that the string tail visiting behavior is triggered. For example, when a \`case value x: i+=1;\` simply counts all values in the tree, the total count would be augmented with an increment for every tail of every string (\!\!\!). This is counterintuitive.
17+
2. The fact that a string is treated as a container is inconsistent with other language feature such as the generator `<-` syntax. There we do not iterate over all tails of a list, for example.
18+
3. The implementation in the interpreter switches to this special string behavior if the **dynamic typ**e of the _subject_ is a string. This contradicts compiler behavior which should select which kind of visit is necessary based on static information.
19+
4. If you are simply using visit to visit all sub-values, it can be very surprising that the string tail visiting behavior is triggered. For example, when a `case value x: i+=1;` simply counts all values in the tree, the total count would be augmented with an increment for every tail of every string (\!\!\!). This is counterintuitive.
2020

2121

2222
### Analysis
2323

2424
2. There seems to be a case of “too much overloading” of the visit syntax. We do need this kind of power to edit strings concisely, but editing strings is not simply a special case of recursively visiting a data-structure. For strings we need additional semantics (a cursor inside of the string)
25-
3. It would be easy to separate the functionality into one \`edit\` statement and a \`visit\` statement, where \`visit\` would behave as before but not dive into tails of strings, and \`edit\` would behave as \`visit\` behaves now on strings (namely to visit all tails).
25+
3. It would be easy to separate the functionality into one `edit` statement and a `visit` statement, where `visit` would behave as before but not dive into tails of strings, and `edit` would behave as `visit` behaves now on strings (namely to visit all tails).
2626

2727
### Solution proposal
2828

2929
Introduce a new type of statement/expression for editing strings:
3030

31-
result \= **edit**(subject) {
32-
**case** “string” \=\> “string”
33-
**case** /regex/ \=\> regex
31+
```rascal
32+
result = edit(subject) {
33+
case “string” => “string”
34+
case /regex/ => regex
3435
}
36+
```
3537

3638
* The subject should (statically) be a string
3739
* Cases of an edit statement should be either literal strings or regular expressions
@@ -42,17 +44,21 @@ This is exactly the same as how visit currently works on strings.
4244

4345
This example shows what would happen:
4446

45-
result \= **edit**(“aaa”) {
46-
**case** “a” \=\> “b”
47+
```rascal
48+
result = edit(“aaa”) {
49+
case “a” => “b”
4750
}
51+
```
4852

4953
This would return “bbb”, since “a” matches at all cursor positions.
5054

5155
Contrarily the following visit statement would behave differently:
5256

53-
result \= **visit** (“aaa”) {
54-
**case** “a” \=\> “b”
57+
```rascal
58+
result = visit (“aaa”) {
59+
case “a” => “b”
5560
}
61+
```
5662

5763
Would return “aaa” since no value matched the “a” pattern. Only entire strings “a” would be replaced by “b” and strings such as “aaa” will remain unchanged.
5864

0 commit comments

Comments
 (0)