Caleb

How to Write Scripts in Scheme

November 23, 2023
Tags:

It's easy to write scripts in Scheme instead of shell! Unfortunately, the first few lines of each script looks rather ugly.

#!/usr/bin/env -S guile --no-auto-compile -e main -s # -*- Scheme -*-
!#

But after that, you just have to wrap your commands in the system function, and the logic (if statemests and such) can be written in Scheme!

(define mount-point "/media/caleb/HUSKY")

(define (main args)
  (if (= (car (cdr args)) "unmount")
      '((system "umount" mount-point)
	(rmdir mount-point))
      '((mkdir mount-point)
	(system "mount -L HUSKY" mount-point))))