diff --git a/README.md b/README.md index e1fccbc..7a33b1e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ Solutions to https://adventofcode.com/2023/ This is my first experience with Lisp, so the code is probably terrible. +Also I decided to reimplement all the mostly basic stuff (like `map` or `reduce`) myself, +both for fun and because Guile documentation is really bad. + Requirements: Guile 3 in `/usr/bin`. In a folder for a specific day, diff --git a/day01-hard/main.scm b/day01-hard/main.scm index fa0ec5f..87ee9a0 100755 --- a/day01-hard/main.scm +++ b/day01-hard/main.scm @@ -1,6 +1,7 @@ #!/usr/bin/guile -s !# +;=============== functions with side effects (I/O) ====================== (use-modules (ice-9 rdelim)) (define (read-lines) @@ -8,17 +9,18 @@ (if (eof-object? line) '() (cons line (read-lines)))) (read-line))) +(define (display-ln value) (list (display value) (display "\n"))) + (define (assert-eq error-message expected actual) (if (not (equal? expected actual)) - (list - (display (list error-message (list "expected" expected) (list "actual" actual))) - (display "\n")) + (display-ln (list error-message (list "expected" expected) (list "actual" actual))) '())) -(define (tee value) (car (list value (display value) (display "\n")))) +(define (tee value) (car (list value (display-ln value)))) +;=============== end of functions with side effects ====================== (define (id value) value) -(define (is-not value) (lambda (x) (not (= x value)))) +(define (is-not value) (lambda (x) (not (equal? x value)))) (define is-not-empty (lambda (x) (not (null? x)))) (define (prepend first-value) (lambda (rest) (cons first-value rest)))