fisl

fisl is scheme lox
git clone git://git.alexkarle.com.com/fisl
Log | Files | Refs | README

commit e2a17cb55d232ccd0e9a4277835d753d9ef1ed0f (patch)
parent 91da6e8c90dc09b32e347ac9bb7916199bea32e9
Author: Alex Karle <alex@alexkarle.com>
Date:   Sat,  1 Oct 2022 18:50:32 -0400

Add initial argument parsing / scaffolding

This took way longer than I expected as I poured over the scheme manual
pages! There's still a chance that I pivot to Golang, but for now.. I
mean Scheme is in the name!

Diffstat:
Afisl.scm | 32++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+), 0 deletions(-)

diff --git a/fisl.scm b/fisl.scm @@ -0,0 +1,32 @@ +#!/usr/bin/chicken-csi -ss +;; fisl -- fisl is scheme lox +(import (chicken io) + (chicken base) + (chicken format)) + +(define (run code) + (print code)) + +(define (run-prompt) + (display "> ") + (let ((l (read-line))) + (if (not (eof-object? l)) + (begin + (run l) + (run-prompt)) + (exit 0)))) + +(define (run-file fname) + (call-with-input-file fname (lambda (p) + (run (read-string #f p))))) + +(define (die str) + (fprintf (current-error-port) "~A\n" str) + (exit 1)) + +(define (main args) + (let ((argc (length args))) + (cond + ((eq? argc 0) (run-prompt)) + ((eq? argc 1) (run-file (car args))) + (else (die "Too many arguments. Usage: fisl [FILE]")))))