Skip to content

Commit

Permalink
use \{..}
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfettes committed Sep 2, 2024
1 parent b54fb00 commit 87ea9c2
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion legacy/examples/avl_tree/lib/avl.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn to_string[U : Show](self : T[U]) -> String {
match self {
Empty => "()"
Node(Empty, v, Empty, _) => v.to_string()
Node(l, v, r, _) => "(\(l), \(v), \(r))"
Node(l, v, r, _) => "(\{l}, \{v}, \{r})"
}
}

Expand Down
2 changes: 1 addition & 1 deletion legacy/examples/avl_tree/main/main.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main {
v = v.add(i)
}
let height = v.height()
println("height of the tree: \(height)")
println("height of the tree: \{height}")
v.print_tree()

// Check values from 0 to iter-1 in the AVL tree
Expand Down
10 changes: 5 additions & 5 deletions moonbit-docs/docs/examples/gmachine-1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ The `PushGlobal` instruction retrieves the address of the specified super combin
fn pushglobal(self : GState, name : String) {
let sc = self.globals[name]
match sc {
None => abort("pushglobal(): cant find super combinator \(name)")
None => abort("pushglobal(): cant find super combinator \{name}")
Some(addr) => {
self.putStack(addr)
}
Expand All @@ -462,7 +462,7 @@ fn pusharg(self : GState, offset : Int) {
let appaddr = nth(self.stack, offset + 1)
let arg = match self.heap[appaddr] {
NApp(_, arg) => arg
otherwise => abort("pusharg: stack offset \(offset) address \(appaddr) node \(otherwise), not a applicative node")
otherwise => abort("pusharg: stack offset \{offset} address \{appaddr} node \{otherwise}, not a applicative node")
}
self.putStack(arg)
}
Expand Down Expand Up @@ -517,7 +517,7 @@ fn unwind(self : GState) {
self.putStack(a)
self.putCode(Cons(Unwind, Nil))
}
otherwise => abort("unwind() : wrong kind of node \(otherwise), address \(addr)")
otherwise => abort("unwind() : wrong kind of node \{otherwise}, address \{addr}")
}
}
```
Expand Down Expand Up @@ -651,9 +651,9 @@ fn reify(self : GState) {
match stack {
Cons(addr, Nil) => {
let res = self.heap[addr]
println("\(res)")
println("\{res}")
}
_ => abort("wrong stack \(stack)")
_ => abort("wrong stack \{stack}")
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions moonbit-docs/docs/examples/gmachine-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn liftArith2(self : GState, op : (Int, Int) -> Int) -> Unit {
let addr = self.heap.alloc(newnode)
self.putStack(addr)
}
(node1, node2) => abort("liftArith2: \(a1) = \(node1) \(a2) = \(node2)")
(node1, node2) => abort("liftArith2: \{a1} = \{node1} \{a2} = \{node2}")
}
}

Expand All @@ -260,7 +260,7 @@ fn liftCmp2(self : GState, op : (Int, Int) -> Bool) -> Unit {
let addr = self.heap.alloc(newnode)
self.putStack(addr)
}
(node1, node2) => abort("liftCmp2: \(a1) = \(node1) \(a2) = \(node2)")
(node1, node2) => abort("liftCmp2: \{a1} = \{node1} \{a2} = \{node2}")
}
}

Expand All @@ -274,7 +274,7 @@ fn negate(self : GState) -> Unit {
}
otherwise => {
// If not NNum, throw an error
abort("negate: wrong kind of node \(otherwise), address \(addr) ")
abort("negate: wrong kind of node \{otherwise}, address \{addr} ")
}
}
}
Expand All @@ -294,7 +294,7 @@ fn condition(self : GState, i1 : List[Instruction], i2 : List[Instruction]) -> U
// If true, jump to i1
self.code = append(i1, self.code)
}
otherwise => abort("cond : \(addr) = \(otherwise)")
otherwise => abort("cond : \{addr} = \{otherwise}")
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion moonbit-docs/docs/examples/gmachine-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn casejump(self : GState, table : List[(Int, List[Instruction])]) -> Unit {
}
}
}
otherwise => abort("casejump(): addr = \(addr) node = \(otherwise)")
otherwise => abort("casejump(): addr = \{addr} node = \{otherwise}")
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions moonbit-docs/docs/examples/lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn subst(self : Term, var : String, term : Term) -> Term {
Abs(variable, body) => {
if freeVars.contains(variable) {
// The variable name is in the set of free variables of the current inner Lambda, indicating variable capture
abort("subst(): error while encountering \(variable)")
abort("subst(): error while encountering \{variable}")
} else {
......
}
Expand Down Expand Up @@ -114,8 +114,8 @@ However, directly writing and reading Lambda terms in de Bruijn index form is pa
fn to_string(self : TermDBI) -> String {
match self {
Var(name, _) => name
Abs(name, body) => "(\\\(name).\(body))"
App(t1, t2) => "\(t1) \(t2)"
Abs(name, body) => "(\\\{name}.\{body})"
App(t1, t2) => "\{t1} \{t2}"
}
}
```
Expand Down Expand Up @@ -214,7 +214,7 @@ fn eval(self : TermDBI) -> TermDBI {
}
}
Abs(_) => self
otherwise => abort("eval(): \(otherwise) ")
otherwise => abort("eval(): \{otherwise} ")
// eval should not encounter free variables
}
}
Expand Down
6 changes: 3 additions & 3 deletions moonbit-docs/docs/examples/myers-diff2.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ fn print_edit(edit : Edit) -> String {
let old_line = pad_right("", line_width)
let new_line = pad_right(edit.new.number.to_string(), line_width)
let text = edit.new.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
Delete(_) as edit => {
let tag = "-"
let old_line = pad_right(edit.old.number.to_string(), line_width)
let new_line = pad_right("", line_width)
let text = edit.old.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
Equal(_) as edit => {
let tag = " "
let old_line = pad_right(edit.old.number.to_string(), line_width)
let new_line = pad_right(edit.new.number.to_string(), line_width)
let text = edit.old.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions moonbit-docs/docs/examples/myers-diff3.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ fn find_path(box : Box, a : Array[Line], b : Array[Line]) -> Iter[(Int, Int)]? {
let end = snake.end;
let headbox = Box { left: box.left, top: box.top, right: start.0, bottom: start.1 };
let tailbox = Box { left: end.0, top: end.1, right: box.right, bottom: box.bottom };
// println("snake = \(snake)")
// println("headbox = \(headbox)")
// println("tailbox = \(tailbox)")
// println("snake = \{snake}")
// println("headbox = \{headbox}")
// println("tailbox = \{tailbox}")
let head = find_path(headbox, a, b).or(Iter::singleton(start));
let tail = find_path(tailbox, a, b).or(Iter::singleton(end));
Some(head.concat(tail))
Expand Down
2 changes: 1 addition & 1 deletion moonbit-docs/docs/examples/sudoku/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn square_to_int(s : String) -> Int {
let col = s[1].to_int() - 49 // '1' <=> 0
return row * 9 + col
} else {
abort("square_to_int(): \(s) is not a square")
abort("square_to_int(): \{s} is not a square")
}
}

Expand Down
2 changes: 1 addition & 1 deletion moonbit-docs/docs/ffi-and-wasm-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn draw(self : Canvas_ctx) -> Unit {
// We also demonstrate the `println` functionality here
pub fn display_pi() -> Unit {
println("PI: \(pi)")
println("PI: \{pi}")
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ PushGlobal指令从全局表中找到指定超组合子的地址,然后将地
fn pushglobal(self : GState, name : String) {
let sc = self.globals[name]
match sc {
None => abort("pushglobal(): cant find supercombinator \(name)")
None => abort("pushglobal(): cant find supercombinator \{name}")
Some(addr) => {
self.putStack(addr)
}
Expand All @@ -467,7 +467,7 @@ fn pusharg(self : GState, offset : Int) {
let appaddr = nth(self.stack, offset + 1)
let arg = match self.heap[appaddr] {
NApp(_, arg) => arg
otherwise => abort("pusharg: stack offset \(offset) address \(appaddr) node \(otherwise), not a applicative node")
otherwise => abort("pusharg: stack offset \{offset} address \{appaddr} node \{otherwise}, not a applicative node")
}
self.putStack(arg)
}
Expand Down Expand Up @@ -522,7 +522,7 @@ fn unwind(self : GState) {
self.putStack(a)
self.putCode(Cons(Unwind, Nil))
}
otherwise => abort("unwind() : wrong kind of node \(otherwise), address \(addr)")
otherwise => abort("unwind() : wrong kind of node \{otherwise}, address \{addr}")
}
}
```
Expand Down Expand Up @@ -660,9 +660,9 @@ fn reify(self : GState) {
match stack {
Cons(addr, Nil) => {
let res = self.heap[addr]
println("\(res)")
println("\{res}")
}
_ => abort("wrong stack \(stack)")
_ => abort("wrong stack \{stack}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn liftArith2(self : GState, op : (Int, Int) -> Int) -> Unit {
let addr = self.heap.alloc(newnode)
self.putStack(addr)
}
(node1, node2) => abort("liftArith2: \(a1) = \(node1) \(a2) = \(node2)")
(node1, node2) => abort("liftArith2: \{a1} = \{node1} \{a2} = \{node2}")
}
}

Expand All @@ -268,7 +268,7 @@ fn liftCmp2(self : GState, op : (Int, Int) -> Bool) -> Unit {
let addr = self.heap.alloc(newnode)
self.putStack(addr)
}
(node1, node2) => abort("liftCmp2: \(a1) = \(node1) \(a2) = \(node2)")
(node1, node2) => abort("liftCmp2: \{a1} = \{node1} \{a2} = \{node2}")
}
}

Expand All @@ -282,7 +282,7 @@ fn negate(self : GState) -> Unit {
}
otherwise => {
// 不是NNum 直接报错
abort("negate: wrong kind of node \(otherwise), address \(addr) ")
abort("negate: wrong kind of node \{otherwise}, address \{addr} ")
}
}
}
Expand All @@ -303,7 +303,7 @@ fn condition(self : GState, i1 : List[Instruction], i2 : List[Instruction]) -> U
// true, 跳转i1
self.code = append(i1, self.code)
}
otherwise => abort("cond : \(addr) = \(otherwise)")
otherwise => abort("cond : \{addr} = \{otherwise}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn casejump(self : GState, table : List[(Int, List[Instruction])]) -> Unit {
}
}
}
otherwise => abort("casejump(): addr = \(addr) node = \(otherwise)")
otherwise => abort("casejump(): addr = \{addr} node = \{otherwise}")
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn subst(self : Term, var : String, term : Term) -> Term {
Abs(variable, body) => {
if freeVars.contains(variable) {
//自由变量集合中有当前这个内层lambda的参数名,即会发生变量捕获
abort("subst(): error while encountering \(variable)")
abort("subst(): error while encountering \{variable}")
} else {
......
}
Expand Down Expand Up @@ -113,8 +113,8 @@ enum TermDBI {
fn to_string(self : TermDBI) -> String {
match self {
VarDBI(name, _) => name
AbsDBI(name, body) => "(\\\(name).\(body))"
AppDBI(t1, t2) => "\(t1) \(t2)"
AbsDBI(name, body) => "(\\\{name}.\{body})"
AppDBI(t1, t2) => "\{t1} \{t2}"
}
}
```
Expand Down Expand Up @@ -142,7 +142,7 @@ struct Index {
// 查找环境中第一个varname对应的整数
fn find(m : List[Index], varname : String) -> Result[Int, String] {
match m {
Nil => Err(varname) // abort("variable \'\(varname)\' not found")
Nil => Err(varname) // abort("variable \'\{varname}\' not found")
Cons(i, rest) => {
if i.name == varname {
Ok(i.depth)
Expand Down Expand Up @@ -201,7 +201,7 @@ fn eval(self : TermDBI) -> TermDBI {
}
}
AbsDBI(_) => self
otherwise => abort("eval(): \(otherwise) ")
otherwise => abort("eval(): \{otherwise} ")
// eval应该不会遇到自由变量才对
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ fn print_edit(edit : Edit) -> String {
let old_line = pad_right("", line_width)
let new_line = pad_right(edit.new.number.to_string(), line_width)
let text = edit.new.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
Delete(_) as edit => {
let tag = "-"
let old_line = pad_right(edit.old.number.to_string(), line_width)
let new_line = pad_right("", line_width)
let text = edit.old.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
Equal(_) as edit => {
let tag = " "
let old_line = pad_right(edit.old.number.to_string(), line_width)
let new_line = pad_right(edit.new.number.to_string(), line_width)
let text = edit.old.text
"\(tag) \(old_line) \(new_line) \(text)"
"\{tag} \{old_line} \{new_line} \{text}"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ fn find_path(box : Box, a : Array[Line], b : Array[Line]) -> Iter[(Int, Int)]? {
let end = snake.end
let headbox = Box::{ left : box.left, top : box.top, right : start.0, bottom : start.1 }
let tailbox = Box::{ left : end.0, top : end.1, right : box.right, bottom : box.bottom }
// println("snake = \(snake)")
// println("headbox = \(headbox)")
// println("tailbox = \(tailbox)")
// println("snake = \{snake}")
// println("headbox = \{headbox}")
// println("tailbox = \{tailbox}")
let head = find_path(headbox, a, b).or(Iter::singleton(start))
let tail = find_path(tailbox, a, b).or(Iter::singleton(end))
Some(head.concat(tail))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn square_to_int(s : String) -> Int {
let col = s[1].to_int() - 49 // '1' <=> 0
return row * 9 + col
} else {
abort("square_to_int(): \(s) is not a square")
abort("square_to_int(): \{s} is not a square")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn draw(self : Canvas_ctx) -> Unit {
// 我们在这里也演示`println`的功能
pub fn display_pi() -> Unit {
println("PI: \(pi)")
println("PI: \{pi}")
}
```

Expand Down

0 comments on commit 87ea9c2

Please sign in to comment.