-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Multiple Replacement | ||
|
||
It is easy to replace one string with another in meow. However, when you want to replace multiple strings with multiple strings, it is not that easy. This is because the replacement is done in a single pass. | ||
|
||
For example, | ||
|
||
```catlet | ||
> let "a" "b" let "c" "a" "ac" | ||
bb | ||
``` | ||
|
||
We want to replace `a` with `b` and `c` with `a`. However, the replacement is done in a single pass, so the first replacement is done, and then the second replacement is done. So, the result is `bb`. | ||
|
||
What if we want to do the replacement simultaneously? It's not easy to see. | ||
|
||
This feature doesn't need i expression and it is originally designed to be supported in catlet. | ||
|
||
First, we have to make sure that the multiple strings are all **independent**. Otherwise the result is not expected. | ||
|
||
Implementation code for 2 strings: | ||
|
||
```meow | ||
enraw(s) { | ||
"_^" = ""; | ||
"_$" = ""; | ||
encode(s) | ||
} | ||
enrep(s,x,y) { | ||
enraw(x) = y; | ||
s | ||
} | ||
rep2(s,x,xr,y,yr) { | ||
var repx = enrep(encode(s),x,"x$"); | ||
var repy = enrep(repx,y,"y$"); | ||
decode({ | ||
"x$" = enraw(xr); | ||
"y$" = enraw(yr); | ||
repy | ||
}) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eat x w = x | ||
head x = ! cat cat `eat "` let " " `" eat "` x `" ""` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eat(x,w) { | ||
x | ||
} | ||
|
||
head(x) { | ||
var xx = {" " = `" eat "`; x}; | ||
!(`eat "` + xx + `" ""`) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters