Skip to content

Commit

Permalink
Create Scheme implementation
Browse files Browse the repository at this point in the history
I expected it to be similar to the common lisp implementation, but it's
actually closer tothe OCaml one.
  • Loading branch information
eliminmax committed May 2, 2024
1 parent 13b1887 commit 7714361
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ At the current moment, I've implemented it in the following languages:
* Ruby
* Rust
* Scala
* Scheme
* Shell Script (should work in any POSIX shell)
* TypeScript *(lightly tweaked JavaScript implementation)* (via ts-node)
* Vala
Expand Down
4 changes: 2 additions & 2 deletions RUNNERS/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
colortest_implementations=(
algol_68 awk babalang befunge bf c cobol cpp csharp d erlang fender forth
fortran go haskell java javascript kotlin lisp lua nim objective-c ocaml
octave odin pascal perl php powershell python r rockstar ruby rust scala sh
typescript vala x86-64_linux_asm zig
octave odin pascal perl php powershell python r rockstar ruby rust scala
scheme sh typescript vala x86-64_linux_asm zig
)

basedir="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
Expand Down
1 change: 1 addition & 0 deletions RUNNERS/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ python_dependencies() { apt_wrapper python3 python3; }
r_dependencies() { apt_wrapper r r-cran-littler; }
ruby_dependencies() { apt_wrapper ruby ruby; }
scala_dependencies() { apt_wrapper scalac scala; }
scheme_dependencies() { apt_wrapper csi chicken-bin; }
typescript_dependencies() { apt_wrapper ts-node ts-node; }
vala_dependencies() { apt_wrapper valac valac;}

Expand Down
1 change: 1 addition & 0 deletions RUNNERS/run-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ run_version() {
'r') r colortest.r ;;
'rockstar') satriani-wrapper colortest.rock ;;
'ruby') ruby colortest.rb ;;
'scheme') csi -script colortest.sld ;;
'sh') sh colortest.sh ;;
'typescript') ts-node colortest.ts ;;
# GNU Octave throws an error on exit if XDG_DATA_HOME is missing
Expand Down
42 changes: 42 additions & 0 deletions scheme/colortest.sld
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; SPDX-FileCopyrightText: 2024 Eli Array Minkoff
;
; SPDX-License-Identifier: GPL-3.0-only


(define (colorcell n)
(display "\x1b[48;5;") (display (number->string n)) (display "m ")
)

(define (range lo hi step)
; Return an empty list if step <= 0 or lo >= hi
(cond ((<= step 0) '())
((>= lo hi) '())
; return lo combined with the next iteration's output
(else (cons lo (range (+ lo step) hi step)))))

; Print the first 16 colors - these vary by terminal configuration
(newline)
(map colorcell (range 0 16 1))
(display "\x1b[0m\n\n")

; Print the 6 sides of the color cube - these are more standardized,
; but the order is a bit odd, thus the need for this trickery
(define (row_a n) (range n (+ n 6) 1))
(define (row_b n) (range (+ n 36) (+ n 42) 1))
(define (row_c n) (range (+ n 72) (+ n 78) 1))
(define (part_2_row n)
(map colorcell (row_a n))
(display "\x1b[0m ")
(map colorcell (row_b n))
(display "\x1b[0m ")
(map colorcell (row_c n))
(display "\x1b[0m\n"))

(map part_2_row (range 16 52 6))
(newline)
(map part_2_row (range 124 160 6))
(newline)

; Finally, the 24 grays
(map colorcell (range 232 256 1))
(display "\x1b[0m\n\n")

0 comments on commit 7714361

Please sign in to comment.