simplified code

main
Inga 🏳‍🌈 11 months ago
parent 5f8c81daf2
commit 00a256de01
  1. 3
      README.md
  2. 12
      day01-hard/main.scm

@ -4,6 +4,9 @@ Solutions to https://adventofcode.com/2023/
This is my first experience with Lisp, so the code is probably terrible. 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`. Requirements: Guile 3 in `/usr/bin`.
In a folder for a specific day, In a folder for a specific day,

@ -1,6 +1,7 @@
#!/usr/bin/guile -s #!/usr/bin/guile -s
!# !#
;=============== functions with side effects (I/O) ======================
(use-modules (ice-9 rdelim)) (use-modules (ice-9 rdelim))
(define (read-lines) (define (read-lines)
@ -8,17 +9,18 @@
(if (eof-object? line) '() (cons line (read-lines)))) (if (eof-object? line) '() (cons line (read-lines))))
(read-line))) (read-line)))
(define (display-ln value) (list (display value) (display "\n")))
(define (assert-eq error-message expected actual) (define (assert-eq error-message expected actual)
(if (not (equal? expected actual)) (if (not (equal? expected actual))
(list (display-ln (list error-message (list "expected" expected) (list "actual" actual)))
(display (list error-message (list "expected" expected) (list "actual" actual)))
(display "\n"))
'())) '()))
(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 (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 is-not-empty (lambda (x) (not (null? x))))
(define (prepend first-value) (lambda (rest) (cons first-value rest))) (define (prepend first-value) (lambda (rest) (cons first-value rest)))

Loading…
Cancel
Save