A start on error reporting.
I outfitted `rest` with some error reporting and tried out exception handling. So far so good. One issue is that the dictionary is not a persistent datastructure, so if there was an "inscribe" command (it's not yet implemented for this Scheme implementation) that might be slightly problematical. (If an error were to occur in an evaluation that had already entered new definitions into the dict then those definitions would "survive" into the rest of the REPL session (or whatever.)) I'll look into persistent dict for Scheme.
This commit is contained in:
parent
d0623508bd
commit
b116c2c98b
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
(import (chicken io))
|
(import (chicken io))
|
||||||
(import (chicken string))
|
(import (chicken string))
|
||||||
|
(import srfi-12)
|
||||||
(import srfi-69)
|
(import srfi-69)
|
||||||
(import matchable)
|
(import matchable)
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@
|
||||||
((concat) (joy-func append stack expression dict))
|
((concat) (joy-func append stack expression dict))
|
||||||
((cons) (joy-func cons stack expression dict))
|
((cons) (joy-func cons stack expression dict))
|
||||||
((first) (values (cons (caar stack) (cdr stack)) expression dict))
|
((first) (values (cons (caar stack) (cdr stack)) expression dict))
|
||||||
((rest) (values (cons (cdar stack) (cdr stack)) expression dict))
|
((rest) (values (joy-rest stack) expression dict))
|
||||||
|
|
||||||
((i) (joy-i stack expression dict))
|
((i) (joy-i stack expression dict))
|
||||||
((dip) (joy-dip stack expression dict))
|
((dip) (joy-dip stack expression dict))
|
||||||
|
|
@ -106,6 +107,16 @@
|
||||||
(else #t)))
|
(else #t)))
|
||||||
|
|
||||||
|
|
||||||
|
(define (joy-rest stack)
|
||||||
|
(match stack
|
||||||
|
(() (abort "Not enough values on Stack"))
|
||||||
|
((head . tail)
|
||||||
|
(match head
|
||||||
|
(() (abort "Cannot take rest of empty list."))
|
||||||
|
((_ . the_rest) (cons the_rest tail))
|
||||||
|
(_ (abort "Not a list."))))))
|
||||||
|
|
||||||
|
|
||||||
; ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗███╗ ██╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
|
; ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗███╗ ██╗ █████╗ ████████╗ ██████╗ ██████╗ ███████╗
|
||||||
;██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║████╗ ██║██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
|
;██╔════╝██╔═══██╗████╗ ████║██╔══██╗██║████╗ ██║██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
|
||||||
;██║ ██║ ██║██╔████╔██║██████╔╝██║██╔██╗ ██║███████║ ██║ ██║ ██║██████╔╝███████╗
|
;██║ ██║ ██║██╔████╔██║██████╔╝██║██╔██╗ ██║███████║ ██║ ██║ ██║██████╔╝███████╗
|
||||||
|
|
@ -243,7 +254,11 @@
|
||||||
(define (main-loop stack0 dict0)
|
(define (main-loop stack0 dict0)
|
||||||
(let ((text (prompt)))
|
(let ((text (prompt)))
|
||||||
(if (not (eof-object? text))
|
(if (not (eof-object? text))
|
||||||
(receive (stack dict) (joy stack0 (text->expression text) dict0)
|
(receive (stack dict)
|
||||||
|
(handle-exceptions exn
|
||||||
|
(begin (display exn) (newline)
|
||||||
|
(values stack0 dict0))
|
||||||
|
(joy stack0 (text->expression text) dict0))
|
||||||
(print (joy-expression->string (reverse stack)))
|
(print (joy-expression->string (reverse stack)))
|
||||||
(main-loop stack dict))
|
(main-loop stack dict))
|
||||||
(print))))
|
(print))))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue