From 6f96b5b161c55fa1660fac12ed766fd6c4204a3b Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Thu, 30 May 2024 13:46:34 +0530 Subject: [PATCH 1/3] feat: add gleam support to grep challenge --- compiled_starters/gleam/.gitattributes | 1 + compiled_starters/gleam/.gitignore | 4 ++ compiled_starters/gleam/README.md | 39 ++++++++++++++ compiled_starters/gleam/codecrafters.yml | 11 ++++ compiled_starters/gleam/gleam.toml | 22 ++++++++ compiled_starters/gleam/manifest.toml | 17 ++++++ compiled_starters/gleam/src/grep.gleam | 38 +++++++++++++ compiled_starters/gleam/your_grep.sh | 8 +++ dockerfiles/gleam-1.0.Dockerfile | 5 ++ solutions/gleam/01-cq2/code/.gitattributes | 1 + solutions/gleam/01-cq2/code/.gitignore | 4 ++ solutions/gleam/01-cq2/code/README.md | 39 ++++++++++++++ solutions/gleam/01-cq2/code/codecrafters.yml | 11 ++++ solutions/gleam/01-cq2/code/gleam.toml | 22 ++++++++ solutions/gleam/01-cq2/code/manifest.toml | 17 ++++++ solutions/gleam/01-cq2/code/src/grep.gleam | 34 ++++++++++++ solutions/gleam/01-cq2/code/your_grep.sh | 8 +++ .../gleam/01-cq2/diff/src/grep.gleam.diff | 53 +++++++++++++++++++ solutions/gleam/01-cq2/explanation.md | 29 ++++++++++ starter-repository-definitions.yml | 22 ++++++++ starter_templates/codecrafters.yml | 4 ++ starter_templates/gleam/.gitignore | 4 ++ starter_templates/gleam/gleam.toml | 22 ++++++++ starter_templates/gleam/manifest.toml | 17 ++++++ starter_templates/gleam/src/grep.gleam | 38 +++++++++++++ starter_templates/gleam/src/tmp.gleam | 32 +++++++++++ starter_templates/gleam/your_grep.sh | 8 +++ 27 files changed, 510 insertions(+) create mode 100644 compiled_starters/gleam/.gitattributes create mode 100644 compiled_starters/gleam/.gitignore create mode 100644 compiled_starters/gleam/README.md create mode 100644 compiled_starters/gleam/codecrafters.yml create mode 100644 compiled_starters/gleam/gleam.toml create mode 100644 compiled_starters/gleam/manifest.toml create mode 100644 compiled_starters/gleam/src/grep.gleam create mode 100755 compiled_starters/gleam/your_grep.sh create mode 100644 dockerfiles/gleam-1.0.Dockerfile create mode 100644 solutions/gleam/01-cq2/code/.gitattributes create mode 100644 solutions/gleam/01-cq2/code/.gitignore create mode 100644 solutions/gleam/01-cq2/code/README.md create mode 100644 solutions/gleam/01-cq2/code/codecrafters.yml create mode 100644 solutions/gleam/01-cq2/code/gleam.toml create mode 100644 solutions/gleam/01-cq2/code/manifest.toml create mode 100644 solutions/gleam/01-cq2/code/src/grep.gleam create mode 100755 solutions/gleam/01-cq2/code/your_grep.sh create mode 100644 solutions/gleam/01-cq2/diff/src/grep.gleam.diff create mode 100644 solutions/gleam/01-cq2/explanation.md create mode 100644 starter_templates/gleam/.gitignore create mode 100644 starter_templates/gleam/gleam.toml create mode 100644 starter_templates/gleam/manifest.toml create mode 100644 starter_templates/gleam/src/grep.gleam create mode 100644 starter_templates/gleam/src/tmp.gleam create mode 100755 starter_templates/gleam/your_grep.sh diff --git a/compiled_starters/gleam/.gitattributes b/compiled_starters/gleam/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/gleam/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/gleam/.gitignore b/compiled_starters/gleam/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/compiled_starters/gleam/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/compiled_starters/gleam/README.md b/compiled_starters/gleam/README.md new file mode 100644 index 0000000..33ba3ae --- /dev/null +++ b/compiled_starters/gleam/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for Gleam solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/grep.gleam`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/grep.gleam`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/compiled_starters/gleam/codecrafters.yml b/compiled_starters/gleam/codecrafters.yml new file mode 100644 index 0000000..0ed6333 --- /dev/null +++ b/compiled_starters/gleam/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.0 +language_pack: gleam-1.0 diff --git a/compiled_starters/gleam/gleam.toml b/compiled_starters/gleam/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/compiled_starters/gleam/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/compiled_starters/gleam/manifest.toml b/compiled_starters/gleam/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/compiled_starters/gleam/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/compiled_starters/gleam/src/grep.gleam b/compiled_starters/gleam/src/grep.gleam new file mode 100644 index 0000000..cd130bb --- /dev/null +++ b/compiled_starters/gleam/src/grep.gleam @@ -0,0 +1,38 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this to pass the first stage + // let args = argv.load().arguments + // let assert Ok(input_line) = erlang.get_line("") + // case args { + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") + // } + // _ -> { + // io.println("Expected first argument to be '-E'") + // } + // } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/compiled_starters/gleam/your_grep.sh b/compiled_starters/gleam/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/compiled_starters/gleam/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file diff --git a/dockerfiles/gleam-1.0.Dockerfile b/dockerfiles/gleam-1.0.Dockerfile new file mode 100644 index 0000000..2d62298 --- /dev/null +++ b/dockerfiles/gleam-1.0.Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/gleam-lang/gleam:v1.0.0-erlang-alpine + +# Pre-compile steps +RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && gleam build" > /codecrafters-precompile.sh +RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/gleam/01-cq2/code/.gitattributes b/solutions/gleam/01-cq2/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/gleam/01-cq2/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/gleam/01-cq2/code/.gitignore b/solutions/gleam/01-cq2/code/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/solutions/gleam/01-cq2/code/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/solutions/gleam/01-cq2/code/README.md b/solutions/gleam/01-cq2/code/README.md new file mode 100644 index 0000000..33ba3ae --- /dev/null +++ b/solutions/gleam/01-cq2/code/README.md @@ -0,0 +1,39 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/grep.png) + +This is a starting point for Gleam solutions to the +["Build Your Own grep" Challenge](https://app.codecrafters.io/courses/grep/overview). + +[Regular expressions](https://en.wikipedia.org/wiki/Regular_expression) +(Regexes, for short) are patterns used to match character combinations in +strings. [`grep`](https://en.wikipedia.org/wiki/Grep) is a CLI tool for +searching using Regexes. + +In this challenge you'll build your own implementation of `grep`. Along the way +we'll learn about Regex syntax, how parsers/lexers work, and how regular +expressions are evaluated. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your `grep` implementation is in `src/grep.gleam`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` + +Time to move on to the next stage! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `gleam (1.0)` installed locally +1. Run `./your_grep.sh` to run your program, which is implemented in + `src/grep.gleam`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. diff --git a/solutions/gleam/01-cq2/code/codecrafters.yml b/solutions/gleam/01-cq2/code/codecrafters.yml new file mode 100644 index 0000000..0ed6333 --- /dev/null +++ b/solutions/gleam/01-cq2/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Gleam version used to run your code +# on Codecrafters. +# +# Available versions: gleam-1.0 +language_pack: gleam-1.0 diff --git a/solutions/gleam/01-cq2/code/gleam.toml b/solutions/gleam/01-cq2/code/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/solutions/gleam/01-cq2/code/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/solutions/gleam/01-cq2/code/manifest.toml b/solutions/gleam/01-cq2/code/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/solutions/gleam/01-cq2/code/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/solutions/gleam/01-cq2/code/src/grep.gleam b/solutions/gleam/01-cq2/code/src/grep.gleam new file mode 100644 index 0000000..0cf803e --- /dev/null +++ b/solutions/gleam/01-cq2/code/src/grep.gleam @@ -0,0 +1,34 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") + } + } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/solutions/gleam/01-cq2/code/your_grep.sh b/solutions/gleam/01-cq2/code/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/solutions/gleam/01-cq2/code/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file diff --git a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff new file mode 100644 index 0000000..1f36180 --- /dev/null +++ b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff @@ -0,0 +1,53 @@ +@@ -1,38 +1,34 @@ + import argv + import gleam/io + import gleam/string + import gleam/erlang + + pub fn main() { +- // You can use print statements as follows for debugging, they'll be visible when running tests. +- io.println("Logs from your program will appear here!") +- +- // Uncomment this to pass the first stage +- // let args = argv.load().arguments +- // let assert Ok(input_line) = erlang.get_line("") +- // case args { +- // ["-E", pattern, ..] -> { +- // case match_pattern(input_line, pattern) { +- // True -> exit(0) +- // False -> exit(1) +- // } +- // io.println("Success") +- // } +- // _ -> { +- // io.println("Expected first argument to be '-E'") +- // } +- // } ++ let args = argv.load().arguments ++ let assert Ok(input_line) = erlang.get_line("") ++ case args { ++ ["-E", pattern, ..] -> { ++ case match_pattern(input_line, pattern) { ++ True -> exit(0) ++ False -> exit(1) ++ } ++ io.println("Success") ++ } ++ _ -> { ++ io.println("Expected first argument to be '-E'") ++ } ++ } + } + + fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } + } + + @external(erlang, "erlang", "halt") + pub fn exit(code: Int) -> Int diff --git a/solutions/gleam/01-cq2/explanation.md b/solutions/gleam/01-cq2/explanation.md new file mode 100644 index 0000000..27d7eba --- /dev/null +++ b/solutions/gleam/01-cq2/explanation.md @@ -0,0 +1,29 @@ +The entry point for your grep implementation is in `src/grep.gleam`. + +Study and uncomment the relevant code: + +```gleam +// Uncomment this to pass the first stage +let args = argv.load().arguments +let assert Ok(input_line) = erlang.get_line("") +case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") + } +} +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index fd58c69..037aacf 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -193,3 +193,25 @@ template_attributes: required_executable: "bun (1.1)" user_editable_file: "app/main.ts" + +- language: gleam + file_mappings: + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/gleam/src/grep.gleam + target: src/grep.gleam + - source: starter_templates/gleam/.gitignore + target: .gitignore + - source: starter_templates/gleam/gleam.toml + target: gleam.toml + - source: starter_templates/gleam/manifest.toml + target: manifest.toml + - source: starter_templates/gleam/your_grep.sh + target: your_grep.sh + - source: starter_templates/.gitattributes + target: .gitattributes + template_attributes: + required_executable: "gleam (1.0)" + user_editable_file: "src/grep.gleam" diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index 26574a1..a182a87 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -79,3 +79,7 @@ language_pack: cpp-20 # Available versions: bun-1.1 language_pack: bun-1.1 {{/language_is_typescript}} +{{#language_is_gleam}} +# Available versions: gleam-1.0 +language_pack: gleam-1.0 +{{/language_is_gleam}} diff --git a/starter_templates/gleam/.gitignore b/starter_templates/gleam/.gitignore new file mode 100644 index 0000000..599be4e --- /dev/null +++ b/starter_templates/gleam/.gitignore @@ -0,0 +1,4 @@ +*.beam +*.ez +/build +erl_crash.dump diff --git a/starter_templates/gleam/gleam.toml b/starter_templates/gleam/gleam.toml new file mode 100644 index 0000000..17e5928 --- /dev/null +++ b/starter_templates/gleam/gleam.toml @@ -0,0 +1,22 @@ +name = "grep" +version = "1.0.0" + +# Fill out these fields if you intend to generate HTML documentation or publish +# your project to the Hex package manager. +# +# description = "" +# licences = ["Apache-2.0"] +# repository = { type = "github", user = "username", repo = "project" } +# links = [{ title = "Website", href = "https://gleam.run" }] +# +# For a full reference of all the available options, you can have a look at +# https://gleam.run/writing-gleam/gleam-toml/. + +[dependencies] +gleam_erlang = "~> 0.25" +gleam_stdlib = "~> 0.34 or ~> 1.0" +argv = ">= 1.0.2 and < 2.0.0" +file_streams = ">= 0.4.2 and < 1.0.0" + +[dev-dependencies] +gleeunit = "~> 1.0" \ No newline at end of file diff --git a/starter_templates/gleam/manifest.toml b/starter_templates/gleam/manifest.toml new file mode 100644 index 0000000..439aa3c --- /dev/null +++ b/starter_templates/gleam/manifest.toml @@ -0,0 +1,17 @@ +# This file was generated by Gleam +# You typically do not need to edit this file + +packages = [ + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, + { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, + { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, +] + +[requirements] +argv = { version = ">= 1.0.2 and < 2.0.0" } +gleam_erlang = { version = "~> 0.25" } +file_streams = { version = ">= 0.4.2 and < 1.0.0" } +gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } +gleeunit = { version = "~> 1.0" } diff --git a/starter_templates/gleam/src/grep.gleam b/starter_templates/gleam/src/grep.gleam new file mode 100644 index 0000000..cd130bb --- /dev/null +++ b/starter_templates/gleam/src/grep.gleam @@ -0,0 +1,38 @@ +import argv +import gleam/io +import gleam/string +import gleam/erlang + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + // Uncomment this to pass the first stage + // let args = argv.load().arguments + // let assert Ok(input_line) = erlang.get_line("") + // case args { + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") + // } + // _ -> { + // io.println("Expected first argument to be '-E'") + // } + // } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} + +@external(erlang, "erlang", "halt") +pub fn exit(code: Int) -> Int diff --git a/starter_templates/gleam/src/tmp.gleam b/starter_templates/gleam/src/tmp.gleam new file mode 100644 index 0000000..9dffc29 --- /dev/null +++ b/starter_templates/gleam/src/tmp.gleam @@ -0,0 +1,32 @@ +import argv + +pub fn main() { + // You can use print statements as follows for debugging, they'll be visible when running tests. + io.println("Logs from your program will appear here!") + + let args = argv.load().arguments + input_line = io.read_line() + + // Uncomment this to pass the first stage + case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> io.exit(0) + False -> io.exit(1) + } + } + _ -> { + io.println("Expected first argument to be '-E'") + } + } +} + +fn match_pattern(input_line: String, pattern: String) -> Bool { + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False + } + } +} \ No newline at end of file diff --git a/starter_templates/gleam/your_grep.sh b/starter_templates/gleam/your_grep.sh new file mode 100755 index 0000000..9fd98a5 --- /dev/null +++ b/starter_templates/gleam/your_grep.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +exec gleam run -- "$@" \ No newline at end of file From 63cc3520f18ba298baa966575a72b018e05b643f Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Thu, 30 May 2024 17:05:55 +0530 Subject: [PATCH 2/3] style: update gleam formatting --- compiled_starters/gleam/gleam.toml | 3 +- compiled_starters/gleam/manifest.toml | 6 +-- compiled_starters/gleam/src/grep.gleam | 27 ++++++------ solutions/gleam/01-cq2/code/gleam.toml | 3 +- solutions/gleam/01-cq2/code/manifest.toml | 6 +-- solutions/gleam/01-cq2/code/src/grep.gleam | 26 ++++++------ .../gleam/01-cq2/diff/src/grep.gleam.diff | 41 +++++++++---------- solutions/gleam/01-cq2/explanation.md | 12 +++--- starter_templates/gleam/gleam.toml | 3 +- starter_templates/gleam/manifest.toml | 6 +-- starter_templates/gleam/src/grep.gleam | 27 ++++++------ starter_templates/gleam/src/tmp.gleam | 32 --------------- 12 files changed, 74 insertions(+), 118 deletions(-) delete mode 100644 starter_templates/gleam/src/tmp.gleam diff --git a/compiled_starters/gleam/gleam.toml b/compiled_starters/gleam/gleam.toml index 17e5928..54dc816 100644 --- a/compiled_starters/gleam/gleam.toml +++ b/compiled_starters/gleam/gleam.toml @@ -13,10 +13,9 @@ version = "1.0.0" # https://gleam.run/writing-gleam/gleam-toml/. [dependencies] +argv = ">= 1.0.2 and < 2.0.0" gleam_erlang = "~> 0.25" gleam_stdlib = "~> 0.34 or ~> 1.0" -argv = ">= 1.0.2 and < 2.0.0" -file_streams = ">= 0.4.2 and < 1.0.0" [dev-dependencies] gleeunit = "~> 1.0" \ No newline at end of file diff --git a/compiled_starters/gleam/manifest.toml b/compiled_starters/gleam/manifest.toml index 439aa3c..5039704 100644 --- a/compiled_starters/gleam/manifest.toml +++ b/compiled_starters/gleam/manifest.toml @@ -2,16 +2,14 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, - { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, - { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, ] [requirements] argv = { version = ">= 1.0.2 and < 2.0.0" } gleam_erlang = { version = "~> 0.25" } -file_streams = { version = ">= 0.4.2 and < 1.0.0" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } diff --git a/compiled_starters/gleam/src/grep.gleam b/compiled_starters/gleam/src/grep.gleam index cd130bb..388b3e7 100644 --- a/compiled_starters/gleam/src/grep.gleam +++ b/compiled_starters/gleam/src/grep.gleam @@ -1,22 +1,21 @@ import argv +import gleam/erlang import gleam/io import gleam/string -import gleam/erlang pub fn main() { // You can use print statements as follows for debugging, they'll be visible when running tests. io.println("Logs from your program will appear here!") - // Uncomment this to pass the first stage // let args = argv.load().arguments // let assert Ok(input_line) = erlang.get_line("") // case args { - // ["-E", pattern, ..] -> { - // case match_pattern(input_line, pattern) { - // True -> exit(0) - // False -> exit(1) - // } - // io.println("Success") + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") // } // _ -> { // io.println("Expected first argument to be '-E'") @@ -25,13 +24,13 @@ pub fn main() { } fn match_pattern(input_line: String, pattern: String) -> Bool { - case string.length(pattern) { - 1 -> string.contains(input_line, pattern) - _ -> { - io.println("Unhandled pattern: " <> pattern) - False - } + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False } + } } @external(erlang, "erlang", "halt") diff --git a/solutions/gleam/01-cq2/code/gleam.toml b/solutions/gleam/01-cq2/code/gleam.toml index 17e5928..54dc816 100644 --- a/solutions/gleam/01-cq2/code/gleam.toml +++ b/solutions/gleam/01-cq2/code/gleam.toml @@ -13,10 +13,9 @@ version = "1.0.0" # https://gleam.run/writing-gleam/gleam-toml/. [dependencies] +argv = ">= 1.0.2 and < 2.0.0" gleam_erlang = "~> 0.25" gleam_stdlib = "~> 0.34 or ~> 1.0" -argv = ">= 1.0.2 and < 2.0.0" -file_streams = ">= 0.4.2 and < 1.0.0" [dev-dependencies] gleeunit = "~> 1.0" \ No newline at end of file diff --git a/solutions/gleam/01-cq2/code/manifest.toml b/solutions/gleam/01-cq2/code/manifest.toml index 439aa3c..5039704 100644 --- a/solutions/gleam/01-cq2/code/manifest.toml +++ b/solutions/gleam/01-cq2/code/manifest.toml @@ -2,16 +2,14 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, - { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, - { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, ] [requirements] argv = { version = ">= 1.0.2 and < 2.0.0" } gleam_erlang = { version = "~> 0.25" } -file_streams = { version = ">= 0.4.2 and < 1.0.0" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } diff --git a/solutions/gleam/01-cq2/code/src/grep.gleam b/solutions/gleam/01-cq2/code/src/grep.gleam index 0cf803e..5b4dc75 100644 --- a/solutions/gleam/01-cq2/code/src/grep.gleam +++ b/solutions/gleam/01-cq2/code/src/grep.gleam @@ -1,18 +1,18 @@ import argv +import gleam/erlang import gleam/io import gleam/string -import gleam/erlang pub fn main() { let args = argv.load().arguments let assert Ok(input_line) = erlang.get_line("") case args { - ["-E", pattern, ..] -> { - case match_pattern(input_line, pattern) { - True -> exit(0) - False -> exit(1) - } - io.println("Success") + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") } _ -> { io.println("Expected first argument to be '-E'") @@ -21,13 +21,13 @@ pub fn main() { } fn match_pattern(input_line: String, pattern: String) -> Bool { - case string.length(pattern) { - 1 -> string.contains(input_line, pattern) - _ -> { - io.println("Unhandled pattern: " <> pattern) - False - } + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False } + } } @external(erlang, "erlang", "halt") diff --git a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff index 1f36180..78a419d 100644 --- a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff +++ b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff @@ -1,23 +1,22 @@ -@@ -1,38 +1,34 @@ +@@ -1,37 +1,34 @@ import argv + import gleam/erlang import gleam/io import gleam/string - import gleam/erlang pub fn main() { - // You can use print statements as follows for debugging, they'll be visible when running tests. - io.println("Logs from your program will appear here!") -- - // Uncomment this to pass the first stage - // let args = argv.load().arguments - // let assert Ok(input_line) = erlang.get_line("") - // case args { -- // ["-E", pattern, ..] -> { -- // case match_pattern(input_line, pattern) { -- // True -> exit(0) -- // False -> exit(1) -- // } -- // io.println("Success") +- // ["-E", pattern, ..] -> { +- // case match_pattern(input_line, pattern) { +- // True -> exit(0) +- // False -> exit(1) +- // } +- // io.println("Success") - // } - // _ -> { - // io.println("Expected first argument to be '-E'") @@ -26,12 +25,12 @@ + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + case args { -+ ["-E", pattern, ..] -> { -+ case match_pattern(input_line, pattern) { -+ True -> exit(0) -+ False -> exit(1) -+ } -+ io.println("Success") ++ ["-E", pattern, ..] -> { ++ case match_pattern(input_line, pattern) { ++ True -> exit(0) ++ False -> exit(1) ++ } ++ io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") @@ -40,13 +39,13 @@ } fn match_pattern(input_line: String, pattern: String) -> Bool { - case string.length(pattern) { - 1 -> string.contains(input_line, pattern) - _ -> { - io.println("Unhandled pattern: " <> pattern) - False - } + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False } + } } @external(erlang, "erlang", "halt") diff --git a/solutions/gleam/01-cq2/explanation.md b/solutions/gleam/01-cq2/explanation.md index 27d7eba..20c4688 100644 --- a/solutions/gleam/01-cq2/explanation.md +++ b/solutions/gleam/01-cq2/explanation.md @@ -7,12 +7,12 @@ Study and uncomment the relevant code: let args = argv.load().arguments let assert Ok(input_line) = erlang.get_line("") case args { - ["-E", pattern, ..] -> { - case match_pattern(input_line, pattern) { - True -> exit(0) - False -> exit(1) - } - io.println("Success") + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } + io.println("Success") } _ -> { io.println("Expected first argument to be '-E'") diff --git a/starter_templates/gleam/gleam.toml b/starter_templates/gleam/gleam.toml index 17e5928..54dc816 100644 --- a/starter_templates/gleam/gleam.toml +++ b/starter_templates/gleam/gleam.toml @@ -13,10 +13,9 @@ version = "1.0.0" # https://gleam.run/writing-gleam/gleam-toml/. [dependencies] +argv = ">= 1.0.2 and < 2.0.0" gleam_erlang = "~> 0.25" gleam_stdlib = "~> 0.34 or ~> 1.0" -argv = ">= 1.0.2 and < 2.0.0" -file_streams = ">= 0.4.2 and < 1.0.0" [dev-dependencies] gleeunit = "~> 1.0" \ No newline at end of file diff --git a/starter_templates/gleam/manifest.toml b/starter_templates/gleam/manifest.toml index 439aa3c..5039704 100644 --- a/starter_templates/gleam/manifest.toml +++ b/starter_templates/gleam/manifest.toml @@ -2,16 +2,14 @@ # You typically do not need to edit this file packages = [ - { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, { name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" }, - { name = "file_streams", version = "0.4.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "file_streams", source = "hex", outer_checksum = "86775D2F36B74C54C64CA9080ACA9B9CF4655759E8D3E87E1A2EA9B0FA8D0804" }, - { name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, + { name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, + { name = "gleam_stdlib", version = "0.38.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "663CF11861179AF415A625307447775C09404E752FF99A24E2057C835319F1BE" }, { name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, ] [requirements] argv = { version = ">= 1.0.2 and < 2.0.0" } gleam_erlang = { version = "~> 0.25" } -file_streams = { version = ">= 0.4.2 and < 1.0.0" } gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } gleeunit = { version = "~> 1.0" } diff --git a/starter_templates/gleam/src/grep.gleam b/starter_templates/gleam/src/grep.gleam index cd130bb..388b3e7 100644 --- a/starter_templates/gleam/src/grep.gleam +++ b/starter_templates/gleam/src/grep.gleam @@ -1,22 +1,21 @@ import argv +import gleam/erlang import gleam/io import gleam/string -import gleam/erlang pub fn main() { // You can use print statements as follows for debugging, they'll be visible when running tests. io.println("Logs from your program will appear here!") - // Uncomment this to pass the first stage // let args = argv.load().arguments // let assert Ok(input_line) = erlang.get_line("") // case args { - // ["-E", pattern, ..] -> { - // case match_pattern(input_line, pattern) { - // True -> exit(0) - // False -> exit(1) - // } - // io.println("Success") + // ["-E", pattern, ..] -> { + // case match_pattern(input_line, pattern) { + // True -> exit(0) + // False -> exit(1) + // } + // io.println("Success") // } // _ -> { // io.println("Expected first argument to be '-E'") @@ -25,13 +24,13 @@ pub fn main() { } fn match_pattern(input_line: String, pattern: String) -> Bool { - case string.length(pattern) { - 1 -> string.contains(input_line, pattern) - _ -> { - io.println("Unhandled pattern: " <> pattern) - False - } + case string.length(pattern) { + 1 -> string.contains(input_line, pattern) + _ -> { + io.println("Unhandled pattern: " <> pattern) + False } + } } @external(erlang, "erlang", "halt") diff --git a/starter_templates/gleam/src/tmp.gleam b/starter_templates/gleam/src/tmp.gleam deleted file mode 100644 index 9dffc29..0000000 --- a/starter_templates/gleam/src/tmp.gleam +++ /dev/null @@ -1,32 +0,0 @@ -import argv - -pub fn main() { - // You can use print statements as follows for debugging, they'll be visible when running tests. - io.println("Logs from your program will appear here!") - - let args = argv.load().arguments - input_line = io.read_line() - - // Uncomment this to pass the first stage - case args { - ["-E", pattern, ..] -> { - case match_pattern(input_line, pattern) { - True -> io.exit(0) - False -> io.exit(1) - } - } - _ -> { - io.println("Expected first argument to be '-E'") - } - } -} - -fn match_pattern(input_line: String, pattern: String) -> Bool { - case string.length(pattern) { - 1 -> string.contains(input_line, pattern) - _ -> { - io.println("Unhandled pattern: " <> pattern) - False - } - } -} \ No newline at end of file From 99fd7597546279a77597b49395057f1708994bd8 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Thu, 30 May 2024 23:34:46 +0530 Subject: [PATCH 3/3] feat: reduce commented section in gleam starter --- compiled_starters/gleam/src/grep.gleam | 8 +++++--- solutions/gleam/01-cq2/code/src/grep.gleam | 3 ++- solutions/gleam/01-cq2/diff/src/grep.gleam.diff | 14 +++++++------- solutions/gleam/01-cq2/explanation.md | 4 +--- starter_templates/gleam/src/grep.gleam | 8 +++++--- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/compiled_starters/gleam/src/grep.gleam b/compiled_starters/gleam/src/grep.gleam index 388b3e7..d4b93cc 100644 --- a/compiled_starters/gleam/src/grep.gleam +++ b/compiled_starters/gleam/src/grep.gleam @@ -6,19 +6,21 @@ import gleam/string pub fn main() { // You can use print statements as follows for debugging, they'll be visible when running tests. io.println("Logs from your program will appear here!") + + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + // Uncomment this to pass the first stage - // let args = argv.load().arguments - // let assert Ok(input_line) = erlang.get_line("") // case args { // ["-E", pattern, ..] -> { // case match_pattern(input_line, pattern) { // True -> exit(0) // False -> exit(1) // } - // io.println("Success") // } // _ -> { // io.println("Expected first argument to be '-E'") + // exit(1) // } // } } diff --git a/solutions/gleam/01-cq2/code/src/grep.gleam b/solutions/gleam/01-cq2/code/src/grep.gleam index 5b4dc75..41dbfc9 100644 --- a/solutions/gleam/01-cq2/code/src/grep.gleam +++ b/solutions/gleam/01-cq2/code/src/grep.gleam @@ -6,16 +6,17 @@ import gleam/string pub fn main() { let args = argv.load().arguments let assert Ok(input_line) = erlang.get_line("") + case args { ["-E", pattern, ..] -> { case match_pattern(input_line, pattern) { True -> exit(0) False -> exit(1) } - io.println("Success") } _ -> { io.println("Expected first argument to be '-E'") + exit(1) } } } diff --git a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff index 78a419d..9ae8877 100644 --- a/solutions/gleam/01-cq2/diff/src/grep.gleam.diff +++ b/solutions/gleam/01-cq2/diff/src/grep.gleam.diff @@ -1,4 +1,4 @@ -@@ -1,37 +1,34 @@ +@@ -1,39 +1,35 @@ import argv import gleam/erlang import gleam/io @@ -7,33 +7,33 @@ pub fn main() { - // You can use print statements as follows for debugging, they'll be visible when running tests. - io.println("Logs from your program will appear here!") +- + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + - // Uncomment this to pass the first stage -- // let args = argv.load().arguments -- // let assert Ok(input_line) = erlang.get_line("") - // case args { - // ["-E", pattern, ..] -> { - // case match_pattern(input_line, pattern) { - // True -> exit(0) - // False -> exit(1) - // } -- // io.println("Success") - // } - // _ -> { - // io.println("Expected first argument to be '-E'") +- // exit(1) - // } - // } -+ let args = argv.load().arguments -+ let assert Ok(input_line) = erlang.get_line("") + case args { + ["-E", pattern, ..] -> { + case match_pattern(input_line, pattern) { + True -> exit(0) + False -> exit(1) + } -+ io.println("Success") + } + _ -> { + io.println("Expected first argument to be '-E'") ++ exit(1) + } + } } diff --git a/solutions/gleam/01-cq2/explanation.md b/solutions/gleam/01-cq2/explanation.md index 20c4688..c80df7b 100644 --- a/solutions/gleam/01-cq2/explanation.md +++ b/solutions/gleam/01-cq2/explanation.md @@ -4,18 +4,16 @@ Study and uncomment the relevant code: ```gleam // Uncomment this to pass the first stage -let args = argv.load().arguments -let assert Ok(input_line) = erlang.get_line("") case args { ["-E", pattern, ..] -> { case match_pattern(input_line, pattern) { True -> exit(0) False -> exit(1) } - io.println("Success") } _ -> { io.println("Expected first argument to be '-E'") + exit(1) } } ``` diff --git a/starter_templates/gleam/src/grep.gleam b/starter_templates/gleam/src/grep.gleam index 388b3e7..d4b93cc 100644 --- a/starter_templates/gleam/src/grep.gleam +++ b/starter_templates/gleam/src/grep.gleam @@ -6,19 +6,21 @@ import gleam/string pub fn main() { // You can use print statements as follows for debugging, they'll be visible when running tests. io.println("Logs from your program will appear here!") + + let args = argv.load().arguments + let assert Ok(input_line) = erlang.get_line("") + // Uncomment this to pass the first stage - // let args = argv.load().arguments - // let assert Ok(input_line) = erlang.get_line("") // case args { // ["-E", pattern, ..] -> { // case match_pattern(input_line, pattern) { // True -> exit(0) // False -> exit(1) // } - // io.println("Success") // } // _ -> { // io.println("Expected first argument to be '-E'") + // exit(1) // } // } }