From d014709a32c987a3748b332d9f92cd8a2875e089 Mon Sep 17 00:00:00 2001 From: sforman Date: Fri, 11 Aug 2023 08:50:00 -0700 Subject: [PATCH] Load defs from defs.txt. They are loaded at runtime though :( shouldn't be too hard to fix that? --- implementations/scheme-chicken/joy.scm | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 6a91587..f9abca0 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -1,6 +1,8 @@ +(import (chicken io)) (import (chicken string)) (import srfi-69) + (define (joy stack expression dict) (if (null? expression) (values stack dict) @@ -78,25 +80,26 @@ (string-intersperse (map joy-term->string expr) " ")) (define (doit text) - (receive (stack dict) - (joy '() (text->expression text) '()) + (receive (stack _dict) + (joy '() (text->expression text) (initialize)) (joy-expression->string stack))) -(define (initialize defs dict) - (map (lambda (def) (add-def dict def)) (string-split defs "\n"))) +(define (initialize) + (load-defs + ; TODO: load defs at compile-time, not run-time. + (with-input-from-file "../defs.txt" read-string) + (make-hash-table string=? string-hash))) + +(define (load-defs defs dict) + (map (lambda (def) (add-def def dict)) (string-split defs "\n")) + dict) (define (add-def def dict) (let ((def_list (text->expression def))) (hash-table-set! dict (car def_list) (cdr def_list)))) - - - - - - (display (doit "ab cd [[ ]] 23 4 - dup - [true] false")) (newline)