From 8f3a4f3f07853d472bc0d1ab4198e531ed8ebf49 Mon Sep 17 00:00:00 2001 From: sforman Date: Tue, 24 Oct 2023 09:49:42 -0700 Subject: [PATCH] Minor cleanup. --- implementations/scheme-chicken/joy.scm | 76 ++++++++++++-------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index da48d92..0b2466c 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -95,41 +95,6 @@ (abort (conc "Unknown word: " symbol)))))) -;██╗ ██╗████████╗██╗██╗ ███████╗ -;██║ ██║╚══██╔══╝██║██║ ██╔════╝ -;██║ ██║ ██║ ██║██║ ███████╗ -;██║ ██║ ██║ ██║██║ ╚════██║ -;╚██████╔╝ ██║ ██║███████╗███████║ -; ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ -; Utils - -(define (not-equal a b) (not (= a b))) - -(define (joy-func op stack expression dict) - (values (cons (op (cadr stack) (car stack)) (cddr stack)) expression dict)) - -(define (joy-math-func op stack0) - (receive (a stack1) (pop-int stack0) - (receive (b stack) (pop-int stack1) - (cons (op b a) stack)))) - -(define (pop-any stack) - (if (null-list? stack) - (abort "Not enough values on Stack") - (car+cdr stack))) - -(define (pop-kind stack predicate message) - (receive (term rest) (pop-any stack) - (if (predicate term) (values term rest) (abort message)))) - -(define (pop-list stack) (pop-kind stack list? "Not a list.")) -(define (pop-int stack) (pop-kind stack number? "Not an integer.")) -(define (pop-bool stack) (pop-kind stack boolean? "Not a Boolean value.")) - -(define (string-replace str from to) - (string-intersperse (string-split str from #t) to)) - - ; ██████╗ ██████╗ ██████╗ ███████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗ ;██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██║ ██║██╔═══██╗██╔══██╗██╔══██╗██╔════╝ ;██║ ██║ ██║██████╔╝█████╗ ██║ █╗ ██║██║ ██║██████╔╝██║ ██║███████╗ @@ -313,6 +278,41 @@ (abort "Def name isn't symbol.")))))) +;██╗ ██╗████████╗██╗██╗ ███████╗ +;██║ ██║╚══██╔══╝██║██║ ██╔════╝ +;██║ ██║ ██║ ██║██║ ███████╗ +;██║ ██║ ██║ ██║██║ ╚════██║ +;╚██████╔╝ ██║ ██║███████╗███████║ +; ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ +; Utils + +(define (not-equal a b) (not (= a b))) + +(define (joy-math-func op stack0) + (receive (a stack1) (pop-int stack0) + (receive (b stack) (pop-int stack1) + (cons (op b a) stack)))) + +(define (pop-any stack) + (if (null-list? stack) + (abort "Not enough values on Stack") + (car+cdr stack))) + +(define (pop-kind stack predicate message) + (receive (term rest) (pop-any stack) + (if (predicate term) (values term rest) (abort message)))) + +(define (pop-list stack) (pop-kind stack list? "Not a list.")) +(define (pop-int stack) (pop-kind stack number? "Not an integer.")) +(define (pop-bool stack) (pop-kind stack boolean? "Not a Boolean value.")) + +(define (string-replace str from to) + (string-intersperse (string-split str from #t) to)) + +(define (joy-trace stack expression) + (print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression)))) + + ;██████╗ ███████╗██████╗ ██╗ ;██╔══██╗██╔════╝██╔══██╗██║ ;██████╔╝█████╗ ██████╔╝██║ @@ -325,8 +325,7 @@ (define (main-loop stack0 dict0) (let ((text (prompt))) - (if (eof-object? text) - (print) + (if (eof-object? text) (print) (receive (stack dict) (handle-exceptions exn (begin (display exn) (newline) (values stack0 dict0)) @@ -334,9 +333,6 @@ (print (joy-expression->string (reverse stack))) (main-loop stack dict))))) -(define (joy-trace stack expression) - (print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression)))) - (main-loop '() (initialize))