From 76e53604573b087c4b7da939c95b7d76dbfdb4db Mon Sep 17 00:00:00 2001 From: shhyou Date: Thu, 24 Oct 2024 21:08:06 -0500 Subject: [PATCH] Enable the `use-function-output-syntax` option for ISL and plus. Fixes #208. The printer for ISL, ISL+ and ASL relies on use-named/undefined-handler and named/undefined-handler to correctly print named lambdas. In particular, use-named/undefined-handler checks whether the option use-function-output-syntax is set. If use-function-output-syntax is not enabled, then during module instantiation, user-written functions like my-add1 would be printed differently. This also affects the error message from the check-expects. #lang htdp/isl+ (define (my-add1 n) (+ n 1)) my-add1 (check-expect my-add1 2) Output: Welcome to DrRacket. (lambda (a1) ...) Ran 1 test. 0 tests passed. check-expect ... error ... :: first argument of equality cannot be a function, given (lambda (a1) ...) > my-add1 my-add1 --- htdp-lib/htdp/bsl/runtime.rkt | 10 ++++++++-- htdp-lib/lang/htdp-langs.rkt | 2 ++ htdp-lib/lang/private/teach-module-begin.rkt | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/htdp-lib/htdp/bsl/runtime.rkt b/htdp-lib/htdp/bsl/runtime.rkt index d31a86cb..3d548420 100644 --- a/htdp-lib/htdp/bsl/runtime.rkt +++ b/htdp-lib/htdp/bsl/runtime.rkt @@ -85,11 +85,17 @@ (lambda (x) (and (sl-runtime-settings-use-function-output-syntax? settings) (procedure? x) + (and (object-name x) + (not (regexp-match? #px"[.][.][.].*[.]rkt:\\d+:\\d+" + (symbol->string (object-name x)))) + (not (regexp-match? #px"/[^/]*[.]rkt:\\d+:\\d+" + (symbol->string (object-name x))))) (object-name x)))) + ;; The ISL case -- sl-runtime-settings-output-function-instead-of-lambda? -- + ;; is already covered by the current-print-convert-hook above. (named/undefined-handler (lambda (x) - (string->symbol - (format "function:~a" (object-name x))))) + (object-name x))) ; sharing done by print-convert (show-sharing (sl-runtime-settings-show-sharing? settings)) diff --git a/htdp-lib/lang/htdp-langs.rkt b/htdp-lib/lang/htdp-langs.rkt index aec0c43a..6e2fcbac 100644 --- a/htdp-lib/lang/htdp-langs.rkt +++ b/htdp-lib/lang/htdp-langs.rkt @@ -1022,6 +1022,7 @@ (language-numbers '(-500 -500 5)) (sharing-printing #t) (abbreviate-cons-as-list #t) + (use-function-output-syntax? #t) (allow-sharing? #t) (reader-module '(lib "htdp-advanced-reader.ss" "lang")) (debugger:supported #t) @@ -1051,6 +1052,7 @@ (language-numbers '(-500 -500 4)) (sharing-printing #f) (abbreviate-cons-as-list #t) + (use-function-output-syntax? #t) (allow-sharing? #f) (reader-module '(lib "htdp-intermediate-lambda-reader.ss" "lang")) (stepper:supported #t) diff --git a/htdp-lib/lang/private/teach-module-begin.rkt b/htdp-lib/lang/private/teach-module-begin.rkt index 4f6fc4ac..ab2866f3 100644 --- a/htdp-lib/lang/private/teach-module-begin.rkt +++ b/htdp-lib/lang/private/teach-module-begin.rkt @@ -184,11 +184,14 @@ output-function-instead-of-lambda)) (mk-module-begin '(abbreviate-cons-as-list read-accept-quasiquote + use-function-output-syntax output-function-instead-of-lambda)) (mk-module-begin '(abbreviate-cons-as-list - read-accept-quasiquote)) + read-accept-quasiquote + use-function-output-syntax)) (mk-module-begin '(abbreviate-cons-as-list read-accept-quasiquote + use-function-output-syntax show-sharing)) ;; module-continue