From 68986fe0410584c6934c835bb0ee784655f5f8c5 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 11 Jan 2022 22:01:23 -0800 Subject: Move scheme compiler into a separate directory. --- format.csc | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 format.csc (limited to 'format.csc') diff --git a/format.csc b/format.csc deleted file mode 100644 index 0469812..0000000 --- a/format.csc +++ /dev/null @@ -1,49 +0,0 @@ -(define-library (csc format) - (export - fprintf - printf - sprintf) - (import (scheme base) - (only (scheme write) display) - (only (csc strings) - find - not-found-error? - prefix?)) - (begin - - - (define (fprintf port format-string . format-args) - (let loop ((start 0) - (args format-args)) - (cond ((>= start (string-length format-string))) - ((prefix? "{{" format-string start) - (write-string "{" port) - (loop (+ 2 start) args)) - ((prefix? "}}" format-string start) - (write-string "}" port) - (loop (+ 2 start) args)) - ((prefix? "{}" format-string start) - (display (car args) port) - (loop (+ 2 start) (cdr args))) - ((prefix? "{" format-string start) - (raise (error "invalid format string" format-string))) - (else - (let* ((open-brace-pos (guard (e - ((not-found-error? e) (string-length format-string))) - (find "{" format-string start))) - (close-brace-pos (guard (e - ((not-found-error? e) (string-length format-string))) - (find "}" format-string start))) - (format-pos (min open-brace-pos close-brace-pos))) - (write-string format-string port start format-pos) - (loop format-pos args)))))) - - - (define (printf format-string . format-args) - (apply fprintf (current-output-port) format-string format-args)) - - - (define (sprintf format-string . format-args) - (let ((string-builder (open-output-string))) - (apply fprintf string-builder format-string format-args) - (get-output-string string-builder))))) -- cgit v1.3.1