simplified code

main
Inga 🏳‍🌈 12 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.
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,

@ -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)))

Loading…
Cancel
Save