Real-World Scheme
51.1 Scripting
#!/usr/bin/env -S guile -s
!#
;; count-lines.scm: count lines in the files given on the command line
(use-modules (ice-9 textual-ports))
(for-each
(lambda (file)
(let ((n (length (string-split (call-with-input-file file get-string-all) #\newline))))
(format #t "~a: ~a lines~%" file (- n 1))))
(cdr (command-line)))51.2 Notable Systems Built with Scheme
GNU Guix / Shepherd Functional package management, OS configuration, init system Accounting (reports) GIMP Script-Fu Image editing automation Racket (CS) Naughty Dog games Racket-based DSLs, GOAL (Lisp) Spritely Goblins / Hoot Distributed objects, WebAssembly (embeddable Scheme) Snd, Common Music, audio Static site generator
51.3 Web Development
Other options: Guile Artanis (web framework), CHICKEN Spiffy/Awful, Racket web-server, Gerbil's HTTP server, and SXML for HTML/XML as s-expressions:
;; Guile's built-in web server
(use-modules (web server) (web request) (web response) (web uri))
(define (handler request body)
(let ((path (uri-path (request-uri request))))
(values '((content-type . (text/plain)))
(string-append "Hello from Guile! You requested " path))))
(run-server handler 'http '(#:port 8080));; SXML: XML/HTML as lists
'(html (head (title "Page")) (body (h1 "Hello") (p (@ (class "intro")) "Text")))
;; Guile: (use-modules (sxml simple)) (sxml->xml tree)51.4 Embedding Scheme as an Extension Language
Applications embed Guile, Chibi, S7, or TinyScheme to let users script them, as Emacs does with Emacs Lisp. Expose host functions to Scheme, run user scripts in restricted environments ((environment ...) with only safe bindings), and call Scheme callbacks from C.