Rename List.push to List.append

This commit is contained in:
Chad Stearns 2020-07-25 03:43:52 -04:00
parent 0b078783fd
commit 759f1289d6
11 changed files with 29 additions and 29 deletions

View file

@ -510,9 +510,9 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
), ),
); );
// push : List elem -> elem -> List elem // append : List elem -> elem -> List elem
add_type( add_type(
Symbol::LIST_PUSH, Symbol::LIST_APPEND,
SolvedType::Func( SolvedType::Func(
vec![list_type(flex(TVAR1)), flex(TVAR1)], vec![list_type(flex(TVAR1)), flex(TVAR1)],
Box::new(list_type(flex(TVAR1))), Box::new(list_type(flex(TVAR1))),

View file

@ -669,13 +669,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
) )
}); });
// push : Attr * (List a) // append : Attr * (List a)
// , a // , a
// -> Attr * (List a) // -> Attr * (List a)
// //
// NOTE: we demand the new item to have the same uniqueness as the other list items. // NOTE: we demand the new item to have the same uniqueness as the other list items.
// It could be allowed to add unique items to shared lists, but that requires special code gen // It could be allowed to add unique items to shared lists, but that requires special code gen
add_type(Symbol::LIST_PUSH, { add_type(Symbol::LIST_APPEND, {
let_tvars! { a, star1, star2 }; let_tvars! { a, star1, star2 };
unique_function( unique_function(

View file

@ -53,7 +53,7 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap<Symbol, Def> {
Symbol::LIST_LEN => list_len, Symbol::LIST_LEN => list_len,
Symbol::LIST_GET => list_get, Symbol::LIST_GET => list_get,
Symbol::LIST_SET => list_set, Symbol::LIST_SET => list_set,
Symbol::LIST_PUSH => list_push, Symbol::LIST_APPEND => list_append,
Symbol::LIST_FIRST => list_first, Symbol::LIST_FIRST => list_first,
Symbol::LIST_IS_EMPTY => list_is_empty, Symbol::LIST_IS_EMPTY => list_is_empty,
Symbol::LIST_SINGLE => list_single, Symbol::LIST_SINGLE => list_single,
@ -856,13 +856,13 @@ fn list_set(symbol: Symbol, var_store: &mut VarStore) -> Def {
) )
} }
/// List.push : List elem, elem -> List elem /// List.append : List elem, elem -> List elem
fn list_push(symbol: Symbol, var_store: &mut VarStore) -> Def { fn list_append(symbol: Symbol, var_store: &mut VarStore) -> Def {
let list_var = var_store.fresh(); let list_var = var_store.fresh();
let elem_var = var_store.fresh(); let elem_var = var_store.fresh();
let body = RunLowLevel { let body = RunLowLevel {
op: LowLevel::ListPush, op: LowLevel::ListAppend,
args: vec![ args: vec![
(list_var, Var(Symbol::ARG_1)), (list_var, Var(Symbol::ARG_1)),
(elem_var, Var(Symbol::ARG_2)), (elem_var, Var(Symbol::ARG_2)),

View file

@ -1820,7 +1820,7 @@ fn run_low_level<'a, 'ctx, 'env>(
} }
} }
ListConcat => list_concat(env, layout_ids, scope, parent, args), ListConcat => list_concat(env, layout_ids, scope, parent, args),
ListPush => { ListAppend => {
// List.push List elem, elem -> List elem // List.push List elem, elem -> List elem
debug_assert_eq!(args.len(), 2); debug_assert_eq!(args.len(), 2);

View file

@ -38,10 +38,10 @@ mod gen_list {
} }
#[test] #[test]
fn list_push() { fn list_append() {
assert_evals_to!("List.push [1] 2", &[1, 2], &'static [i64]); assert_evals_to!("List.append [1] 2", &[1, 2], &'static [i64]);
assert_evals_to!("List.push [1, 1] 2", &[1, 1, 2], &'static [i64]); assert_evals_to!("List.append [1, 1] 2", &[1, 1, 2], &'static [i64]);
assert_evals_to!("List.push [] 3", &[3], &'static [i64]); assert_evals_to!("List.append [] 3", &[3], &'static [i64]);
assert_evals_to!( assert_evals_to!(
indoc!( indoc!(
r#" r#"
@ -49,19 +49,19 @@ mod gen_list {
initThrees = initThrees =
[] []
List.push (List.push initThrees 3) 3 List.append (List.append initThrees 3) 3
"# "#
), ),
&[3, 3], &[3, 3],
&'static [i64] &'static [i64]
); );
assert_evals_to!( assert_evals_to!(
"List.push [ True, False ] True", "List.append [ True, False ] True",
&[true, false, true], &[true, false, true],
&'static [bool] &'static [bool]
); );
assert_evals_to!( assert_evals_to!(
"List.push [ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ] 23", "List.append [ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ] 23",
&[11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], &[11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
&'static [i64] &'static [i64]
); );

View file

@ -54,7 +54,7 @@ reconstructPath = \cameFrom, goal ->
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
updateCost : position, position, Model position -> Model position updateCost : position, position, Model position -> Model position
updateCost = \current, neighbour, model -> updateCost = \current, neighbour, model ->

View file

@ -54,7 +54,7 @@ reconstructPath = \cameFrom, goal ->
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
updateCost : position, position, Model position -> Model position updateCost : position, position, Model position -> Model position
updateCost = \current, neighbour, model -> updateCost = \current, neighbour, model ->

View file

@ -11,7 +11,7 @@ pub enum LowLevel {
ListRepeat, ListRepeat,
ListReverse, ListReverse,
ListConcat, ListConcat,
ListPush, ListAppend,
NumAdd, NumAdd,
NumSub, NumSub,
NumMul, NumMul,

View file

@ -648,7 +648,7 @@ define_builtins! {
2 LIST_IS_EMPTY: "isEmpty" 2 LIST_IS_EMPTY: "isEmpty"
3 LIST_GET: "get" 3 LIST_GET: "get"
4 LIST_SET: "set" 4 LIST_SET: "set"
5 LIST_PUSH: "push" 5 LIST_APPEND: "append"
6 LIST_MAP: "map" 6 LIST_MAP: "map"
7 LIST_LEN: "len" 7 LIST_LEN: "len"
8 LIST_FOLDL: "foldl" 8 LIST_FOLDL: "foldl"

View file

@ -2362,7 +2362,7 @@ mod solve_expr {
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
reconstructPath reconstructPath
"# "#
@ -2534,7 +2534,7 @@ mod solve_expr {
x = [] x = []
when List.get input 0 is when List.get input 0 is
Ok val -> List.push x val Ok val -> List.append x val
Err _ -> f input Err _ -> f input
f f
"# "#

View file

@ -2275,9 +2275,9 @@ mod solve_uniq_expr {
} }
#[test] #[test]
fn list_push() { fn list_append() {
infer_eq( infer_eq(
"List.push", "List.append",
"Attr * (Attr * (List a), a -> Attr * (List a))", "Attr * (Attr * (List a), a -> Attr * (List a))",
); );
} }
@ -2303,7 +2303,7 @@ mod solve_uniq_expr {
infer_eq( infer_eq(
indoc!( indoc!(
r#" r#"
singleton = \x -> List.push [] x singleton = \x -> List.append [] x
singleton singleton
"# "#
@ -2317,7 +2317,7 @@ mod solve_uniq_expr {
infer_eq( infer_eq(
indoc!( indoc!(
r#" r#"
reverse = \list -> List.foldr list (\e, l -> List.push l e) [] reverse = \list -> List.foldr list (\e, l -> List.append l e) []
reverse reverse
"# "#
@ -2742,7 +2742,7 @@ mod solve_uniq_expr {
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
reconstructPath reconstructPath
"# "#
@ -2812,7 +2812,7 @@ mod solve_uniq_expr {
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
updateCost : position, position, Model position -> Model position updateCost : position, position, Model position -> Model position
updateCost = \current, neighbour, model -> updateCost = \current, neighbour, model ->
@ -2897,7 +2897,7 @@ mod solve_uniq_expr {
[] []
Ok next -> Ok next ->
List.push (reconstructPath cameFrom next) goal List.append (reconstructPath cameFrom next) goal
updateCost : position, position, Model position -> Model position updateCost : position, position, Model position -> Model position