diff --git a/drracket-core-lib/drracket/private/colored-errors.rkt b/drracket-core-lib/drracket/private/colored-errors.rkt index 7f7778d2e..01ef1642e 100644 --- a/drracket-core-lib/drracket/private/colored-errors.rkt +++ b/drracket-core-lib/drracket/private/colored-errors.rkt @@ -47,15 +47,16 @@ ;; of additional source locations. These additional location will also be highlighted in the code, ;; even though they do not correspond to any section of the text of the error message. (struct colored-error-message (fragments additional-highlights) #:transparent) -(provide/contract [struct colored-error-message - ([fragments (listof msg-fragment?)] - [additional-highlights additional-highlights/c])] - [struct msg-fragment:str ([str string?])] - [struct msg-fragment:v ([v any/c])] - [struct colored-msg-fragment ([locs srcloc-syntax/c] - [frags (listof (or/c msg-fragment:str? msg-fragment:v?))] - [important boolean?] - [color color/c])]) +(provide (contract-out (struct colored-error-message + ([fragments (listof msg-fragment?)] [additional-highlights + additional-highlights/c])) + (struct msg-fragment:str ([str string?])) + (struct msg-fragment:v ([v any/c])) + (struct colored-msg-fragment + ([locs srcloc-syntax/c] + [frags (listof (or/c msg-fragment:str? msg-fragment:v?))] + [important boolean?] + [color color/c])))) ;; prop:exn:colored-message : The property of exceptions that contain colored-message information. ;; The property's value is a function that when given an exception, returns the colored-error-message. @@ -72,7 +73,7 @@ ;; get-error-message/color : When given an exception, if that exception contains coloring information, ;; returns it, otherwise, returns a colored-error-message that capture the information provided by ;; by field message and the srclocs property (if any) of the exception. -(provide/contract [get-error-message/color (exn? . -> . colored-error-message?)]) +(provide (contract-out [get-error-message/color (exn? . -> . colored-error-message?)])) (define (get-error-message/color exn) (cond [(exn:colored-message? exn) ((exn:colored-message-accessor exn) exn)] [(exn:srclocs? exn) @@ -81,11 +82,13 @@ [else (colored-error-message (list (msg-fragment:str (exn-message exn))) empty)])) -(provide/contract [get-error-colored-srclocs (exn? . -> . (listof (list/c srcloc-syntax/c color/c)))]) +(provide (contract-out [get-error-colored-srclocs + (exn? . -> . (listof (list/c srcloc-syntax/c color/c)))])) (define (get-error-colored-srclocs exn) (get-message-colored-srclocs (get-error-message/color exn))) -(provide/contract [get-message-colored-srclocs (colored-error-message? . -> . (listof (list/c srcloc-syntax/c color/c)))]) +(provide (contract-out [get-message-colored-srclocs + (colored-error-message? . -> . (listof (list/c srcloc-syntax/c color/c)))])) (define (get-message-colored-srclocs msg) (define (promote srcloc) (if (list? srcloc) srcloc (list srcloc #f))) (map promote @@ -165,12 +168,12 @@ (check-arg "~|" args 1) (define-values (sub rest-args) (let loop ([fragments fragments] [args (rest args)]) - (if (empty? fragments) - (values empty args) - (let () - (define-values (f rest-args) (colored-format:str-or-v (first fragments) args)) - (define-values (rest-fs rest-rest-args) (loop (rest fragments) rest-args)) - (values (cons f rest-fs) rest-rest-args))))) + (cond + [(empty? fragments) (values empty args)] + [else + (define-values (f rest-args) (colored-format:str-or-v (first fragments) args)) + (define-values (rest-fs rest-rest-args) (loop (rest fragments) rest-args)) + (values (cons f rest-fs) rest-rest-args)]))) (define the-arg (first args)) (match the-arg [(list loc imp col other ..1) @@ -190,7 +193,7 @@ (define colored-format/c (([fmt string?]) (#:additional-highlights [additional-highlights additional-highlights/c]) #:rest [_ any/c] . ->i . [_ colored-error-message?])) -(provide/contract [colored-format colored-format/c]) +(provide (contract-out [colored-format colored-format/c])) ;; colored-format : Takes a format string and a number of arguments, and produces a string where each ;; format marker has been replaced by their corresponding argument. This function support @@ -279,7 +282,7 @@ ;; The message and srcloc fields of the exception are populated from the information ;; in the fmt. additional-highlights specifies srclocs that should be highlighted, in addition ;; to the highlights used to explicate the correspondance between the text and the piece of codes. -(provide/contract [raise-colored-syntax-error colored-format/c]) +(provide (contract-out [raise-colored-syntax-error colored-format/c])) (define (raise-colored-syntax-error fmt #:additional-highlights [additional-highlights empty] . args) (define formatted (apply colored-format fmt #:additional-highlights additional-highlights args)) (raise (exn:fail:colored:syntax (uncolor-message formatted) diff --git a/drracket-core-lib/drracket/private/insulated-read-language.rkt b/drracket-core-lib/drracket/private/insulated-read-language.rkt index 935bce4a7..3a4292aa6 100644 --- a/drracket-core-lib/drracket/private/insulated-read-language.rkt +++ b/drracket-core-lib/drracket/private/insulated-read-language.rkt @@ -266,8 +266,7 @@ Will not work with the definitions text surrogate interposition that (λ () (val text start-position limit-position direction)))))] [(drracket:keystrokes) (for/list ([pr (in-list val)]) - (define key (list-ref pr 0)) - (define proc (list-ref pr 1)) + (match-define (list key proc) pr) (list key (procedure-rename (λ (txt evt) (call-in-irl-context/abort @@ -440,9 +439,8 @@ Will not work with the definitions text surrogate interposition that [(and (equal? p1 #\|) (equal? (peek-char-or-special port 1) #\#)) (get-it "|#") - (cond - [(= depth 0) (void)] - [else (loop (- depth 1))])] + (unless (= depth 0) + (loop (- depth 1)))] [(and (equal? p1 #\#) (equal? (peek-char-or-special port 1) #\|)) (get-it "#|") diff --git a/drracket-core-lib/drracket/private/syncheck-debug.rkt b/drracket-core-lib/drracket/private/syncheck-debug.rkt index 01717dbd7..9d2553fef 100644 --- a/drracket-core-lib/drracket/private/syncheck-debug.rkt +++ b/drracket-core-lib/drracket/private/syncheck-debug.rkt @@ -10,156 +10,148 @@ ;; origin and source fields of an expanded sexp ;; also the 'bound-in-source syntax property - (define debug-origin - (case-lambda - [(original-object) (debug-origin original-object (expand original-object))] - [(original-object expanded-object) - (define-values (expanded-datum stx-ht) (syntax-object->datum/ht expanded-object)) - - (define output-text (make-object text%)) - (define output-port (make-text-port output-text)) - (define info-text (make-object text%)) - (define info-port (make-text-port info-text)) - - ;; assume that there aren't any eq? sub structures, only eq? flat stuff (symbols, etc) - ;; this is guaranteed by syntax-object->datum/ht - (define range-start-ht (make-hasheq)) - (define range-ht (make-hasheq)) - (define original-output-port (current-output-port)) - (define (range-pretty-print-pre-hook x v) - (hash-set! range-start-ht x (send output-text last-position))) - (define (range-pretty-print-post-hook x v) - (hash-set! range-ht x - (cons - (cons - (hash-ref range-start-ht x) - (send output-text last-position)) - (hash-ref range-ht x (λ () null))))) - - (define (make-modern text) - (send text change-style - (make-object style-delta% 'change-family 'modern) - 0 - (send text last-position))) - - (define dummy - (begin (pretty-print (syntax->datum original-object) output-port) - (newline output-port) - (parameterize ([current-output-port output-port] - [pretty-print-pre-print-hook range-pretty-print-pre-hook] - [pretty-print-post-print-hook range-pretty-print-post-hook] - [pretty-print-columns 30]) - (pretty-print expanded-datum)) - (make-modern output-text))) - - (define ranges - (sort - (apply append (hash-map range-ht (λ (k vs) (map (λ (v) (cons k v)) vs)))) - (λ (x y) - (<= (- (car (cdr x)) (cdr (cdr x))) - (- (car (cdr y)) (cdr (cdr y))))))) - - (define (show-info stx) - (fprintf info-port "datum: ~s\nsource: ~a\nposition: ~s\noffset: ~s\noriginal: ~s\nbound-in-source: ~s\n\n" - (syntax->datum stx) - (syntax-source stx) - (syntax-position stx) - (syntax-span stx) - (syntax-original? stx) - (syntax-property stx 'bound-in-source)) - (let loop ([origin (syntax-property stx 'origin)]) - (cond - [(pair? origin) - (loop (car origin)) - (loop (cdr origin))] - [(syntax? origin) - (display " " info-port) - (display origin info-port) - (newline info-port) - (fprintf info-port - " original? ~a\n datum:\n ~a\n\n" - (and (syntax? origin) (syntax-original? origin)) - (and (syntax? origin) (syntax->datum origin)))] - [else (void)]))) - - (for-each - (λ (range) - (let* ([obj (car range)] - [stx (hash-ref stx-ht obj)] - [start (cadr range)] - [end (cddr range)]) - (when (syntax? stx) - (send output-text set-clickback start end - (λ _ - (send info-text begin-edit-sequence) - (send info-text erase) - (show-info stx) - (make-modern info-text) - (send info-text end-edit-sequence)))))) - ranges) - - (newline output-port) - (newline output-port) - (let ([before (send output-text last-position)]) - (display "all" output-port) - (send output-text set-clickback - before - (send output-text last-position) - (λ _ - (send info-text begin-edit-sequence) - (send info-text erase) - (for-each (λ (rng) - (let ([stx (hash-ref stx-ht (car rng))]) - (when (syntax? stx) - (show-info stx)))) - ranges) - (make-modern info-text) - (send info-text end-edit-sequence)))) - - (let () - (define f (make-object frame% "Syntax 'origin Browser" #f 600 300)) - (define p (make-object horizontal-panel% f)) - (make-object editor-canvas% p output-text) - (make-object editor-canvas% p info-text) - (send f show #t))])) + (define (debug-origin original-object [expanded-object (expand original-object)]) + (define-values (expanded-datum stx-ht) (syntax-object->datum/ht expanded-object)) + + (define output-text (make-object text%)) + (define output-port (make-text-port output-text)) + (define info-text (make-object text%)) + (define info-port (make-text-port info-text)) + + ;; assume that there aren't any eq? sub structures, only eq? flat stuff (symbols, etc) + ;; this is guaranteed by syntax-object->datum/ht + (define range-start-ht (make-hasheq)) + (define range-ht (make-hasheq)) + (define original-output-port (current-output-port)) + (define (range-pretty-print-pre-hook x v) + (hash-set! range-start-ht x (send output-text last-position))) + (define (range-pretty-print-post-hook x v) + (hash-set! range-ht + x + (cons (cons (hash-ref range-start-ht x) (send output-text last-position)) + (hash-ref range-ht x (λ () null))))) + + (define (make-modern text) + (send text change-style + (make-object style-delta% 'change-family 'modern) + 0 + (send text last-position))) + + (define dummy + (begin + (pretty-print (syntax->datum original-object) output-port) + (newline output-port) + (parameterize ([current-output-port output-port] + [pretty-print-pre-print-hook range-pretty-print-pre-hook] + [pretty-print-post-print-hook range-pretty-print-post-hook] + [pretty-print-columns 30]) + (pretty-print expanded-datum)) + (make-modern output-text))) + + (define ranges + (sort (apply append (hash-map range-ht (λ (k vs) (map (λ (v) (cons k v)) vs)))) + (λ (x y) (<= (- (car (cdr x)) (cdr (cdr x))) (- (car (cdr y)) (cdr (cdr y))))))) + + (define (show-info stx) + (fprintf + info-port + "datum: ~s\nsource: ~a\nposition: ~s\noffset: ~s\noriginal: ~s\nbound-in-source: ~s\n\n" + (syntax->datum stx) + (syntax-source stx) + (syntax-position stx) + (syntax-span stx) + (syntax-original? stx) + (syntax-property stx 'bound-in-source)) + (let loop ([origin (syntax-property stx 'origin)]) + (cond + [(pair? origin) + (loop (car origin)) + (loop (cdr origin))] + [(syntax? origin) + (display " " info-port) + (display origin info-port) + (newline info-port) + (fprintf info-port + " original? ~a\n datum:\n ~a\n\n" + (and (syntax? origin) (syntax-original? origin)) + (and (syntax? origin) (syntax->datum origin)))] + [else (void)]))) + + (for-each (λ (range) + (let* ([obj (car range)] + [stx (hash-ref stx-ht obj)] + [start (cadr range)] + [end (cddr range)]) + (when (syntax? stx) + (send output-text set-clickback + start + end + (λ _ + (send info-text begin-edit-sequence) + (send info-text erase) + (show-info stx) + (make-modern info-text) + (send info-text end-edit-sequence)))))) + ranges) + + (newline output-port) + (newline output-port) + (let ([before (send output-text last-position)]) + (display "all" output-port) + (send output-text set-clickback + before + (send output-text last-position) + (λ _ + (send info-text begin-edit-sequence) + (send info-text erase) + (for-each (λ (rng) + (let ([stx (hash-ref stx-ht (car rng))]) + (when (syntax? stx) + (show-info stx)))) + ranges) + (make-modern info-text) + (send info-text end-edit-sequence)))) + + (let () + (define f (make-object frame% "Syntax 'origin Browser" #f 600 300)) + (define p (make-object horizontal-panel% f)) + (make-object editor-canvas% p output-text) + (make-object editor-canvas% p info-text) + (send f show #t))) ;; build-ht : stx -> hash-table ;; the resulting hash-table maps from the each sub-object's to its syntax. (define (syntax-object->datum/ht stx) - (let ([ht (make-hasheq)]) - (values (let loop ([stx stx]) - (let ([obj (syntax-e stx)]) - (cond - [(list? obj) - (let ([res (map loop obj)]) - (hash-set! ht res stx) - res)] - [(pair? obj) - (let ([res (cons (loop (car obj)) - (loop (cdr obj)))]) - (hash-set! ht res stx) - res)] - [(vector? obj) - (let ([res (list->vector (map loop (vector->list obj)))]) - (hash-set! ht res stx) - res)] - [else - (let ([res (syntax->datum stx)]) - (hash-set! ht res stx) - res)]))) - ht))) + (define ht (make-hasheq)) + (values (let loop ([stx stx]) + (let ([obj (syntax-e stx)]) + (cond + [(list? obj) + (let ([res (map loop obj)]) + (hash-set! ht res stx) + res)] + [(pair? obj) + (let ([res (cons (loop (car obj)) (loop (cdr obj)))]) + (hash-set! ht res stx) + res)] + [(vector? obj) + (let ([res (list->vector (map loop (vector->list obj)))]) + (hash-set! ht res stx) + res)] + [else + (let ([res (syntax->datum stx)]) + (hash-set! ht res stx) + res)]))) + ht)) ;; make-text-port : text -> port ;; builds a port from a text object. (define (make-text-port text) - (let-values ([(in out) (make-pipe)]) - (thread - (λ () - (let loop () - (let ([c (read-char in)]) - (unless (eof-object? c) - (send text insert (string c) - (send text last-position) - (send text last-position)) - (loop)))))) - out)) + (define-values (in out) (make-pipe)) + (thread (λ () + (let loop () + (let ([c (read-char in)]) + (unless (eof-object? c) + (send text insert (string c) (send text last-position) (send text last-position)) + (loop)))))) + out) diff --git a/drracket-core-lib/drracket/private/tool-contract-language.rkt b/drracket-core-lib/drracket/private/tool-contract-language.rkt index 0c9d2affe..abc17bcac 100644 --- a/drracket-core-lib/drracket/private/tool-contract-language.rkt +++ b/drracket-core-lib/drracket/private/tool-contract-language.rkt @@ -59,23 +59,19 @@ body)))))])))))))] [(_ (name type type-names strs ...) ...) (begin - (for-each - (λ (str-stx) - (when (string? (syntax->datum str-stx)) - (raise-syntax-error 'tool-contract-language.rkt "expected type name specification" - stx - str-stx))) - (syntax->list (syntax (type-names ...)))) - (for-each - (λ (name) - (unless (identifier? name) - (raise-syntax-error 'tool-contract-language.rkt "expected identifier" stx name))) - (syntax->list (syntax (name ...)))) - (for-each - (λ (str) - (unless (string? (syntax->datum str)) - (raise-syntax-error 'tool-contract-language.rkt "expected docs string" stx str))) - (apply append (map syntax->list (syntax->list (syntax ((strs ...) ...)))))))])) + (for ([str-stx (in-list (syntax->list (syntax (type-names ...))))]) + (when (string? (syntax->datum str-stx)) + (raise-syntax-error 'tool-contract-language.rkt + "expected type name specification" + stx + str-stx))) + (for ([name (in-list (syntax->list (syntax (name ...))))]) + (unless (identifier? name) + (raise-syntax-error 'tool-contract-language.rkt "expected identifier" stx name))) + (for ([str (in-list (apply append + (map syntax->list (syntax->list (syntax ((strs ...) ...))))))]) + (unless (string? (syntax->datum str)) + (raise-syntax-error 'tool-contract-language.rkt "expected docs string" stx str))))])) (define-syntax (-#%module-begin2 stx) (syntax-case stx () @@ -116,20 +112,16 @@ body)))]))))))] [(_ (name type type-names strs ...) ...) (begin - (for-each - (λ (str-stx) - (when (string? (syntax->datum str-stx)) - (raise-syntax-error 'tool-contract-language.rkt "expected type name specification" - stx - str-stx))) - (syntax->list (syntax (type-names ...)))) - (for-each - (λ (name) - (unless (identifier? name) - (raise-syntax-error 'tool-contract-language.rkt "expected identifier" stx name))) - (syntax->list (syntax (name ...)))) - (for-each - (λ (str) - (unless (string? (syntax->datum str)) - (raise-syntax-error 'tool-contract-language.rkt "expected docs string" stx str))) - (apply append (map syntax->list (syntax->list (syntax ((strs ...) ...)))))))])) + (for ([str-stx (in-list (syntax->list (syntax (type-names ...))))]) + (when (string? (syntax->datum str-stx)) + (raise-syntax-error 'tool-contract-language.rkt + "expected type name specification" + stx + str-stx))) + (for ([name (in-list (syntax->list (syntax (name ...))))]) + (unless (identifier? name) + (raise-syntax-error 'tool-contract-language.rkt "expected identifier" stx name))) + (for ([str (in-list (apply append + (map syntax->list (syntax->list (syntax ((strs ...) ...))))))]) + (unless (string? (syntax->datum str)) + (raise-syntax-error 'tool-contract-language.rkt "expected docs string" stx str))))])) diff --git a/drracket-core-lib/drracket/sprof.rkt b/drracket-core-lib/drracket/sprof.rkt index 6245bdfd0..bc665d140 100644 --- a/drracket-core-lib/drracket/sprof.rkt +++ b/drracket-core-lib/drracket/sprof.rkt @@ -16,9 +16,9 @@ (sleep pause-time) (define new-traces (map (λ (t) (continuation-mark-set->context (continuation-marks t))) (get-threads))) - (for ([trace (in-list new-traces)]) - (for ([line (in-list trace)]) - (hash-set! traces-table line (cons trace (hash-ref traces-table line '()))))) + (for* ([trace (in-list new-traces)] + [line (in-list trace)]) + (hash-set! traces-table line (cons trace (hash-ref traces-table line '())))) (cond [(zero? i) (update-gui traces-table) diff --git a/drracket/help/private/save-bug-report.rkt b/drracket/help/private/save-bug-report.rkt index c8f5064f3..82fe323e3 100644 --- a/drracket/help/private/save-bug-report.rkt +++ b/drracket/help/private/save-bug-report.rkt @@ -89,12 +89,9 @@ (λ (bug-reports) (define ids (map saved-report-id bug-reports)) (define new-id - (let loop ([i 0]) - (cond - [(member i ids) - (loop (+ i 1))] - [else - i]))) + (for/first ([i (in-naturals 0)] + #:unless (member i ids)) + i)) (set! ans (blank-bug-form new-id)) (cons ans bug-reports))) ans)