mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +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))
|
||||
},
|
||||
|
||||
Let(Identifier(name), definition, in_expr) => {
|
||||
Assign(Identifier(name), definition, in_expr) => {
|
||||
if vars.contains_key(&name) {
|
||||
problem(ReassignedVarName(name))
|
||||
} 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!");
|
||||
},
|
||||
|
||||
Let(Fraction(_, _), _, _) => {
|
||||
Assign(Fraction(_, _), _, _) => {
|
||||
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!");
|
||||
},
|
||||
|
||||
Let(Underscore, definition, in_expr) => {
|
||||
Assign(Underscore, definition, in_expr) => {
|
||||
// Faithfully eval this, but discard its result.
|
||||
scoped_eval(*definition, &vars);
|
||||
|
||||
|
@ -105,7 +105,7 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
|||
scoped_eval(*in_expr, vars)
|
||||
},
|
||||
|
||||
Let(Pattern::EmptyRecord, definition, in_expr) => {
|
||||
Assign(Pattern::EmptyRecord, definition, in_expr) => {
|
||||
// Faithfully eval this, but discard its result.
|
||||
scoped_eval(*definition, &vars);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ pub enum Expr {
|
|||
Char(char),
|
||||
|
||||
Var(Ident),
|
||||
Let(Pattern, Box<Expr>, Box<Expr>),
|
||||
Assign(Pattern, Box<Expr>, Box<Expr>),
|
||||
|
||||
// Functions
|
||||
Func(Ident, Vec<Expr>),
|
||||
|
|
|
@ -335,7 +335,7 @@ where I: Stream<Item = char, Position = IndentablePosition>,
|
|||
if in_expr_indent != original_indent {
|
||||
unexpected_any("the return expression was indented differently from the original declaration").left()
|
||||
} 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()
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ mod test_eval {
|
|||
fn string_interpolation() {
|
||||
assert_eq!(
|
||||
eval(
|
||||
Let(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(Let(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
||||
Assign(Identifier("foo".to_string()), Box::new(Str("one".to_string())),
|
||||
Box::new(Assign(Identifier("bar".to_string()), Box::new(Str("two".to_string())),
|
||||
Box::new(Assign(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
||||
Box::new(InterpolatedStr(
|
||||
// "hi_\(foo)_\(bar)_\(baz)_string!"
|
||||
vec![
|
||||
|
|
|
@ -754,7 +754,7 @@ mod test_parse {
|
|||
assert_eq!(
|
||||
parse_standalone("one = Abc\n\ntwo = Bar\n\none"),
|
||||
Ok((
|
||||
Let(
|
||||
Assign(
|
||||
Identifier(
|
||||
"one".to_string()
|
||||
),
|
||||
|
@ -762,7 +762,7 @@ mod test_parse {
|
|||
"Abc".to_string(),
|
||||
None
|
||||
)),
|
||||
Box::new(Let(
|
||||
Box::new(Assign(
|
||||
Identifier(
|
||||
"two".to_string()
|
||||
),
|
||||
|
@ -883,14 +883,14 @@ mod test_parse {
|
|||
);
|
||||
}
|
||||
|
||||
// LET
|
||||
// ASSIGN
|
||||
|
||||
#[test]
|
||||
fn let_with_function_application() {
|
||||
assert_eq!(
|
||||
parse_standalone("abc =\n y 1\n\nabc"),
|
||||
Ok((
|
||||
Let(
|
||||
Assign(
|
||||
Identifier(
|
||||
"abc".to_string()
|
||||
),
|
||||
|
@ -917,7 +917,7 @@ mod test_parse {
|
|||
// let x = 5 in -10
|
||||
parse_standalone("x = 5\n-10"),
|
||||
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
|
||||
parse_standalone("x=5\n-10"),
|
||||
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
|
||||
parse_standalone("x =(5 + 10)\n-20"),
|
||||
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(Int(-20))),
|
||||
"")
|
||||
|
@ -949,7 +949,7 @@ mod test_parse {
|
|||
// let x = 5 + 10 in -20
|
||||
parse_standalone("x= 5 + 10\n-20"),
|
||||
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(Int(-20))),
|
||||
"")
|
||||
|
@ -960,7 +960,7 @@ mod test_parse {
|
|||
// let x = 5 + 10 in -20
|
||||
parse_standalone("x=5\n + 10\n-20"),
|
||||
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(Int(-20))),
|
||||
"")
|
||||
|
@ -982,10 +982,10 @@ mod test_parse {
|
|||
// let x = 5 in let y = 12 in 3
|
||||
parse_standalone("x = 5\ny = 12\n3"),
|
||||
Ok((
|
||||
Let(Identifier("x".to_string()),
|
||||
Assign(Identifier("x".to_string()),
|
||||
Box::new(Int(5)),
|
||||
Box::new(
|
||||
Let(Identifier("y".to_string()), Box::new(Int(12)),
|
||||
Assign(Identifier("y".to_string()), Box::new(Int(12)),
|
||||
Box::new(Int(3))
|
||||
))),
|
||||
"")
|
||||
|
@ -996,14 +996,14 @@ mod test_parse {
|
|||
// let x = 5 in let y = 12 in 3
|
||||
parse_standalone("x = 5 - -3\ny = 12 + 7\n3 * -5"),
|
||||
Ok((
|
||||
Let(Identifier("x".to_string()),
|
||||
Assign(Identifier("x".to_string()),
|
||||
Box::new(
|
||||
Operator(
|
||||
Box::new(Int(5)), Minus, Box::new(Int(-3))
|
||||
)
|
||||
),
|
||||
Box::new(
|
||||
Let(Identifier("y".to_string()),
|
||||
Assign(Identifier("y".to_string()),
|
||||
Box::new(Operator(
|
||||
Box::new(Int(12)), Plus, Box::new(Int(7))
|
||||
)),
|
||||
|
@ -1021,7 +1021,7 @@ mod test_parse {
|
|||
assert_eq!(
|
||||
parse_standalone("x=5\nx"),
|
||||
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!(
|
||||
parse_standalone("f = (x) -> c 1\n\nf"),
|
||||
Ok((
|
||||
Let(
|
||||
Assign(
|
||||
Identifier("f".to_string()),
|
||||
Box::new(Closure(
|
||||
smallvec![Identifier("x".to_string())],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue