mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Merge branch 'main' into simplify-refcount
Signed-off-by: Brendan Hansknecht <Brendan.Hansknecht@gmail.com>
This commit is contained in:
commit
7643f89781
131 changed files with 2464 additions and 2148 deletions
|
@ -278,14 +278,14 @@ import pf.Stdin
|
|||
main =
|
||||
Stdout.line! "What's your name?"
|
||||
name = Stdin.line!
|
||||
Stdout.line! "Hi $(name)!""#;
|
||||
Stdout.line! "Hi ${name}!""#;
|
||||
|
||||
const UNFORMATTED_ROC: &str = r#"app [main] { pf: platform "platform/main.roc" }
|
||||
|
||||
main =
|
||||
Stdout.line! "What's your name?"
|
||||
name = Stdin.line!
|
||||
Stdout.line! "Hi $(name)!"
|
||||
Stdout.line! "Hi ${name}!"
|
||||
"#;
|
||||
|
||||
fn setup_test_file(dir: &Path, file_name: &str, contents: &str) -> PathBuf {
|
||||
|
|
|
@ -10,7 +10,7 @@ show = \list ->
|
|||
|> List.map(Num.to_str)
|
||||
|> Str.join_with(", ")
|
||||
|
||||
"[$(content)]"
|
||||
"[${content}]"
|
||||
|
||||
sort_by : List a, (a -> Num *) -> List a
|
||||
sort_by = \list, to_comparable ->
|
||||
|
|
|
@ -25,7 +25,7 @@ show_rb_tree = \tree, show_key, show_value ->
|
|||
s_l = node_in_parens(left, show_key, show_value)
|
||||
s_r = node_in_parens(right, show_key, show_value)
|
||||
|
||||
"Node $(s_color) $(s_key) $(s_value) $(s_l) $(s_r)"
|
||||
"Node ${s_color} ${s_key} ${s_value} ${s_l} ${s_r}"
|
||||
|
||||
node_in_parens : RedBlackTree k v, (k -> Str), (v -> Str) -> Str
|
||||
node_in_parens = \tree, show_key, show_value ->
|
||||
|
@ -36,7 +36,7 @@ node_in_parens = \tree, show_key, show_value ->
|
|||
Node(_, _, _, _, _) ->
|
||||
inner = show_rb_tree(tree, show_key, show_value)
|
||||
|
||||
"($(inner))"
|
||||
"(${inner})"
|
||||
|
||||
show_color : NodeColor -> Str
|
||||
show_color = \color ->
|
||||
|
|
|
@ -8,7 +8,7 @@ snapshot_kind: text
|
|||
|
||||
The get_user function expects 1 argument, but it got 2 instead:
|
||||
|
||||
12│ $(Api.get_user(1, 2))
|
||||
12│ ${Api.get_user(1, 2)}
|
||||
^^^^^^^^^^^^
|
||||
|
||||
Are there any missing commas? Or missing parentheses?
|
||||
|
@ -18,7 +18,7 @@ Are there any missing commas? Or missing parentheses?
|
|||
|
||||
This value is not a function, but it was given 1 argument:
|
||||
|
||||
13│ $(Api.base_url(1))
|
||||
13│ ${Api.base_url(1)}
|
||||
^^^^^^^^^^^^
|
||||
|
||||
Are there any missing commas? Or missing parentheses?
|
||||
|
@ -28,7 +28,7 @@ Are there any missing commas? Or missing parentheses?
|
|||
|
||||
The get_post_comment function expects 2 arguments, but it got only 1:
|
||||
|
||||
16│ $(Api.get_post_comment(1))
|
||||
16│ ${Api.get_post_comment(1)}
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Roc does not allow functions to be partially applied. Use a closure to
|
||||
|
|
|
@ -11,7 +11,7 @@ fn_annotated_as_value definition:
|
|||
|
||||
3│ fn_annotated_as_value : Str
|
||||
4│> fn_annotated_as_value = \post_id, comment_id ->
|
||||
5│> "/posts/$(post_id)/comments/$(Num.to_str(comment_id))"
|
||||
5│> "/posts/${post_id}/comments/${Num.to_str(comment_id)}"
|
||||
|
||||
The body is an anonymous function of type:
|
||||
|
||||
|
@ -28,7 +28,7 @@ Something is off with the body of the missing_arg definition:
|
|||
|
||||
7│ missing_arg : Str -> Str
|
||||
8│> missing_arg = \post_id, _ ->
|
||||
9│> "/posts/$(post_id)/comments"
|
||||
9│> "/posts/${post_id}/comments"
|
||||
|
||||
The body is an anonymous function of type:
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ snapshot_kind: text
|
|||
|
||||
This argument to this string interpolation has an unexpected type:
|
||||
|
||||
10│ "$(Api.get_post)"
|
||||
10│ "${Api.get_post}"
|
||||
^^^^^^^^^^^^
|
||||
|
||||
The argument is an anonymous function of type:
|
||||
|
|
|
@ -12,7 +12,7 @@ main =
|
|||
_: Task.ok(Dict.single("a", "b")),
|
||||
}!
|
||||
|
||||
Stdout.line!("For multiple tasks: $(Inspect.to_str(multiple_in))")
|
||||
Stdout.line!("For multiple tasks: ${Inspect.to_str(multiple_in)}")
|
||||
|
||||
sequential : Task a err, Task b err, (a, b -> c) -> Task c err
|
||||
sequential = \first_task, second_task, mapper ->
|
||||
|
|
|
@ -15,8 +15,8 @@ main! = \{} ->
|
|||
validate! : U32 => Result {} U32
|
||||
validate! = \x ->
|
||||
if Num.is_even(x) then
|
||||
Effect.put_line!("✅ $(Num.to_str(x))")
|
||||
Effect.put_line!("✅ ${Num.to_str(x)}")
|
||||
Ok({})
|
||||
else
|
||||
Effect.put_line!("$(Num.to_str(x)) is not even! ABORT!")
|
||||
Effect.put_line!("${Num.to_str(x)} is not even! ABORT!")
|
||||
Err(x)
|
||||
|
|
|
@ -7,7 +7,7 @@ main! = \{} ->
|
|||
first = ask!("What's your first name?")
|
||||
last = ask!("What's your last name?")
|
||||
|
||||
Effect.put_line!("\nHi, $(first) $(last)!\n")
|
||||
Effect.put_line!("\nHi, ${first} ${last}!\n")
|
||||
|
||||
when Str.to_u8(ask!("How old are you?")) is
|
||||
Err(InvalidNumStr) ->
|
||||
|
@ -17,7 +17,7 @@ main! = \{} ->
|
|||
Effect.put_line!("\nNice! You can vote!")
|
||||
|
||||
Ok(age) ->
|
||||
Effect.put_line!("\nYou'll be able to vote in $(Num.to_str((18 - age))) years")
|
||||
Effect.put_line!("\nYou'll be able to vote in ${Num.to_str(18 - age)} years")
|
||||
|
||||
Effect.put_line!("\nBye! 👋")
|
||||
|
||||
|
|
|
@ -15,5 +15,5 @@ main! = \{} ->
|
|||
else
|
||||
{}
|
||||
|
||||
Effect.put_line!("You entered: $(line)")
|
||||
Effect.put_line!("You entered: ${line}")
|
||||
Effect.put_line!("It is known")
|
||||
|
|
|
@ -18,5 +18,5 @@ main! = \{} ->
|
|||
get_line!: Effect.get_line!,
|
||||
}
|
||||
|
||||
Effect.put_line!("not_effectful: $(not_effectful.get_line!({}))")
|
||||
Effect.put_line!("effectful: $(effectful.get_line!({}))")
|
||||
Effect.put_line!("not_effectful: ${not_effectful.get_line!({})}")
|
||||
Effect.put_line!("effectful: ${effectful.get_line!({})}")
|
||||
|
|
|
@ -7,6 +7,6 @@ main! = \{} ->
|
|||
logged!("hello", \{} -> Effect.put_line!("Hello, World!"))
|
||||
|
||||
logged! = \name, fx! ->
|
||||
Effect.put_line!("Before $(name)")
|
||||
Effect.put_line!("Before ${name}")
|
||||
fx!({})
|
||||
Effect.put_line!("After $(name)")
|
||||
Effect.put_line!("After ${name}")
|
||||
|
|
|
@ -56,7 +56,7 @@ to_str = \{ scopes, stack, state, vars } ->
|
|||
stack_str = Str.join_with(List.map(stack, to_str_data), " ")
|
||||
vars_str = Str.join_with(List.map(vars, to_str_data), " ")
|
||||
|
||||
"\n============\nDepth: $(depth)\nState: $(state_str)\nStack: [$(stack_str)]\nVars: [$(vars_str)]\n============\n"
|
||||
"\n============\nDepth: ${depth}\nState: ${state_str}\nStack: [${stack_str}]\nVars: [${vars_str}]\n============\n"
|
||||
|
||||
with! : Str, (Context => a) => a
|
||||
with! = \path, callback! ->
|
||||
|
|
|
@ -21,7 +21,7 @@ main! = \filename ->
|
|||
{}
|
||||
|
||||
Err(StringErr(e)) ->
|
||||
Stdout.line!("Ran into problem:\n$(e)\n")
|
||||
Stdout.line!("Ran into problem:\n${e}\n")
|
||||
|
||||
interpret_file! : Str => Result {} [StringErr Str]
|
||||
interpret_file! = \filename ->
|
||||
|
@ -44,7 +44,7 @@ interpret_file! = \filename ->
|
|||
Err(StringErr("Ran into an invalid boolean that was neither false (0) or true (-1)"))
|
||||
|
||||
Err(InvalidChar(char)) ->
|
||||
Err(StringErr("Ran into an invalid character with ascii code: $(char)"))
|
||||
Err(StringErr("Ran into an invalid character with ascii code: ${char}"))
|
||||
|
||||
Err(MaxInputNumber) ->
|
||||
Err(StringErr("Like the original false compiler, the max input number is 320,000"))
|
||||
|
|
|
@ -7,4 +7,4 @@ app [main] {
|
|||
import json.JsonParser
|
||||
import csv.Csv
|
||||
|
||||
main = "Hello, World! $(JsonParser.example) $(Csv.example)"
|
||||
main = "Hello, World! ${JsonParser.example} ${Csv.example}"
|
||||
|
|
|
@ -7,4 +7,4 @@ app [main] {
|
|||
import one.One
|
||||
import two.Two
|
||||
|
||||
main = "$(One.example) | $(Two.example)"
|
||||
main = "${One.example} | ${Two.example}"
|
||||
|
|
|
@ -2,4 +2,4 @@ module [example]
|
|||
|
||||
import two.Two
|
||||
|
||||
example = "[One imports Two: $(Two.example)]"
|
||||
example = "[One imports Two: ${Two.example}]"
|
||||
|
|
|
@ -2,4 +2,4 @@ module [example]
|
|||
|
||||
import one.One
|
||||
|
||||
example = "[Zero imports One: $(One.example)]"
|
||||
example = "[Zero imports One: ${One.example}]"
|
||||
|
|
|
@ -14,18 +14,18 @@ module { app_id, protocol } -> [
|
|||
## value def referencing params
|
||||
base_url : Str
|
||||
base_url =
|
||||
protocol("api.example.com/$(app_id)")
|
||||
protocol("api.example.com/${app_id}")
|
||||
|
||||
## function def referencing params
|
||||
get_user : U32 -> Str
|
||||
get_user = \user_id ->
|
||||
# purposefully not using baseUrl to test top-level fn referencing param
|
||||
protocol("api.example.com/$(app_id)/users/$(Num.to_str(user_id))")
|
||||
protocol("api.example.com/${app_id}/users/${Num.to_str(user_id)}")
|
||||
|
||||
## function def referencing top-level value
|
||||
get_post : U32 -> Str
|
||||
get_post = \post_id ->
|
||||
"$(base_url)/posts/$(Num.to_str(post_id))"
|
||||
"${base_url}/posts/${Num.to_str(post_id)}"
|
||||
|
||||
## function def passing top-level function
|
||||
get_posts : List U32 -> List Str
|
||||
|
@ -35,13 +35,13 @@ get_posts = \ids ->
|
|||
## function def calling top-level function
|
||||
get_post_comments : U32 -> Str
|
||||
get_post_comments = \post_id ->
|
||||
"$(get_post(post_id))/comments"
|
||||
"${get_post(post_id)}/comments"
|
||||
|
||||
## function def passing nested function
|
||||
get_companies : List U32 -> List Str
|
||||
get_companies = \ids ->
|
||||
get_company = \id ->
|
||||
protocol("api.example.com/$(app_id)/companies/$(Num.to_str(id))")
|
||||
protocol("api.example.com/${app_id}/companies/${Num.to_str(id)}")
|
||||
|
||||
List.map(ids, get_company)
|
||||
|
||||
|
@ -59,11 +59,11 @@ get_post_aliased =
|
|||
get_user_safe : U32 -> Str
|
||||
get_user_safe =
|
||||
if Str.starts_with(app_id, "prod_") then
|
||||
\id -> "$(get_user(id))?safe=true"
|
||||
\id -> "${get_user(id)}?safe=true"
|
||||
else
|
||||
get_user
|
||||
|
||||
## two-argument function
|
||||
get_post_comment : U32, U32 -> Str
|
||||
get_post_comment = \post_id, comment_id ->
|
||||
"$(get_post(post_id))/comments/$(Num.to_str(comment_id))"
|
||||
"${get_post(post_id)}/comments/${Num.to_str(comment_id)}"
|
||||
|
|
|
@ -2,8 +2,8 @@ module { app_id } -> [fn_annotated_as_value, missing_arg]
|
|||
|
||||
fn_annotated_as_value : Str
|
||||
fn_annotated_as_value = \post_id, comment_id ->
|
||||
"/posts/$(post_id)/comments/$(Num.to_str(comment_id))"
|
||||
"/posts/${post_id}/comments/${Num.to_str(comment_id)}"
|
||||
|
||||
missing_arg : Str -> Str
|
||||
missing_arg = \post_id, _ ->
|
||||
"/posts/$(post_id)/comments"
|
||||
"/posts/${post_id}/comments"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module []
|
||||
|
||||
https = \url -> "https://$(url)"
|
||||
https = \url -> "https://${url}"
|
||||
|
||||
expect
|
||||
import Api { app_id: "one", protocol: https }
|
||||
|
|
|
@ -4,4 +4,4 @@ menu = \name ->
|
|||
indirect(name)
|
||||
|
||||
indirect = \name ->
|
||||
echo("Hi, $(name)!")
|
||||
echo("Hi, ${name}!")
|
||||
|
|
|
@ -6,8 +6,8 @@ import Api { app_id: "one", protocol: https } as App1
|
|||
import Api { app_id: "two", protocol: http } as App2
|
||||
import Api { app_id: "prod_1", protocol: http } as Prod
|
||||
|
||||
https = \url -> "https://$(url)"
|
||||
http = \url -> "http://$(url)"
|
||||
https = \url -> "https://${url}"
|
||||
http = \url -> "http://${url}"
|
||||
|
||||
users_app1 =
|
||||
# pass top-level fn in a module with params
|
||||
|
@ -27,33 +27,33 @@ main =
|
|||
List.map([1, 2, 3], App3.get_user)
|
||||
|
||||
"""
|
||||
App1.baseUrl: $(App1.base_url)
|
||||
App2.baseUrl: $(App2.base_url)
|
||||
App3.baseUrl: $(App3.base_url)
|
||||
App1.getUser 1: $(App1.get_user(1))
|
||||
App2.getUser 2: $(App2.get_user(2))
|
||||
App3.getUser 3: $(App3.get_user(3))
|
||||
App1.getPost 1: $(App1.get_post(1))
|
||||
App2.getPost 2: $(App2.get_post(2))
|
||||
App3.getPost 3: $(App3.get_post(3))
|
||||
App1.getPosts [1, 2]: $(Inspect.to_str(App1.get_posts([1, 2])))
|
||||
App2.getPosts [3, 4]: $(Inspect.to_str(App2.get_posts([3, 4])))
|
||||
App2.getPosts [5, 6]: $(Inspect.to_str(App2.get_posts([5, 6])))
|
||||
App1.getPostComments 1: $(App1.get_post_comments(1))
|
||||
App2.getPostComments 2: $(App2.get_post_comments(2))
|
||||
App2.getPostComments 3: $(App2.get_post_comments(3))
|
||||
App1.getCompanies [1, 2]: $(Inspect.to_str(App1.get_companies([1, 2])))
|
||||
App2.getCompanies [3, 4]: $(Inspect.to_str(App2.get_companies([3, 4])))
|
||||
App2.getCompanies [5, 6]: $(Inspect.to_str(App2.get_companies([5, 6])))
|
||||
App1.getPostAliased 1: $(App1.get_post_aliased(1))
|
||||
App2.getPostAliased 2: $(App2.get_post_aliased(2))
|
||||
App3.getPostAliased 3: $(App3.get_post_aliased(3))
|
||||
App1.baseUrlAliased: $(App1.base_url_aliased)
|
||||
App2.baseUrlAliased: $(App2.base_url_aliased)
|
||||
App3.baseUrlAliased: $(App3.base_url_aliased)
|
||||
App1.getUserSafe 1: $(App1.get_user_safe(1))
|
||||
Prod.getUserSafe 2: $(Prod.get_user_safe(2))
|
||||
usersApp1: $(Inspect.to_str(users_app1))
|
||||
getUserApp3Nested 3: $(get_user_app3_nested(3))
|
||||
usersApp3Passed: $(Inspect.to_str(users_app3_passed))
|
||||
App1.baseUrl: ${App1.base_url}
|
||||
App2.baseUrl: ${App2.base_url}
|
||||
App3.baseUrl: ${App3.base_url}
|
||||
App1.getUser 1: ${App1.get_user(1)}
|
||||
App2.getUser 2: ${App2.get_user(2)}
|
||||
App3.getUser 3: ${App3.get_user(3)}
|
||||
App1.getPost 1: ${App1.get_post(1)}
|
||||
App2.getPost 2: ${App2.get_post(2)}
|
||||
App3.getPost 3: ${App3.get_post(3)}
|
||||
App1.getPosts [1, 2]: ${Inspect.to_str(App1.get_posts([1, 2]))}
|
||||
App2.getPosts [3, 4]: ${Inspect.to_str(App2.get_posts([3, 4]))}
|
||||
App2.getPosts [5, 6]: ${Inspect.to_str(App2.get_posts([5, 6]))}
|
||||
App1.getPostComments 1: ${App1.get_post_comments(1)}
|
||||
App2.getPostComments 2: ${App2.get_post_comments(2)}
|
||||
App2.getPostComments 3: ${App2.get_post_comments(3)}
|
||||
App1.getCompanies [1, 2]: ${Inspect.to_str(App1.get_companies([1, 2]))}
|
||||
App2.getCompanies [3, 4]: ${Inspect.to_str(App2.get_companies([3, 4]))}
|
||||
App2.getCompanies [5, 6]: ${Inspect.to_str(App2.get_companies([5, 6]))}
|
||||
App1.getPostAliased 1: ${App1.get_post_aliased(1)}
|
||||
App2.getPostAliased 2: ${App2.get_post_aliased(2)}
|
||||
App3.getPostAliased 3: ${App3.get_post_aliased(3)}
|
||||
App1.baseUrlAliased: ${App1.base_url_aliased}
|
||||
App2.baseUrlAliased: ${App2.base_url_aliased}
|
||||
App3.baseUrlAliased: ${App3.base_url_aliased}
|
||||
App1.getUserSafe 1: ${App1.get_user_safe(1)}
|
||||
Prod.getUserSafe 2: ${Prod.get_user_safe(2)}
|
||||
usersApp1: ${Inspect.to_str(users_app1)}
|
||||
getUserApp3Nested 3: ${get_user_app3_nested(3)}
|
||||
usersApp3Passed: ${Inspect.to_str(users_app3_passed)}
|
||||
"""
|
||||
|
|
|
@ -4,14 +4,14 @@ app [main] {
|
|||
|
||||
import Api { app_id: "one", protocol: https }
|
||||
|
||||
https = \url -> "https://$(url)"
|
||||
https = \url -> "https://${url}"
|
||||
|
||||
main =
|
||||
"""
|
||||
# too many args
|
||||
$(Api.get_user(1, 2))
|
||||
$(Api.base_url(1))
|
||||
${Api.get_user(1, 2)}
|
||||
${Api.base_url(1)}
|
||||
|
||||
# too few args
|
||||
$(Api.get_post_comment(1))
|
||||
${Api.get_post_comment(1)}
|
||||
"""
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module { stdout! } -> [log!]
|
||||
|
||||
log! = \msg, level -> stdout!("$(level):$(msg)")
|
||||
log! = \msg, level -> stdout!("${level}:${msg}")
|
||||
|
|
|
@ -4,7 +4,7 @@ app [main] {
|
|||
|
||||
import Api { app_id: "one", protocol: https }
|
||||
|
||||
https = \url -> "https://$(url)"
|
||||
https = \url -> "https://${url}"
|
||||
|
||||
main =
|
||||
"$(Api.get_post)"
|
||||
"${Api.get_post}"
|
||||
|
|
|
@ -11,4 +11,4 @@ import foo.Foo
|
|||
|
||||
main_for_host : Str
|
||||
main_for_host =
|
||||
"$(main) $(Foo.foo)"
|
||||
"${main} ${Foo.foo}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue