[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-chez e038c28 09/37: more reduction on geiser:eval,
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-chez e038c28 09/37: more reduction on geiser:eval, add test |
Date: |
Sun, 1 Aug 2021 18:25:56 -0400 (EDT) |
branch: elpa/geiser-chez
commit e038c289b15d6895c78d7694c12e75129bd2f4aa
Author: Chaos Eternal <chaos@shlug.org>
Commit: Chaos Eternal <chaos@shlug.org>
more reduction on geiser:eval, add test
---
scheme/chez/geiser/geiser.ss | 58 +++++++++++++---------------
scheme/chez/geiser/test.ss | 90 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 117 insertions(+), 31 deletions(-)
diff --git a/scheme/chez/geiser/geiser.ss b/scheme/chez/geiser/geiser.ss
index ca50295..8b9aba7 100644
--- a/scheme/chez/geiser/geiser.ss
+++ b/scheme/chez/geiser/geiser.ss
@@ -34,37 +34,33 @@
(if module
(eval form (environment module))
(eval form))))
- (result-mid (call-with-values
- (lambda ()
- (call/cc
- (lambda (k)
- (with-exception-handler
- (lambda (e)
- (k 'error e))
- (lambda ()
- (call-with-values
- (lambda ()
- (body))
- (lambda (x . y)
- (if (null? y)
- (k 'single x)
- (k 'multi (cons x y))))))))))
- (lambda (t v)
- (cons t v))))
- (result (if (eq? (car result-mid) 'error)
- ""
- (with-output-to-string
- (lambda ()
- (pretty-print (cdr result-mid))))))
- (error (if (eq? (car result-mid) 'error)
- (cons 'error (list
- (cons 'key
- (with-output-to-string
- (lambda () (display-condition (cdr
result-mid)))))))
- '())))
- (write `((result ,result)
- (output . "")
- ,error))
+ (gen-result (lambda (result-mid is-error?)
+ (if is-error?
+ `((result "")
+ (output . "")
+ (error . ,(list
+ (cons 'key
+ (with-output-to-string
+ (lambda ()
+ (display-condition
result-mid)))))))
+ `((result ,(with-output-to-string
+ (lambda ()
+ (pretty-print result-mid))))
+ (output . "")))))
+ (result (call/cc
+ (lambda (k)
+ (with-exception-handler
+ (lambda (e)
+ (k (gen-result e #t)))
+ (lambda ()
+ (call-with-values
+ (lambda ()
+ (body))
+ (lambda (x . y)
+ (if (null? y)
+ (k (gen-result x #f))
+ (k (gen-result (cons x y) #f)))))))))))
+ (write result)
(newline)))
(define (geiser:module-completions prefix . rest)
diff --git a/scheme/chez/geiser/test.ss b/scheme/chez/geiser/test.ss
new file mode 100644
index 0000000..ac5503b
--- /dev/null
+++ b/scheme/chez/geiser/test.ss
@@ -0,0 +1,90 @@
+(import (geiser)
+ (chezscheme))
+
+
+(define-syntax get-result
+ (syntax-rules ()
+ ((_ form)
+ (with-output-to-string
+ (lambda ()
+ (geiser:eval #f form))))))
+
+(define-syntax do-test
+ (syntax-rules ()
+ ((_ form result)
+ (assert
+ (equal?
+ (get-result form)
+ result)))))
+
+;; (something-doesnot-exist)
+;;=> Error: Exception: variable something-doesnot-exist is not bound
+(do-test
+ '(something-doesnot-exist)
+ "((result \"\") (output . \"\") (error (key . \"Exception: variable
something-doesnot-exist is not bound\")))\n"
+ )
+
+;; (make-violation)
+;;=> #<condition &violation>
+(do-test
+ '(make-violation)
+ "((result \"#<condition &violation>\\n\") (output . \"\"))\n")
+
+;; (values 1 2 3)
+;;==> (1 2 3)
+(do-test
+ '(values 1 2 3)
+ "((result \"(1 2 3)\\n\") (output . \"\"))\n")
+
+;; 1
+;;=> 1
+(do-test '1 "((result \"1\\n\") (output . \"\"))\n")
+
+
+;; '(case-lambda
+;; [(x1 x2) (+ x1 x2)]
+;; [(x1 x2 x3) (+ (+ x1 x2) x3)]
+;; [(x1 x2 . rest)
+;; ((letrec ([loop (lambda (x1 x2 rest)
+;; (let ([x (+ x1 x2)])
+;; (if (null? rest)
+;; x
+;; (loop x (car rest) (cdr rest)))))])
+;; loop)
+;; x1
+;; x2
+;; rest)]
+;; [(x1) (+ x1)]
+;; [() (+)])
+#|=> (case-lambda
+ [(x1 x2) (+ x1 x2)]
+ [(x1 x2 x3) (+ (+ x1 x2) x3)]
+ [(x1 x2 . rest)
+ ((letrec ([loop (lambda (x1 x2 rest)
+ (let ([x (+ x1 x2)])
+ (if (null? rest)
+ x
+ (loop x (car rest) (cdr rest)))))])
+ loop)
+ x1
+ x2
+ rest)]
+ [(x1) (+ x1)]
+ [() (+)])
+ |#
+(do-test (quote '(case-lambda
+ [(x1 x2) (+ x1 x2)]
+ [(x1 x2 x3) (+ (+ x1 x2) x3)]
+ [(x1 x2 . rest)
+ ((letrec ([loop (lambda (x1 x2 rest)
+ (let ([x (+ x1 x2)])
+ (if (null? rest)
+ x
+ (loop x (car rest) (cdr rest)))))])
+ loop)
+ x1
+ x2
+ rest)]
+ [(x1) (+ x1)]
+ [() (+)])) "((result \"(case-lambda\\n [(x1 x2) (+ x1 x2)]\\n [(x1 x2 x3)
(+ (+ x1 x2) x3)]\\n [(x1 x2 . rest)\\n ((letrec ([loop (lambda (x1 x2
rest)\\n (let ([x (+ x1 x2)])\\n (if
(null? rest)\\n x\\n (loop
x (car rest) (cdr rest)))))])\\n loop)\\n x1\\n x2\\n
rest)]\\n [(x1) (+ x1)]\\n [() (+)])\\n\") (output . \"\"))\n")
+
- [nongnu] elpa/geiser-chez 7bc8f62 14/37: Capture stdout in ChezScheme's eval:geiser, (continued)
- [nongnu] elpa/geiser-chez 7bc8f62 14/37: Capture stdout in ChezScheme's eval:geiser, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 352515c 16/37: Begin the summary lines of all elisp libraries with three semicolons, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez a0f6fc3 15/37: Add rudimentary Chez support for macro expansion, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 146d4a7 18/37: Fix indentation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 9d66c63 24/37: chez: pretty printing macroexpand results., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 502b3ac 20/37: Use cl-lib instead of cl, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 086dbba 23/37: make chez display output and error messages., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 94296d8 25/37: files moved from original import locations, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 111ecdd 26/37: scheme load path adjustments, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 055e43d 27/37: license and readme, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez e038c28 09/37: more reduction on geiser:eval, add test,
Philip Kaludercic <=
- [nongnu] elpa/geiser-chez 6eb6a92 10/37: simple geiser-chez--display-error, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 591c794 17/37: Mark the beginning of code part of elisp libraries with Code: heading, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez fcb2a6a 22/37: add extra parameter support to chez, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 21bc5bb 19/37: Delete trailing whitespace, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 6b9b733 12/37: Add geiser-chez-init-file, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 755a7cc 21/37: add extra parameter support to chez implementation, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez 98999d7 28/37: typo, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez dbebff9 31/37: preparing MELPA submission, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez e8065b4 33/37: compilation warnings (unused variable), Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chez fe3d881 36/37: whitespace, Philip Kaludercic, 2021/08/01