option for line numbers for report macro #1

Closed
opened 10 years ago by AlexKnauth · 2 comments
AlexKnauth commented 10 years ago (Migrated from github.com)

I think something like this would be a nice option to have:

(define x 5)
(report x #:line) ; x = 5 at line 2

Or maybe this:

(define x 5)
(parameterize ([report-line-number #t])
  (report x)) ; x = 5 at line 3

Or maybe something where drracket can show one of those octagons with 'x's in them like it shows if you do this in drracket: (if it's possible without messing it up for other stuff)

(with-handlers ([exn:fail:syntax? (lambda (e) ((error-display-handler) "x = 5" e))])
  (raise-syntax-error #f "whatever" #'here))
I think something like this would be a nice option to have: ``` racket (define x 5) (report x #:line) ; x = 5 at line 2 ``` Or maybe this: ``` racket (define x 5) (parameterize ([report-line-number #t]) (report x)) ; x = 5 at line 3 ``` Or maybe something where drracket can show one of those octagons with 'x's in them like it shows if you do this in drracket: (if it's possible without messing it up for other stuff) ``` racket (with-handlers ([exn:fail:syntax? (lambda (e) ((error-display-handler) "x = 5" e))]) (raise-syntax-error #f "whatever" #'here)) ```
mbutterick commented 10 years ago (Migrated from github.com)

Interesting suggestion, though I have had difficulty getting keyword arguments to work smoothly in macros (perhaps it could just be (report-with-line ...).

Does parameterize work with macros? I thought it was strictly a way of manipulating the runtime namespace.

Interesting suggestion, though I have had difficulty getting keyword arguments to work smoothly in macros (perhaps it could just be `(report-with-line ...)`. Does `parameterize` work with macros? I thought it was strictly a way of manipulating the runtime namespace.
AlexKnauth commented 10 years ago (Migrated from github.com)

For parameterize, it can expand to code that would do something different depending on the value of the parameter.

(define-syntax (report stx)
  (syntax-case stx ()
    [(_ expr) #'(report expr expr)]
    [(_ expr name)
     #`(let ([x expr])
         (display-for-report x 'name #,(syntax-line #'expr))
         x)]))
(define (display-for-report x name line)
  (cond [(report-line-number)
         (displayln (format "~a = ~v at line ~a" name x line) (current-error-port))]
        [else
         (displayln (format "~a = ~v" name x) (current-error-port))]))

For keywords, it might be easier with syntax-parse and the seq-no-order pkg, or a report-with-line would be just as good.

For parameterize, it can expand to code that would do something different depending on the value of the parameter. ``` racket (define-syntax (report stx) (syntax-case stx () [(_ expr) #'(report expr expr)] [(_ expr name) #`(let ([x expr]) (display-for-report x 'name #,(syntax-line #'expr)) x)])) (define (display-for-report x name line) (cond [(report-line-number) (displayln (format "~a = ~v at line ~a" name x line) (current-error-port))] [else (displayln (format "~a = ~v" name x) (current-error-port))])) ``` For keywords, it might be easier with syntax-parse and the [seq-no-order](http://pkg-build.racket-lang.org/doc/seq-no-order/index.html) pkg, or a `report-with-line` would be just as good.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/sugar#1
Loading…
There is no content yet.