Skip to content

Commit 8207669

Browse files
authored
Merge pull request #74 from codecrafters-io/andy/feat
Add Gleam for Shell
2 parents 651951d + c64b32e commit 8207669

31 files changed

+371
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to compile your program on CodeCrafters
4+
#
5+
# This runs before .codecrafters/run.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
gleam build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to run your program on CodeCrafters
4+
#
5+
# This runs after .codecrafters/compile.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
exec gleam run --no-print-progress --module main -- "$@"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/gleam/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump

compiled_starters/gleam/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for Gleam solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
In this challenge, you'll build your own POSIX compliant shell that's capable of
7+
interpreting shell commands, running external programs and builtin commands like
8+
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
9+
REPLs, builtin commands, and more.
10+
11+
**Note**: If you're viewing this repo on GitHub, head over to
12+
[codecrafters.io](https://codecrafters.io) to try the challenge.
13+
14+
# Passing the first stage
15+
16+
The entry point for your `shell` implementation is in `src/main.gleam`. Study
17+
and uncomment the relevant code, and push your changes to pass the first stage:
18+
19+
```sh
20+
git commit -am "pass 1st stage" # any msg
21+
git push origin master
22+
```
23+
24+
Time to move on to the next stage!
25+
26+
# Stage 2 & beyond
27+
28+
Note: This section is for stages 2 and beyond.
29+
30+
1. Ensure you have `gleam (1.9.1)` installed locally
31+
1. Run `./your_program.sh` to run your program, which is implemented in
32+
`src/main.gleam`.
33+
1. Commit your changes and run `git push origin master` to submit your solution
34+
to CodeCrafters. Test output will be streamed to your terminal.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the Gleam version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: gleam-1.9
11+
language_pack: gleam-1.9

compiled_starters/gleam/gleam.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "codecrafters_shell"
2+
version = "1.0.0"
3+
4+
# For a full reference of all the available options, you can have a look at
5+
# https://gleam.run/writing-gleam/gleam-toml/.
6+
7+
[dependencies]
8+
gleam_stdlib = "~> 0.34 or ~> 1.0"
9+
gleam_erlang = ">= 0.33.0 and < 1.0.0"
10+
11+
[dev-dependencies]
12+
gleeunit = "~> 1.0"

compiled_starters/gleam/manifest.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
6+
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
7+
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
8+
]
9+
10+
[requirements]
11+
gleam_erlang = { version = ">= 0.33.0 and < 1.0.0" }
12+
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
13+
gleeunit = { version = "~> 1.0" }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import gleam/erlang
2+
import gleam/io
3+
4+
pub fn main() {
5+
// Uncomment this block to pass the first stage
6+
// io.print("$ ")
7+
8+
// Wait for user input
9+
erlang.get_line("")
10+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
#
3+
# Use this script to run your program LOCALLY.
4+
#
5+
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit early if any commands fail
10+
11+
# Copied from .codecrafters/compile.sh
12+
#
13+
# - Edit this to change how your program compiles locally
14+
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
15+
(
16+
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17+
gleam build
18+
)
19+
20+
# Copied from .codecrafters/run.sh
21+
#
22+
# - Edit this to change how your program runs locally
23+
# - Edit .codecrafters/run.sh to change how your program runs remotely
24+
exec gleam run --no-print-progress --module main -- "$@"

course-definition.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ languages:
1919
- slug: "c"
2020
- slug: "cpp"
2121
- slug: "csharp"
22+
- slug: "gleam"
2223
- slug: "go"
2324
- slug: "java"
2425
- slug: "javascript"

dockerfiles/gleam-1.9.Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM ghcr.io/gleam-lang/gleam:v1.9.1-erlang-alpine
3+
4+
# Rebuild if gleam.toml or manifest.toml change
5+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="gleam.toml,manifest.toml"
6+
7+
WORKDIR /app
8+
9+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10+
COPY --exclude=.git --exclude=README.md . /app
11+
12+
# Force deps to be downloaded
13+
RUN gleam build
14+
15+
# Cache build directory
16+
RUN mkdir -p /app-cached
17+
RUN mv build /app-cached/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to compile your program on CodeCrafters
4+
#
5+
# This runs before .codecrafters/run.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
gleam build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to run your program on CodeCrafters
4+
#
5+
# This runs after .codecrafters/compile.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
exec gleam run --no-print-progress --module main -- "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump

solutions/gleam/01-oo8/code/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for Gleam solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
In this challenge, you'll build your own POSIX compliant shell that's capable of
7+
interpreting shell commands, running external programs and builtin commands like
8+
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
9+
REPLs, builtin commands, and more.
10+
11+
**Note**: If you're viewing this repo on GitHub, head over to
12+
[codecrafters.io](https://codecrafters.io) to try the challenge.
13+
14+
# Passing the first stage
15+
16+
The entry point for your `shell` implementation is in `src/main.gleam`. Study
17+
and uncomment the relevant code, and push your changes to pass the first stage:
18+
19+
```sh
20+
git commit -am "pass 1st stage" # any msg
21+
git push origin master
22+
```
23+
24+
Time to move on to the next stage!
25+
26+
# Stage 2 & beyond
27+
28+
Note: This section is for stages 2 and beyond.
29+
30+
1. Ensure you have `gleam (1.9.1)` installed locally
31+
1. Run `./your_program.sh` to run your program, which is implemented in
32+
`src/main.gleam`.
33+
1. Commit your changes and run `git push origin master` to submit your solution
34+
to CodeCrafters. Test output will be streamed to your terminal.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the Gleam version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: gleam-1.9
11+
language_pack: gleam-1.9
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "codecrafters_shell"
2+
version = "1.0.0"
3+
4+
# For a full reference of all the available options, you can have a look at
5+
# https://gleam.run/writing-gleam/gleam-toml/.
6+
7+
[dependencies]
8+
gleam_stdlib = "~> 0.34 or ~> 1.0"
9+
gleam_erlang = ">= 0.33.0 and < 1.0.0"
10+
11+
[dev-dependencies]
12+
gleeunit = "~> 1.0"
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
6+
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
7+
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
8+
]
9+
10+
[requirements]
11+
gleam_erlang = { version = ">= 0.33.0 and < 1.0.0" }
12+
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
13+
gleeunit = { version = "~> 1.0" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import gleam/erlang
2+
import gleam/io
3+
4+
pub fn main() {
5+
io.print("$ ")
6+
7+
// Wait for user input
8+
erlang.get_line("")
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
#
3+
# Use this script to run your program LOCALLY.
4+
#
5+
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit early if any commands fail
10+
11+
# Copied from .codecrafters/compile.sh
12+
#
13+
# - Edit this to change how your program compiles locally
14+
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
15+
(
16+
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17+
gleam build
18+
)
19+
20+
# Copied from .codecrafters/run.sh
21+
#
22+
# - Edit this to change how your program runs locally
23+
# - Edit .codecrafters/run.sh to change how your program runs remotely
24+
exec gleam run --no-print-progress --module main -- "$@"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@@ -1,10 +1,9 @@
2+
import gleam/erlang
3+
import gleam/io
4+
5+
pub fn main() {
6+
- // Uncomment this block to pass the first stage
7+
- // io.print("$ ")
8+
+ io.print("$ ")
9+
10+
// Wait for user input
11+
erlang.get_line("")
12+
}

solutions/gleam/01-oo8/explanation.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The entry point for your Shell implementation is in `src/main.gleam`.
2+
3+
Study and uncomment the relevant code:
4+
5+
```gleam
6+
// Uncomment this block to pass the first stage
7+
io.print("$ ")
8+
```
9+
10+
Push your changes to pass the first stage:
11+
12+
```
13+
git add .
14+
git commit -m "pass 1st stage" # any msg
15+
git push origin master
16+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to compile your program on CodeCrafters
4+
#
5+
# This runs before .codecrafters/run.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
gleam build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to run your program on CodeCrafters
4+
#
5+
# This runs after .codecrafters/compile.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
exec gleam run --no-print-progress --module main -- "$@"
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.beam
2+
*.ez
3+
/build
4+
erl_crash.dump
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name = "codecrafters_shell"
2+
version = "1.0.0"
3+
4+
# For a full reference of all the available options, you can have a look at
5+
# https://gleam.run/writing-gleam/gleam-toml/.
6+
7+
[dependencies]
8+
gleam_stdlib = "~> 0.34 or ~> 1.0"
9+
gleam_erlang = ">= 0.33.0 and < 1.0.0"
10+
11+
[dev-dependencies]
12+
gleeunit = "~> 1.0"
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This file was generated by Gleam
2+
# You typically do not need to edit this file
3+
4+
packages = [
5+
{ name = "gleam_erlang", version = "0.33.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "A1D26B80F01901B59AABEE3475DD4C18D27D58FA5C897D922FCB9B099749C064" },
6+
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" },
7+
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
8+
]
9+
10+
[requirements]
11+
gleam_erlang = { version = ">= 0.33.0 and < 1.0.0" }
12+
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
13+
gleeunit = { version = "~> 1.0" }

0 commit comments

Comments
 (0)