Skip to content

Commit aef9ae1

Browse files
committed
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
1 parent 3eab980 commit aef9ae1

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

htdp-lib/htdp/bsl/runtime.rkt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@
8787
(and (sl-runtime-settings-use-function-output-syntax? settings)
8888
(procedure? x)
8989
(object-name x))))
90+
;; The ISL case -- sl-runtime-settings-output-function-instead-of-lambda? --
91+
;; is already covered by the current-print-convert-hook above.
9092
(named/undefined-handler
9193
(lambda (x)
92-
(string->symbol
93-
(format "function:~a" (object-name x)))))
94+
(object-name x)))
9495

9596
; sharing done by print-convert
9697
(show-sharing (sl-runtime-settings-show-sharing? settings))

htdp-lib/lang/htdp-langs.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@
10221022
(language-numbers '(-500 -500 5))
10231023
(sharing-printing #t)
10241024
(abbreviate-cons-as-list #t)
1025+
(use-function-output-syntax? #t)
10251026
(allow-sharing? #t)
10261027
(reader-module '(lib "htdp-advanced-reader.ss" "lang"))
10271028
(debugger:supported #t)
@@ -1051,6 +1052,7 @@
10511052
(language-numbers '(-500 -500 4))
10521053
(sharing-printing #f)
10531054
(abbreviate-cons-as-list #t)
1055+
(use-function-output-syntax? #t)
10541056
(allow-sharing? #f)
10551057
(reader-module '(lib "htdp-intermediate-lambda-reader.ss" "lang"))
10561058
(stepper:supported #t)

htdp-lib/lang/private/teach-module-begin.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@
184184
output-function-instead-of-lambda))
185185
(mk-module-begin '(abbreviate-cons-as-list
186186
read-accept-quasiquote
187+
use-function-output-syntax
187188
output-function-instead-of-lambda))
188189
(mk-module-begin '(abbreviate-cons-as-list
189-
read-accept-quasiquote))
190+
read-accept-quasiquote
191+
use-function-output-syntax))
190192
(mk-module-begin '(abbreviate-cons-as-list
191193
read-accept-quasiquote
194+
use-function-output-syntax
192195
show-sharing))
193196

194197
;; module-continue

htdp-lib/lang/private/teach.rkt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@
164164
(define-for-syntax (stepper-ignore-checker stx)
165165
(stepper-syntax-property stx 'stepper-skipto '(syntax-e cdr syntax-e cdr car)))
166166

167+
168+
;; wrap-lambda-remove-name: syntax? -> syntax?
169+
;; Removes source-location names for lambdas by erasing the source location
170+
;; Preserves the lexical context, the syntax properties, but removes the source location
171+
(define-for-syntax (wrap-lambda-remove-name stx)
172+
(cond [(syntax-local-name) stx]
173+
[else (datum->syntax stx (syntax-e stx) #f stx)]))
174+
167175
(define-for-syntax (map-with-index proc . lists)
168176
(let loop ([i 0] [lists lists] [rev-result '()])
169177
(if (null? (car lists))
@@ -2297,7 +2305,8 @@
22972305
stx
22982306
(syntax->list (syntax (lexpr ...)))
22992307
args)
2300-
(syntax/loc stx (lambda arg-seq lexpr ...)))]
2308+
(wrap-lambda-remove-name
2309+
(syntax/loc stx (lambda arg-seq lexpr ...))))]
23012310
;; Bad lambda because bad args:
23022311
[(_ args . __)
23032312
(teach-syntax-error
@@ -2504,7 +2513,8 @@
25042513
stx
25052514
(syntax->list (syntax exprs))
25062515
names)
2507-
(syntax/loc stx (lambda (name ...) . exprs)))]
2516+
(wrap-lambda-remove-name
2517+
(syntax/loc stx (lambda (name ...) . exprs))))]
25082518
[(_ args . __)
25092519
(teach-syntax-error
25102520
'lambda

htdp-test/tests/htdp-lang/intm-lam.rktl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
exn:fail:contract?
44
#rx"map: first argument must be a function that expects one argument"))
55

6-
(htdp-err/rt-test (map (lambda (x y) (+ x y)) (list 2 3 4))
7-
(exn-type-and-msg
8-
exn:fail:contract?
9-
#rx"intm-lam.rktl"))
10-
116
(htdp-err/rt-test (foldr (lambda (x y) (+ x y)) 0 (list 2 3 4) (list 2 3 4))
127
(exn-type-and-msg
138
exn:fail:contract?

0 commit comments

Comments
 (0)