mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Rename Let to Assign
This commit is contained in:
parent
d6bfc42142
commit
41ddfc149b
5 changed files with 26 additions and 26 deletions
12
src/eval.rs
12
src/eval.rs
|
@ -70,7 +70,7 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
||||||
Evaluated(Str(output))
|
Evaluated(Str(output))
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Identifier(name), definition, in_expr) => {
|
Assign(Identifier(name), definition, in_expr) => {
|
||||||
if vars.contains_key(&name) {
|
if vars.contains_key(&name) {
|
||||||
problem(ReassignedVarName(name))
|
problem(ReassignedVarName(name))
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,19 +85,19 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Integer(_), _, _) => {
|
Assign(Integer(_), _, _) => {
|
||||||
panic!("You cannot assign integers to other values!");
|
panic!("You cannot assign integers to other values!");
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Fraction(_, _), _, _) => {
|
Assign(Fraction(_, _), _, _) => {
|
||||||
panic!("You cannot assign fractions to other values!");
|
panic!("You cannot assign fractions to other values!");
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Variant(_name, _patterns), _definition, _in_expr) => {
|
Assign(Variant(_name, _patterns), _definition, _in_expr) => {
|
||||||
panic!("Pattern matching on variants is not yet supported!");
|
panic!("Pattern matching on variants is not yet supported!");
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Underscore, definition, in_expr) => {
|
Assign(Underscore, definition, in_expr) => {
|
||||||
// Faithfully eval this, but discard its result.
|
// Faithfully eval this, but discard its result.
|
||||||
scoped_eval(*definition, &vars);
|
scoped_eval(*definition, &vars);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
||||||
scoped_eval(*in_expr, vars)
|
scoped_eval(*in_expr, vars)
|
||||||
},
|
},
|
||||||
|
|
||||||
Let(Pattern::EmptyRecord, definition, in_expr) => {
|
Assign(Pattern::EmptyRecord, definition, in_expr) => {
|
||||||
// Faithfully eval this, but discard its result.
|
// Faithfully eval this, but discard its result.
|
||||||
scoped_eval(*definition, &vars);
|
scoped_eval(*definition, &vars);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub enum Expr {
|
||||||
Char(char),
|
Char(char),
|
||||||
|
|
||||||
Var(Ident),
|
Var(Ident),
|
||||||
Let(Pattern, Box<Expr>, Box<Expr>),
|
Assign(Pattern, Box<Expr>, Box<Expr>),
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
Func(Ident, Vec<Expr>),
|
Func(Ident, Vec<Expr>),
|
||||||
|
|
|
@ -335,7 +335,7 @@ where I: Stream<Item = char, Position = IndentablePosition>,
|
||||||
if in_expr_indent != original_indent {
|
if in_expr_indent != original_indent {
|
||||||
unexpected_any("the return expression was indented differently from the original declaration").left()
|
unexpected_any("the return expression was indented differently from the original declaration").left()
|
||||||
} else {
|
} else {
|
||||||
value(Expr::Let(var_pattern.to_owned(), Box::new(var_expr), Box::new(in_expr))).right()
|
value(Expr::Assign(var_pattern.to_owned(), Box::new(var_expr), Box::new(in_expr))).right()
|
||||||
}
|
}
|
||||||
}).right()
|
}).right()
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,9 @@ mod test_eval {
|
||||||
fn string_interpolation() {
|
fn string_interpolation() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
eval(
|
eval(
|
||||||
Let(Identifier("foo".to_string()), Box::new(Str("one".to_string())),
|
Assign(Identifier("foo".to_string()), Box::new(Str("one".to_string())),
|
||||||
Box::new(Let(Identifier("bar".to_string()), Box::new(Str("two".to_string())),
|
Box::new(Assign(Identifier("bar".to_string()), Box::new(Str("two".to_string())),
|
||||||
Box::new(Let(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
Box::new(Assign(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
||||||
Box::new(InterpolatedStr(
|
Box::new(InterpolatedStr(
|
||||||
// "hi_\(foo)_\(bar)_\(baz)_string!"
|
// "hi_\(foo)_\(bar)_\(baz)_string!"
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -754,7 +754,7 @@ mod test_parse {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_standalone("one = Abc\n\ntwo = Bar\n\none"),
|
parse_standalone("one = Abc\n\ntwo = Bar\n\none"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(
|
Assign(
|
||||||
Identifier(
|
Identifier(
|
||||||
"one".to_string()
|
"one".to_string()
|
||||||
),
|
),
|
||||||
|
@ -762,7 +762,7 @@ mod test_parse {
|
||||||
"Abc".to_string(),
|
"Abc".to_string(),
|
||||||
None
|
None
|
||||||
)),
|
)),
|
||||||
Box::new(Let(
|
Box::new(Assign(
|
||||||
Identifier(
|
Identifier(
|
||||||
"two".to_string()
|
"two".to_string()
|
||||||
),
|
),
|
||||||
|
@ -883,14 +883,14 @@ mod test_parse {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LET
|
// ASSIGN
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn let_with_function_application() {
|
fn let_with_function_application() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_standalone("abc =\n y 1\n\nabc"),
|
parse_standalone("abc =\n y 1\n\nabc"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(
|
Assign(
|
||||||
Identifier(
|
Identifier(
|
||||||
"abc".to_string()
|
"abc".to_string()
|
||||||
),
|
),
|
||||||
|
@ -917,7 +917,7 @@ mod test_parse {
|
||||||
// let x = 5 in -10
|
// let x = 5 in -10
|
||||||
parse_standalone("x = 5\n-10"),
|
parse_standalone("x = 5\n-10"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Int(-10))),
|
Assign(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Int(-10))),
|
||||||
"")
|
"")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -926,7 +926,7 @@ mod test_parse {
|
||||||
// let x = 5 in 10
|
// let x = 5 in 10
|
||||||
parse_standalone("x=5\n-10"),
|
parse_standalone("x=5\n-10"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Int(-10))),
|
Assign(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Int(-10))),
|
||||||
"")
|
"")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -938,7 +938,7 @@ mod test_parse {
|
||||||
// let x = 5 + 10 in -20
|
// let x = 5 + 10 in -20
|
||||||
parse_standalone("x =(5 + 10)\n-20"),
|
parse_standalone("x =(5 + 10)\n-20"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()),
|
Assign(Identifier("x".to_string()),
|
||||||
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
||||||
Box::new(Int(-20))),
|
Box::new(Int(-20))),
|
||||||
"")
|
"")
|
||||||
|
@ -949,7 +949,7 @@ mod test_parse {
|
||||||
// let x = 5 + 10 in -20
|
// let x = 5 + 10 in -20
|
||||||
parse_standalone("x= 5 + 10\n-20"),
|
parse_standalone("x= 5 + 10\n-20"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()),
|
Assign(Identifier("x".to_string()),
|
||||||
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
||||||
Box::new(Int(-20))),
|
Box::new(Int(-20))),
|
||||||
"")
|
"")
|
||||||
|
@ -960,7 +960,7 @@ mod test_parse {
|
||||||
// let x = 5 + 10 in -20
|
// let x = 5 + 10 in -20
|
||||||
parse_standalone("x=5\n + 10\n-20"),
|
parse_standalone("x=5\n + 10\n-20"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()),
|
Assign(Identifier("x".to_string()),
|
||||||
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
Box::new(Operator(Box::new(Int(5)), Plus, Box::new(Int(10)))),
|
||||||
Box::new(Int(-20))),
|
Box::new(Int(-20))),
|
||||||
"")
|
"")
|
||||||
|
@ -982,10 +982,10 @@ mod test_parse {
|
||||||
// let x = 5 in let y = 12 in 3
|
// let x = 5 in let y = 12 in 3
|
||||||
parse_standalone("x = 5\ny = 12\n3"),
|
parse_standalone("x = 5\ny = 12\n3"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()),
|
Assign(Identifier("x".to_string()),
|
||||||
Box::new(Int(5)),
|
Box::new(Int(5)),
|
||||||
Box::new(
|
Box::new(
|
||||||
Let(Identifier("y".to_string()), Box::new(Int(12)),
|
Assign(Identifier("y".to_string()), Box::new(Int(12)),
|
||||||
Box::new(Int(3))
|
Box::new(Int(3))
|
||||||
))),
|
))),
|
||||||
"")
|
"")
|
||||||
|
@ -996,14 +996,14 @@ mod test_parse {
|
||||||
// let x = 5 in let y = 12 in 3
|
// let x = 5 in let y = 12 in 3
|
||||||
parse_standalone("x = 5 - -3\ny = 12 + 7\n3 * -5"),
|
parse_standalone("x = 5 - -3\ny = 12 + 7\n3 * -5"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()),
|
Assign(Identifier("x".to_string()),
|
||||||
Box::new(
|
Box::new(
|
||||||
Operator(
|
Operator(
|
||||||
Box::new(Int(5)), Minus, Box::new(Int(-3))
|
Box::new(Int(5)), Minus, Box::new(Int(-3))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Box::new(
|
Box::new(
|
||||||
Let(Identifier("y".to_string()),
|
Assign(Identifier("y".to_string()),
|
||||||
Box::new(Operator(
|
Box::new(Operator(
|
||||||
Box::new(Int(12)), Plus, Box::new(Int(7))
|
Box::new(Int(12)), Plus, Box::new(Int(7))
|
||||||
)),
|
)),
|
||||||
|
@ -1021,7 +1021,7 @@ mod test_parse {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_standalone("x=5\nx"),
|
parse_standalone("x=5\nx"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Var("x".to_string()))),
|
Assign(Identifier("x".to_string()), Box::new(Int(5)), Box::new(Var("x".to_string()))),
|
||||||
"")
|
"")
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1042,7 +1042,7 @@ mod test_parse {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_standalone("f = (x) -> c 1\n\nf"),
|
parse_standalone("f = (x) -> c 1\n\nf"),
|
||||||
Ok((
|
Ok((
|
||||||
Let(
|
Assign(
|
||||||
Identifier("f".to_string()),
|
Identifier("f".to_string()),
|
||||||
Box::new(Closure(
|
Box::new(Closure(
|
||||||
smallvec![Identifier("x".to_string())],
|
smallvec![Identifier("x".to_string())],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue